Skip to content

Commit

Permalink
Update to Rails 7.1 compatibility (#17)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
avonderluft authored May 4, 2024
1 parent ea3c408 commit d63c59e
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 89 deletions.
1 change: 1 addition & 0 deletions .github/workflows/rubyonrails.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand All @@ -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)
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 @@ -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
8 changes: 8 additions & 0 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,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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 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 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.

Expand Down
3 changes: 3 additions & 0 deletions lib/occams/content/tags/siblings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

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.

2 changes: 1 addition & 1 deletion lib/occams/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Occams
VERSION = '1.0.8'
VERSION = '1.1.0'
end
10 changes: 5 additions & 5 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 @@ -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
Expand All @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d63c59e

Please sign in to comment.