Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax gem requirement to allow Rails 7 #2428

Merged
merged 6 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ jobs:
matrix:
include:
# Recent Rubies and Rails
- ruby-version: '3.0'
rails-version: '7.0'
- ruby-version: '2.7'
rails-version: '7.0'
- ruby-version: '2.6'
rails-version: '6.1'
- ruby-version: '2.6'
Expand Down
2 changes: 1 addition & 1 deletion active_model_serializers.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = '>= 2.1'

rails_versions = ['>= 4.1', '< 7.0']
rails_versions = ['>= 4.1', '< 7.1']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might as well remove the max version. only real benefit is it gets people to ask us to add a new version to CI

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wasifhossain had a different idea but happy to go with the consensus.

spec.add_runtime_dependency 'activemodel', rails_versions
# 'activesupport', rails_versions
# 'builder'
Expand Down
13 changes: 13 additions & 0 deletions test/support/rails_7_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

# HACK: to prevent the resetting of instance variables after each request in Rails 7
# see https://github.com/rails/rails/pull/43735
if Rails::VERSION::MAJOR >= 7
module ActionController
module Testing
module Functional
def clear_instance_variables_between_requests; end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my only concern is, whether we should go forward and adopt the new rails practice (resetting the instance variables) by rewriting the affected tests in this repo, or should we pull things behind by using this hack

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other option is to target the hack at the one controller that causes the issue ImplicitSerializationTestController in order to limit the likelihood of instance variables being re-used across requests in future.

ie

# frozen_string_literal: true

require 'test_helper'

module ActionController
  module Serialization
    class ImplicitSerializerTest < ActionController::TestCase
      class ImplicitSerializationTestController < ActionController::Base
        include SerializationTesting
        
        ...

        # HACK: to prevent the resetting of instance variables after each request in Rails 7
        # see https://github.com/rails/rails/pull/43735
        def clear_instance_variables_between_requests; end

        def update_and_render_object_with_cache_enabled
          @post.updated_at = Time.zone.now # requires hack above to prevent `NoMethodError: undefined method `updated_at=' for nil:NilClass`

          generate_cached_serializer(@post)
          render json: @post
        end

        ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be a more optimized approach. this way we can apply the hack on the affected controllers exclusively, at the same time influence adopting the new practice before writing new tests.

Also in future iteration, we may proactively work on getting rid of this hack from these controllers by rewriting the tests.

end
end
end
end
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def silence_warnings

require 'support/rails_app'

require 'support/rails_7_patch'
require 'support/ruby_2_6_rails_4_2_patch'

# require "rails/test_help"
Expand Down