Conversation
Fixes #1479 Rails 8.1 changed `ActionDispatch::Routing::Mapper::Resources::Resource#initialize` to require keyword args (only:, except:, **options). The JSONAPI‑Resources DSL still passes a positional options hash, so jsonapi_relationships never runs and relationship routes are missing. Adding the ** operator to `**options` converts the hash into keyword args. Tests that fail without this change: `test/controllers/controller_test.rb` I ran into several other deprecations. * `ActiveSupport::Deprecation.silenced` will not work the way it was set up in the tests because `#silenced` now works on an instance of `Deprecators` instead of globally. I created a module `JSONAPI.deprecator` so that the gem can use its own instance of Deprecator and the tests can work as designed. * `:unprocessable_entity` was deprecated in favor of `:unprocessable_content` * Used lazy method evaluation for `Configuration` because Rails 8.1 does not guarantee class-body initialization order, so @configuration was returning `nil`. * My team uses an active_record oracle adapter. Oracle unquoted identifiers are automatically stored as UPPERCASE. Rails 8.1 no longer normalizes the case automatically for queries, so I added a condition for using the oracle adapter. * `length` is no longer a valid column constraint. Used `limit` instead * `references:` is not a valid option key for ActiveRecord migrations. Excplicitly pass a foreign_key to the things table instead. * `:none` is not a valid active_record schema format in Rails 8.1 * Disabled foreign key constraints for SQLite tests * Use `ActiveRecord::Base.connection.quoted_true` as it is database agnostic There are a few warnings in the test suite that I did not address because they were unrelated to this change.
This commit addresses several Rails 8.1 compatibility issues: 1. **CSV gem dependency**: Added 'csv' gem to Gemfile for Rails 8.1+ (removed from standard library). Required by acts_as_resource_controller.rb. 2. **HTTP status code compatibility**: Updated :unprocessable_entity to use conditional :unprocessable_content for Rails 8.1+ to avoid deprecation warnings while maintaining backward compatibility with earlier Rails versions. - Added unprocessable_status helper in JSONAPI::Exceptions::Error - Updated ValidationErrors and SaveFailed exceptions - Updated test assertions in controller_test.rb 3. **Database adapter improvements**: Simplified db_true helper in join_manager_test.rb to use ActiveRecord::Base.connection.quoted_true for database-agnostic boolean value handling. These changes maintain full backward compatibility with Rails 6.1, 7.0, 7.1, 7.2, and 8.0 while preparing for Rails 8.1+. Based on upstream PR: https://github.com/cerebris/jsonapi-resources/pull/1485 Co-Authored-By: Cassie Simpson <simps614@umn.edu>
|
Hi @simps614, Thank you so much for your excellent work on Rails 8.1 compatibility! 🎉 I've incorporated several of your changes into the Speee fork of jsonapi-resources. Specifically, I adopted:
I made some slight modifications to maintain backward compatibility by only using The changes are available in: speee#24 If you're interested, we'd love for you to try out the Speee fork at https://github.com/speee/jsonapi-resources! We've been working on maintaining compatibility with recent Rails versions and would appreciate any feedback. Thanks again for your contribution to the jsonapi-resources community! |
This commit addresses several Rails 8.1 compatibility issues: 1. **CSV gem dependency**: Added 'csv' gem to Gemfile for Rails 8.1+ (removed from standard library). Required by acts_as_resource_controller.rb. 2. **HTTP status code compatibility**: Updated :unprocessable_entity to use conditional :unprocessable_content for Rails 8.1+ to avoid deprecation warnings while maintaining backward compatibility with earlier Rails versions. - Added unprocessable_status helper in JSONAPI::Exceptions::Error - Updated ValidationErrors and SaveFailed exceptions - Updated test assertions in controller_test.rb 3. **Database adapter improvements**: Simplified db_true helper in join_manager_test.rb to use ActiveRecord::Base.connection.quoted_true for database-agnostic boolean value handling. These changes maintain full backward compatibility with Rails 6.1, 7.0, 7.1, 7.2, and 8.0 while preparing for Rails 8.1+. Based on upstream PR: https://github.com/cerebris/jsonapi-resources/pull/1485 Co-Authored-By: Cassie Simpson <simps614@umn.edu>
This commit addresses several Rails 8.1 compatibility issues: 1. **CSV gem dependency**: Added 'csv' gem to Gemfile for Rails 8.1+ (removed from standard library). Required by acts_as_resource_controller.rb. 2. **HTTP status code compatibility**: Updated :unprocessable_entity to use conditional :unprocessable_content for Rails 8.0+ to avoid deprecation warnings while maintaining backward compatibility with earlier Rails versions. - Added unprocessable_status helper in JSONAPI::Exceptions::Error - Updated ValidationErrors and SaveFailed exceptions - Updated test assertions in controller_test.rb and test helpers 3. **Database adapter improvements**: Simplified db_true helper in join_manager_test.rb to use ActiveRecord::Base.connection.quoted_true for database-agnostic boolean value handling. These changes maintain full backward compatibility with Rails 6.1, 7.0, and 7.1 while preparing for Rails 8.0+. Based on upstream PR: https://github.com/cerebris/jsonapi-resources/pull/1485 Co-Authored-By: Cassie Simpson <simps614@umn.edu>
|
@takaokouji thank you for addressing this so quickly! I tried the fork on two of our applications and it is working. Do you know when we could expect a release? |
|
@simps614 We've just released v26.1.2 which includes these fixes. You can try it out by adding the following to your Gemfile: gem 'jsonapi-resources', git: 'https://github.com/speee/jsonapi-resources.git', tag: 'v26.1.2'Or if you prefer to use the latest from master: gem 'jsonapi-resources', git: 'https://github.com/speee/jsonapi-resources.git'Release notes: https://github.com/speee/jsonapi-resources/releases/tag/v26.1.2 Please let us know if you encounter any issues! |
Fixes #1479
Rails 8.1 changed
ActionDispatch::Routing::Mapper::Resources::Resource#initializeto require keyword args (only:, except:, **options). The JSONAPI‑Resources DSL still passes a positional options hash, so jsonapi_relationships never runs and relationship routes are missing.Adding the ** operator to
**optionsconverts the hash into keyword args.Tests that fail without this change:
test/controllers/controller_test.rbI ran into several other deprecations.
ActiveSupport::Deprecation.silencedwill not work the way it was set up in the tests because#silencednow works on an instance ofDeprecatorsinstead of globally. I created a moduleJSONAPI.deprecatorso that the gem can use its own instance of Deprecator and the tests can work as designed.:unprocessable_entitywas deprecated in favor of:unprocessable_contentConfigurationbecause Rails 8.1 does not guarantee class-body initialization order, so @configuration was returningnil.lengthis no longer a valid column constraint. Usedlimitinsteadreferences:is not a valid option key for ActiveRecord migrations. Excplicitly pass a foreign_key to the things table instead.:noneis not a valid active_record schema format in Rails 8.1ActiveRecord::Base.connection.quoted_trueas it is database agnosticThere are a few warnings in the test suite that I did not address because they were unrelated to this change.
All Submissions:
Bug fixes and Changes to Core Features:
Reviewer Checklist:
NOTE: I used Ruby 3.2 locally. There are big changes since Ruby 2.6 so CI fails.