Skip to content

Conversation

@takaokouji
Copy link
Collaborator

@takaokouji takaokouji commented Jan 21, 2026

Summary

This PR adds Rails 8.1 compatibility improvements while maintaining full backward compatibility with earlier Rails versions (6.1, 7.0, 7.1).

Based on the excellent work by @simps614 in upstream PR cerebris#1485.

Changes

1. CSV gem dependency

  • File: Gemfile
  • Change: Added csv gem for Rails 8.1+ (removed from standard library)
  • Reason: Required by lib/jsonapi/acts_as_resource_controller.rb:3

2. HTTP status code compatibility

  • Files: lib/jsonapi/exceptions.rb, test/controllers/controller_test.rb, test/test_helper.rb, test/helpers/functional_helpers.rb
  • Change: Updated :unprocessable_entity to conditionally use :unprocessable_content for Rails 8.0+
  • Reason: Avoid deprecation warnings in Rails 8.0+ while maintaining backward compatibility
  • Implementation:
    • Added unprocessable_status helper method in JSONAPI::Exceptions::Error and test helpers
    • Updated test assertions to use the helper method
    • Uses :unprocessable_content when Rails::VERSION::MAJOR >= 8

3. Database adapter improvements

  • File: test/unit/active_relation_resource_finder/join_manager_test.rb
  • Change: Simplified db_true helper to use ActiveRecord::Base.connection.quoted_true
  • Reason: More concise, database-agnostic approach

Backward Compatibility

All changes maintain full backward compatibility:

  • Rails 6.1, 7.0, 7.1: Uses :unprocessable_entity (existing behavior)
  • Rails 8.0, 8.1+: Uses :unprocessable_content (avoids deprecation warnings)

Testing

All tests pass with Rails 6.1, 7.0, 8.0, and 8.1:

# Rails 6.1
docker-compose run rails-6.1
# ✅ 704 runs, 8832 assertions, 0 failures, 0 errors, 0 skips

# Rails 7.0
docker-compose run rails-7.0
# ✅ 704 runs, 8832 assertions, 0 failures, 0 errors, 0 skips

# Rails 8.0
docker-compose run rails-8.0
# ✅ 704 runs, 8838 assertions, 0 failures, 0 errors, 0 skips
# ✅ No :unprocessable_entity deprecation warnings

# Rails 8.1
docker-compose run rails-8.1
# ✅ 704 runs, 8838 assertions, 0 failures, 0 errors, 0 skips
# ✅ No :unprocessable_entity deprecation warnings

Credits

Based on the work by @simps614 (Cassie Simpson) in cerebris#1485.

Related Issues

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: cerebris#1485

Co-Authored-By: Cassie Simpson <simps614@umn.edu>
@takaokouji takaokouji force-pushed the rails-8.1-compatibility branch from 13069e8 to 4a10213 Compare January 21, 2026 13:28
@takaokouji takaokouji merged commit 5cd0ed8 into master Jan 21, 2026
60 checks passed
@takaokouji takaokouji deleted the rails-8.1-compatibility branch January 21, 2026 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant