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

Conversation

jpawlyn
Copy link

@jpawlyn jpawlyn commented Dec 16, 2021

Purpose

Follow on from #2423 to enable AMS to be used with Rails 7

Changes

Updates rails_versions in Gemspec to < 7.1

Caveats

Related GitHub issues

Additional helpful information

@delphaber
Copy link

Since Ruby 3.0 is "preferred" in Rails 7, should Ruby 3.0 be added to travis too? 🤔

@wasifhossain
Copy link
Member

I think AMS is currently using Github CI instead of Travis. could you please make the changes on https://github.com/rails-api/active_model_serializers/blob/0-10-stable/.github/workflows/ci.yml.

Thanks!

@@ -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', '< 8.0']
Copy link
Member

Choose a reason for hiding this comment

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

as the rails version on main branch is now having 7.1.0, can we use < 7.1 instead of < 8.0. thanks

Copy link
Author

Choose a reason for hiding this comment

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

Good idea

@@ -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.

@NickLaMuro
Copy link

NickLaMuro commented Dec 18, 2021

Thought I should throw a couple of relevant links in here since this took me a bit too stumble across this PR and almost opened a duplicate PR:

A big reason most will need this fix pretty quickly is because without it, you will get forced into using an ancient version of the gem predating this change:

#1736

This means that the errors mentioned in and fixed by #2395 are not in the gem version that is bundled, leading to a very confusing upgrade experience.

(Edit: This assumes a loose gem dependency to this gem in the Gemfile of the Rails project, which maybe arguably should be fixed in the project I am working on... 😖 )

For now, using the jpawlyn:0-10-stable branch for this should be enough for proof of concept purposes, but is probably not best for prime time.


Thanks for all the hard work and will be looking forward to this getting merged. 🙇

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.

@wasifhossain
Copy link
Member

Hi @jpawlyn the PR looks good to me! thanks for your efforts 👍

as ruby 3.1.0 has just been out, would you mind adding this in github CI as well 🙂 thanks!

@jpawlyn
Copy link
Author

jpawlyn commented Dec 28, 2021

Hi @jpawlyn the PR looks good to me! thanks for your efforts 👍

as ruby 3.1.0 has just been out, would you mind adding this in github CI as well 🙂 thanks!

Sure, easily done.

@jpawlyn
Copy link
Author

jpawlyn commented Dec 29, 2021

Hi @jpawlyn the PR looks good to me! thanks for your efforts 👍
as ruby 3.1.0 has just been out, would you mind adding this in github CI as well 🙂 thanks!

The CI error is due to an incompatibility I think between Rails 7.0 and ruby 3.1 (see rails/rails#43998). It has been fixed on main (rails/rails#43951) so once Rails 7.0.1 is released it should be fine.

@bf4
Copy link
Member

bf4 commented Jan 3, 2022

I figure this is fine to merge as it's going to keep failing on Rails 7.0 and Ruby 3.1 due to incompatibilities outside of AMS scope?

@jpawlyn
Copy link
Author

jpawlyn commented Jan 3, 2022

I figure this is fine to merge as it's going to keep failing on Rails 7.0 and Ruby 3.1 due to incompatibilities outside of AMS scope?

I reckon so 👍🏼

@wasifhossain
Copy link
Member

Great! let's merge it.

@wasifhossain wasifhossain merged commit fae99ee into rails-api:0-10-stable Jan 3, 2022
@AhmedKamal20
Copy link

Will we get a new release?

@bopm
Copy link

bopm commented Jan 12, 2022

@bf4 I am going to tag you here, as this seems to be stalled for a week.

@bf4
Copy link
Member

bf4 commented Jan 13, 2022

I just released 0.10.13. I didn't check to make sure the change log is up to date. Help appreciated.

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.

7 participants