From 695e2a0a029a080ce510a481b64250ea2326ffc1 Mon Sep 17 00:00:00 2001 From: Andrew vonderLuft Date: Fri, 3 May 2024 16:41:36 -0700 Subject: [PATCH] Update to Rails 7.1 compatibility - corrected bug in siblings tag to not display links to unpublished pages - children lists and sibling navs are updated after page create, update, delete - fixed zeitwerk check failures - updated README --- .github/workflows/rubyonrails.yml | 1 + .gitignore | 1 + CHANGELOG.md | 8 +++ Gemfile | 4 +- README.md | 4 +- .../concerns/occams/reorder_action.rb | 3 + .../occams/admin/cms/pages_controller.rb | 8 +++ config/application.rb | 3 +- config/environments/test.rb | 2 + config/locales/en.yml | 6 +- lib/occams/content/tags/siblings.rb | 3 + lib/occams/routes/cms.rb | 16 ------ lib/occams/routes/cms_admin.rb | 56 ------------------- lib/occams/version.rb | 2 +- .../occams/admin/cms/pages_controller_test.rb | 10 ++-- test/system/zeitwerk_compliance_test.rb | 9 +++ test/test_helper.rb | 2 +- 17 files changed, 49 insertions(+), 89 deletions(-) delete mode 100644 lib/occams/routes/cms.rb delete mode 100644 lib/occams/routes/cms_admin.rb create mode 100644 test/system/zeitwerk_compliance_test.rb diff --git a/.github/workflows/rubyonrails.yml b/.github/workflows/rubyonrails.yml index bd0266bc..b5ee6a84 100644 --- a/.github/workflows/rubyonrails.yml +++ b/.github/workflows/rubyonrails.yml @@ -17,6 +17,7 @@ jobs: rails-version: - "6.1" - "7.0" + - "7.1" continue-on-error: [true] name: ${{ format('Tests (Ruby {0}, Rails {1})', matrix.ruby-version, matrix.rails-version) }} runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 692de629..310bde4f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ coverage/ db/*.sqlite3 db/cms_fixtures/test-site/ db/development_structure.sql +db/development.sqlite3* db/schema.rb db/test.sqlite3* Gemfile.lock diff --git a/CHANGELOG.md b/CHANGELOG.md index 20ef4be6..633df7d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## v.1.1.0 13 May 2024 + +- Rails 7.1 compatibility, all tests passing +- corrected bug in siblings tag to not display links to unpublished pages +- children lists and sibling navs are updated after page create, update, delete +- fixed zeitwerk check failures +- updated README + ## v1.0.8 - 29 December 2023 - Updated configs, et al. in pursuit of Rails 7.1 compatibility diff --git a/Gemfile b/Gemfile index 675abc11..a503a216 100644 --- a/Gemfile +++ b/Gemfile @@ -5,11 +5,11 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } gemspec -gem 'rails', '~> 7.0.0' +gem 'rails', '~> 7.1.2' group :development, :test do gem 'autoprefixer-rails', '~> 8.1.0' - gem 'byebug', '~> 10.0.0', platforms: %i[mri mingw x64_mingw] + gem 'byebug', '~> 11.1.0', platforms: %i[mri mingw x64_mingw] gem 'image_processing', '>= 1.2' gem 'sqlite3', '~> 1.6.7' # gem 'mysql2', '~> 0.5' diff --git a/README.md b/README.md index 14317b50..8d53cd92 100644 --- a/README.md +++ b/README.md @@ -98,8 +98,6 @@ Once you have a layout, you may start creating pages and populating content. It' ## Documentation -[Occams](https://github.com/avonderluft/occams) - For more information on how to use this CMS please refer to the [Wiki](https://github.com/avonderluft/occams/wiki). Section that might be of interest is the entry on [Content Tags](https://github.com/comfy/avonderluft/occams/Content-Tags). @@ -120,5 +118,5 @@ For more detail see [CONTRIBUTING](CONTRIBUTING.md) - Thanks to [Roman Almeida](https://github.com/nasmorn) for contributing OEM License for [Redactor Text Editor](http://imperavi.com/redactor) --- -- [Occams](https://github.com/avonderluft/occams) Copyright 2023 Andrew vonderLuft, following Comfy, released under the [MIT license](LICENSE) +- [Occams](https://github.com/avonderluft/occams) Copyright 2023-2024 Andrew vonderLuft, following Comfy, released under the [MIT license](LICENSE) - [ComfortableMexicanSofa](https://github.com/comfy/comfortable-mexican-sofa) Copyright 2010-2019 Oleg Khabarov. Released under the [MIT license](LICENSE) diff --git a/app/controllers/concerns/occams/reorder_action.rb b/app/controllers/concerns/occams/reorder_action.rb index 37fa6199..27673dc8 100644 --- a/app/controllers/concerns/occams/reorder_action.rb +++ b/app/controllers/concerns/occams/reorder_action.rb @@ -12,6 +12,9 @@ def reorder (params.permit(order: [])[:order] || []).each_with_index do |id, index| resource_class.where(id: id).update_all(position: index) end + if resource_class == ::Occams::Cms::Page + Occams::Cms::Page.all.each(&:save!) + end head :ok end end diff --git a/app/controllers/occams/admin/cms/pages_controller.rb b/app/controllers/occams/admin/cms/pages_controller.rb index a57c6025..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,6 +52,7 @@ def create def update @page.save! + update_family flash[:success] = I18n.t('occams.admin.cms.pages.updated') redirect_to action: :edit, id: @page rescue ActiveRecord::RecordInvalid @@ -55,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 19ab641f..dfe18bf5 100644 --- a/config/application.rb +++ b/config/application.rb @@ -14,8 +14,6 @@ class Application < Rails::Application config.load_defaults Rails.version.scan(%r{^\d+\.\d+}).first.to_f # Rails 7.1 compatibility - See config/initializers/new_framework_defaults_7_1.rb - config.add_autoload_paths_to_load_path = true - if Gem::Version.new(Rails.version) >= Gem::Version.new('7.1.0') config.active_record.default_column_serializer = YAML config.active_record.before_committed_on_all_records = false @@ -30,6 +28,7 @@ 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.add_autoload_paths_to_load_path = false config.autoload_lib(ignore: %w[generators]) end diff --git a/config/environments/test.rb b/config/environments/test.rb index 883457fb..14dae900 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -10,6 +10,8 @@ defined?(Occams::Application) && Occams::Application.configure do # Settings specified here will take precedence over those in config/application.rb. + config.active_job.queue_adapter = :test # added for Rails 7.1 + # While tests run files are not watched, reloading is not necessary. config.enable_reloading = false diff --git a/config/locales/en.yml b/config/locales/en.yml index 14bf3d02..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 updated + 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/content/tags/siblings.rb b/lib/occams/content/tags/siblings.rb index 76090a91..6655b81b 100644 --- a/lib/occams/content/tags/siblings.rb +++ b/lib/occams/content/tags/siblings.rb @@ -31,6 +31,9 @@ def initialize(context:, params: [], source: nil) @links = '' # ActiveRecord_Associations_CollectionProxy @sibs = context.self_and_siblings.order(:position).to_ary + unless Rails.env == 'development' + @sibs.delete_if { |sib| !sib.is_published } + end @sibs.delete_if { |sib| @exclude.include? sib.slug } end 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/lib/occams/version.rb b/lib/occams/version.rb index 550bb7e5..7e380a55 100644 --- a/lib/occams/version.rb +++ b/lib/occams/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Occams - VERSION = '1.0.8' + VERSION = '1.1.0' end diff --git a/test/controllers/occams/admin/cms/pages_controller_test.rb b/test/controllers/occams/admin/cms/pages_controller_test.rb index 0d9766f0..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 @@ -290,7 +290,7 @@ def test_update @page.reload assert_response :redirect assert_redirected_to action: :edit, id: @page - assert_equal 'Page updated', flash[:success] + assert_equal 'Page, siblings, and parent updated', flash[:success] assert_equal 'Updated Label', @page.label end end @@ -310,7 +310,7 @@ def test_update_with_layout_change @page.reload assert_response :redirect assert_redirected_to action: :edit, id: @page - assert_equal 'Page updated', flash[:success] + assert_equal 'Page, siblings, and parent updated', flash[:success] assert_equal 'Updated Label', @page.label identifiers = @page.fragments.collect(&:identifier) assert_equal %w[boolean content datetime file header], identifiers.sort @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index 953ed189..c64321fa 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -43,7 +43,7 @@ class ActiveSupport::TestCase include ActionDispatch::TestProcess fixtures :all - parallelize(workers: 1) # rails 7.1 tests pass in github actions + self.use_transactional_tests = false setup :reset_config, :reset_locale