Skip to content

Commit

Permalink
Fix for zeitwerk
Browse files Browse the repository at this point in the history
  • Loading branch information
avonderluft committed May 3, 2024
1 parent e1bc552 commit 6cbb6d3
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 83 deletions.
3 changes: 3 additions & 0 deletions app/controllers/concerns/occams/reorder_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ def reorder
resource_class = self.class.reorder_action_resource
(params.permit(order: [])[:order] || []).each_with_index do |id, index|
resource_class.where(id: id).update_all(position: index)
if resource_class == ::Occams::Cms::Page
Occams::Cms::Page.all.each(&:save!)
end
end
head :ok
end
Expand Down
10 changes: 8 additions & 2 deletions app/controllers/occams/admin/cms/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@ def edit
render
end

def update_family
@page.siblings.each(&:save!) if @page.siblings
@page.parent.save! if @page.parent
end

def create
@page.save!
update_family
flash[:success] = I18n.t('occams.admin.cms.pages.created')
redirect_to action: :edit, id: @page
rescue ActiveRecord::RecordInvalid
Expand All @@ -46,8 +52,7 @@ def create

def update
@page.save!
@page.siblings.each(&:save!) if @page.siblings
@page.parent.save! if @page.parent
update_family
flash[:success] = I18n.t('occams.admin.cms.pages.updated')
redirect_to action: :edit, id: @page
rescue ActiveRecord::RecordInvalid
Expand All @@ -57,6 +62,7 @@ def update

def destroy
@page.destroy
update_family
flash[:success] = I18n.t('occams.admin.cms.pages.deleted')
redirect_to action: :index
end
Expand Down
5 changes: 1 addition & 4 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ class Application < Rails::Application
# Please, add to the `ignore` list any other `lib` subdirectories that do
# not contain `.rb` files, or that should not be reloaded or eager loaded.
# Common ones are `templates`, `generators`, or `middleware`, for example.
config.autoload_paths << "#{config.root}/lib"
config.eager_load_paths << "#{config.root}/lib"
config.add_autoload_paths_to_load_path = false
config.autoload_lib(ignore: %w[generators])
config.autoloader = :classic
# config.add_autoload_paths_to_load_path = false
end

# Making sure we don't load our dev routes as part of the engine
Expand Down
4 changes: 2 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ en:
update: Update Layout

pages:
created: Page created
created: Page created, siblings, and parent updated
creation_failure: Failed to create page
updated: Page, siblings, and parent updated
update_failure: Failed to update page
deleted: Page deleted
deleted: Page deleted, siblings, and parent updated
not_found: Page not found
layout_not_found: No Layouts found. Please create one.

Expand Down
16 changes: 0 additions & 16 deletions lib/occams/routes/cms.rb

This file was deleted.

56 changes: 0 additions & 56 deletions lib/occams/routes/cms_admin.rb

This file was deleted.

6 changes: 3 additions & 3 deletions test/controllers/occams/admin/cms/pages_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def test_creation
page = Occams::Cms::Page.last
assert_equal @site, page.site
assert_redirected_to action: :edit, id: page
assert_equal 'Page created', flash[:success]
assert_equal 'Page created, siblings, and parent updated', flash[:success]
end
end
end
Expand Down Expand Up @@ -255,7 +255,7 @@ def test_creation_with_files
page = Occams::Cms::Page.last
assert_equal @site, page.site
assert_redirected_to action: :edit, id: page
assert_equal 'Page created', flash[:success]
assert_equal 'Page created, siblings, and parent updated', flash[:success]
end
end
end
Expand Down Expand Up @@ -333,7 +333,7 @@ def test_destroy
r :delete, occams_admin_cms_site_page_path(site_id: @site, id: @page)
assert_response :redirect
assert_redirected_to action: :index
assert_equal 'Page deleted', flash[:success]
assert_equal 'Page deleted, siblings, and parent updated', flash[:success]
end
end
end
Expand Down
9 changes: 9 additions & 0 deletions test/system/zeitwerk_compliance_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require 'test_helper'

class ZeitwerkComplianceTest < ActiveSupport::TestCase
test 'eager loads all files without errors' do
assert_nothing_raised { Rails.application.eager_load! }
end
end

0 comments on commit 6cbb6d3

Please sign in to comment.