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

Upgrade to Ruby 2.7.6 #953

Merged
merged 10 commits into from
May 30, 2022
Merged

Upgrade to Ruby 2.7.6 #953

merged 10 commits into from
May 30, 2022

Conversation

nimmolo
Copy link
Contributor

@nimmolo nimmolo commented May 27, 2022

Steps to try the update, a couple safeguards to prevent a glitch updating the gem mini-racer to 0.6.2.
These can be performed in vagrant console:

Add the new Ruby version alongside 2.6.6

  • rvm install 2.7.6
  • /bin/bash --login
  • rvm use 2.7.6
  • ruby -v (check!)

Update rubygems and bundler

  • gem update --system
  • gem update bundler

Delete your gemfile.lock and update the gems

  • bundle update

@coveralls
Copy link
Collaborator

coveralls commented May 27, 2022

Coverage Status

Coverage remained the same at 93.065% when pulling 008ebfa on ruby-2.7 into 2c7eabc on master.

@nimmolo
Copy link
Contributor Author

nimmolo commented May 27, 2022

Incredible. Nothing but net!

There are many notices of the upcoming kwarg behavior change in our code to fix, but they're just deprecation warnings for now, and only caused by very few methods. cure_acts_as_versioned needs a tweak too.

If I can track the methods down, I'll fix them in this PR.

@pellaea
Copy link
Member

pellaea commented May 27, 2022 via email

@nimmolo
Copy link
Contributor Author

nimmolo commented May 27, 2022

I guess you have been fixing them — It's only one method!!!
NameTest#do_name_parse_test(str, expects, deprecated: false)
How can I fix? I've been reading up but i'm not sure I understand where to fix it - in the method, or in the calls to the method.
I have all the line numbers that call it in name_test.rb

I also think cure_acts_as_versioned is fixable, it's our fork isn't it?

@nimmolo
Copy link
Contributor Author

nimmolo commented May 27, 2022

In acts_as_versioned.rb, it's here on line 160:

        self.version_association_options  = {
                                                    :class_name  => "#{self.to_s}::#{versioned_class_name}",
                                                    :foreign_key => versioned_foreign_key,
        }.merge(options[:association_options] || {})

and then used here on line 243:

        included do
          has_many :versions, self.version_association_options

Should we splat has_many :versions, **self.version_association_options?

What I don't understand is what the new usage is, for kwargs. I've read a bunch of posts about it and I still don't get it.

For the NameTest#do_name_parse_test(str, expects, deprecated: false) it seems like I could move the deprecated into the expects, but that's not very DRY.

@pellaea
Copy link
Member

pellaea commented May 27, 2022 via email

@JoeCohen
Copy link
Member

So much has been happening, I can't keep up.
I'm glad you've merged everything without waiting for me.

Re cure_acts_as_versioned.

  • It is our fork.
  • If it's easily fixable, it should be done.
  • IMO we should think about moving to a more current, more widely gem, so that we don't have to maintain it ourselves, even if that means losing all existing old versions. Example paper_trail.

@pellaea
Copy link
Member

pellaea commented May 27, 2022 via email

@nimmolo
Copy link
Contributor Author

nimmolo commented May 27, 2022

@JoeCohen - Thanks! I do feel like the acts_as_versioned fix would be easy, I just don't understand the syntax change. But I believe it's in the lines I pointed out. Here's the deprecation warning:

/home/vagrant/.rvm/gems/ruby-2.7.6/bundler/gems/acts_as_versioned-59a408816683/lib/acts_as_versioned.rb:243: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call

@pellaea - More likely it is I who misunderstood something! But here is a sample of the warnings:

/vagrant/mushroom-observer/test/models/name_test.rb:1086: warning: Passing the keyword argument as the last hash parameter is deprecated:19
/vagrant/mushroom-observer/test/models/name_test.rb:19: warning: The called method `do_name_parse_test' is defined here
/vagrant/mushroom-observer/test/models/name_test.rb:964: warning: Passing the keyword argument as the last hash parameter is deprecated1:18
/vagrant/mushroom-observer/test/models/name_test.rb:19: warning: The called method `do_name_parse_test' is defined here
/vagrant/mushroom-observer/test/models/name_test.rb:1116: warning: Passing the keyword argument as the last hash parameter is deprecated
/vagrant/mushroom-observer/test/models/name_test.rb:19: warning: The called method `do_name_parse_test' is defined here

It's basically each time do_name_parse_test is called. Here's the code for the test:

  # Parse a string, with detailed error message.
  def do_name_parse_test(str, expects, deprecated: false)
    ...
  end

  ...

  def test_name_parse_21
    do_name_parse_test(
      "Amanita “quoted”",
      text_name: 'Amanita "quoted"',
      real_text_name: 'Amanita "quoted"',
      search_name: 'Amanita "quoted"',
      real_search_name: 'Amanita "quoted"',
      sort_name: 'Amanita quoted"',
      display_name: '**__Amanita "quoted"__**',
      parent_name: "Amanita",
      rank: :Species,
      author: ""
    )
  end

@JoeCohen
Copy link
Member

JoeCohen commented May 27, 2022 via email

@nimmolo
Copy link
Contributor Author

nimmolo commented May 27, 2022 via email

@nimmolo
Copy link
Contributor Author

nimmolo commented May 28, 2022 via email

@JoeCohen
Copy link
Member

@nimmolo. Re acts_as_versioned
I'm also not getting it.
act_as_versioned line 243:

has_many :versions, self.version_association_options

self.version_association_options is a hash
act_as_versioned lines 160-163:

self.version_association_options  = {
                                            :class_name  => "#{self.to_s}::#{versioned_class_name}",
                                            :foreign_key => versioned_foreign_key,
}.merge(options[:association_options] || {})

So the call to has_many does use a hash as its last argument.
But has_many ought to handle that, as it splats the options param:

# File activerecord/lib/active_record/associations.rb, line 1370
def has_many(name, scope = nil, **options, &extension)

I don't know what to try. Maybe add a second positional arg:

has_many :versions, nil, self.version_association_options

Maybe try an extra splat

has_many :versions, **(self.version_association_options)

Even worse, I have no idea how to try out these ideas. I forget how I worked with acts_as_versioned when I forked it.

@nimmolo
Copy link
Contributor Author

nimmolo commented May 28, 2022 via email

@nimmolo
Copy link
Contributor Author

nimmolo commented May 28, 2022 via email

JoeCohen added a commit to MushroomObserver/acts_as_versioned that referenced this pull request May 28, 2022
Fixes "last argument as keyword parameters is deprecated" as kwargs by double-splatting the last argument. See
https://www.ruby-lang.org/en/news/2019/12/25/ruby-2-7-0-released/
MushroomObserver/mushroom-observer#953 (comment)
@nimmolo
Copy link
Contributor Author

nimmolo commented May 29, 2022

I believe this is good to go:

  • Joe has updated cure_acts_as_versioned to fix deprecation warnings
  • Everything in the app is fixed to avoid deprecation warnings
    ...but when it's switched, or before, will the vagrantfile need an update too (in developer-startup)?

@nimmolo
Copy link
Contributor Author

nimmolo commented May 29, 2022

Actually, #957 should merge first. But then the dep warnings will be fixed.

@nimmolo nimmolo marked this pull request as draft May 29, 2022 23:53
test/controller_extensions.rb Outdated Show resolved Hide resolved
test/controller_extensions.rb Outdated Show resolved Hide resolved
test/controller_extensions.rb Outdated Show resolved Hide resolved
test/controllers/account_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/account_controller_test.rb Outdated Show resolved Hide resolved
@nimmolo
Copy link
Contributor Author

nimmolo commented May 30, 2022

Update: Both #957 and #960 should merge first, to clear Codeclimate warnings.

test/controllers/account_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/account_controller_test.rb Outdated Show resolved Hide resolved
test/session_extensions.rb Outdated Show resolved Hide resolved
test/session_extensions.rb Outdated Show resolved Hide resolved
@codeclimate
Copy link
Contributor

codeclimate bot commented May 30, 2022

Code Climate has analyzed commit 008ebfa and detected 0 issues on this pull request.

View more on Code Climate.

@nimmolo nimmolo marked this pull request as ready for review May 30, 2022 09:18
@nimmolo
Copy link
Contributor Author

nimmolo commented May 30, 2022

Good to merge if you're ready. Rubocop says 👍, Codeclimate says🤙

@pellaea pellaea merged commit 937bb38 into master May 30, 2022
@JoeCohen JoeCohen deleted the ruby-2.7 branch June 6, 2022 00:24
@JoeCohen
Copy link
Member

JoeCohen commented Oct 11, 2022 via email

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.

None yet

4 participants