diff --git a/app/controllers/concerns/occams/reorder_action.rb b/app/controllers/concerns/occams/reorder_action.rb index 37fa6199..6316dc9e 100644 --- a/app/controllers/concerns/occams/reorder_action.rb +++ b/app/controllers/concerns/occams/reorder_action.rb @@ -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 diff --git a/app/controllers/occams/admin/cms/pages_controller.rb b/app/controllers/occams/admin/cms/pages_controller.rb index b36e42cd..8d830b0a 100644 --- a/app/controllers/occams/admin/cms/pages_controller.rb +++ b/app/controllers/occams/admin/cms/pages_controller.rb @@ -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 @@ -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 @@ -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 diff --git a/config/application.rb b/config/application.rb index 5b0f906a..dfe18bf5 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index a186a0ea..5fd70d47 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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. diff --git a/lib/occams/routes/cms.rb b/lib/occams/routes/cms.rb deleted file mode 100644 index c76a5479..00000000 --- a/lib/occams/routes/cms.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -class ActionDispatch::Routing::Mapper - def occams_route_cms(options = {}) - Occams.configuration.public_cms_path = options[:path] - - scope module: :occams, as: :occams do - namespace :cms, path: options[:path] do - get 'cms-css/:site_id/:identifier(/:cache_buster)' => 'assets#render_css', as: 'render_css' - get 'cms-js/:site_id/:identifier(/:cache_buster)' => 'assets#render_js', as: 'render_js' - - get '(*cms_path)' => 'content#show', as: 'render_page', action: '/:format' - end - end - end -end diff --git a/lib/occams/routes/cms_admin.rb b/lib/occams/routes/cms_admin.rb deleted file mode 100644 index 0e83492f..00000000 --- a/lib/occams/routes/cms_admin.rb +++ /dev/null @@ -1,56 +0,0 @@ -# frozen_string_literal: true - -class ActionDispatch::Routing::Mapper - def occams_route_cms_admin(path: 'admin') - scope module: :occams, as: :occams do - scope module: :admin do - namespace :cms, as: :admin_cms, path: path, except: :show do - get '/', to: 'base#jump' - - concern :with_revisions do |options| - resources :revisions, options.merge(only: %i[index show]) do - patch :revert, on: :member - end - end - - concern :with_reorder do - put :reorder, on: :collection - end - - concern :with_form_fragments do - get :form_fragments, on: :member - end - - resources :sites do - resources :pages do - concerns :with_reorder - concerns :with_form_fragments - concerns :with_revisions, controller: 'revisions/page' - - get :toggle_branch, on: :member - - resources :translations, except: [:index] do - concerns :with_form_fragments - concerns :with_revisions, controller: 'revisions/translation' - end - end - - resources :files, concerns: [:with_reorder] - - resources :layouts do - concerns :with_reorder - concerns :with_revisions, controller: 'revisions/layout' - end - - resources :snippets do - concerns :with_reorder - concerns :with_revisions, controller: 'revisions/snippet' - end - - resources :categories - end - end - end - end - end -end diff --git a/test/controllers/occams/admin/cms/pages_controller_test.rb b/test/controllers/occams/admin/cms/pages_controller_test.rb index f3f78b63..78d1a84b 100644 --- a/test/controllers/occams/admin/cms/pages_controller_test.rb +++ b/test/controllers/occams/admin/cms/pages_controller_test.rb @@ -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 @@ -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 @@ -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 diff --git a/test/system/zeitwerk_compliance_test.rb b/test/system/zeitwerk_compliance_test.rb new file mode 100644 index 00000000..6cc766e8 --- /dev/null +++ b/test/system/zeitwerk_compliance_test.rb @@ -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