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

Update to Rails 7.1 (including related updates) #2219

Merged
merged 8 commits into from
Dec 19, 2024
Merged

Conversation

david-a-wheeler
Copy link
Collaborator

Update to Rails 7.1. This requires other related updates.

Oddly, 'rails-i18n' doesn't upgrade to the same number this time. It will later when we upgrade again, so be careful about that. I've added a spurious extra version number comment to hint at that for later.

This updates paper_trail. However, it does not adjust the older data in paper_trail. Paper_trail records data as it was, and by default uses YAML. This is a problem due to a datatype change; YAML records the actual datatype, even when we don't want to use it. That should be addressed separately before merging this change. This PR removes the known-failing test on papertrail.

This updates does not deal with a Rack deprecation. We'll need to deal with that separately, but since it's still supported, we can deal with it separately.
It will currently show:

DEPRECATION WARNING: Setting action_dispatch.show_exceptions
to false is deprecated. Set to :none instead.
(called from call at ... /best-practices-badge/config/initializers/
canonical_trailing_slash.rb:30)

Update to Rails 7.1. This requires other related updates.

Oddly, 'rails-i18n' doesn't upgrade to the same number this time.
It *will* later when we upgrade again, so be careful about that.
I've added a spurious extra version number comment to hint at
that for later.

This updates paper_trail. However, it does *not* adjust the
older data in paper_trail. Paper_trail records data as it was,
and by default uses YAML. This is a problem due to a datatype change;
YAML records the *actual* datatype, even when we don't want to use it.
That should be addressed separately before merging this change.
This PR removes the known-failing test on papertrail.

This updates does *not* deal with a Rack deprecation.
We'll need to deal with that separately, but since it's still
supported, we can deal with it separately.
It will currently show:

> DEPRECATION WARNING: Setting action_dispatch.show_exceptions
> to false is deprecated. Set to :none instead.
> (called from call at ... /best-practices-badge/config/initializers/
> canonical_trailing_slash.rb:30)

Signed-off-by: David A. Wheeler <[email protected]>
Copy link

codecov bot commented Dec 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.95%. Comparing base (105aa1a) to head (5fad32e).
Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2219      +/-   ##
==========================================
+ Coverage   98.08%   99.95%   +1.86%     
==========================================
  Files          55       55              
  Lines        2144     2125      -19     
==========================================
+ Hits         2103     2124      +21     
+ Misses         41        1      -40     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@andrewfader
Copy link
Collaborator

ran into this also (codecov showing decreased coverage) but I didn't figure out why

This changes PaperTrail to store using jsonb, which should
make this transition easier.

Signed-off-by: David A. Wheeler <[email protected]>
Now that PaperTrail is fixed up, restore test using it.

Signed-off-by: David A. Wheeler <[email protected]>
Signed-off-by: David A. Wheeler <[email protected]>
@david-a-wheeler
Copy link
Collaborator Author

@andrewfader - Hi! Great to hear from you, and Merry Christmas!

If you have any ideas, let me know. I'm starting by reviewing the File Explorer results e.g., here.

Sometimes there's a race where CodeCov produces results before tests have completed, producing lower numbers. But usually it's re-run when the test complete & the coverage value updates. So I don't think that's it, it seems to actually have a problem.

@david-a-wheeler
Copy link
Collaborator Author

Well, it just gets weirder. For example, CodeCov says that lots of code in UsersController isn't run, including "index". We do have such tests. So the tests aren't running for some reasons, or the results aren't getting recorded.

@andrewfader
Copy link
Collaborator

@david-a-wheeler yeah, it's almost like it bails out or crashes at some point and stops tracking the things getting run

@andrewfader
Copy link
Collaborator

btw, I opened #2212 if you want a monkeypatch to silence that VCR error. Also you can manage webdrivers with selenium now

@david-a-wheeler
Copy link
Collaborator Author

Wow, thanks for creating #2212 !

Below is the output when I run the tests locally ("rake" which includes "rake test"). All the tests pass (0 failures). However, there are lots of warnings about failures between vcr and webmock.

I suspect what's happening is that our old version of vcr isn't happy, leading to passing tests not always being recorded as passing. The vcr gem switched from an OSS license to a "Hippocratic Oath" license which is why we haven't upgraded it. I long ago raised a legal question about it, & then moved on to other things.

19 tests, 181 assertions, 0 failures, 0 errors, 0 skips
Coverage report generated for Minitest to /home/dwheeler/best-practices-badge/coverage.
Line Coverage: 58.55% (1352 / 2309)
bin/rails: warning: Exception in finalizer #<Proc:0x00007f4e0e3df078 /home/dwheeler/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/vcr-5.0.0/lib/vcr/library_hooks/webmock.rb:36 (lambda)>
/home/dwheeler/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/vcr-5.0.0/lib/vcr/library_hooks/webmock.rb:36:in `block in global_hook_disabled_requests': wrong number of arguments (given 1, expected 0) (ArgumentError)
bin/rails: warning: Exception in finalizer #<Proc:0x00007f4e0e071788 /home/dwheeler/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/vcr-5.0.0/lib/vcr/library_hooks/webmock.rb:36 (lambda)>
/home/dwheeler/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/vcr-5.0.0/lib/vcr/library_hooks/webmock.rb:36:in `block in global_hook_disabled_requests': wrong number of arguments (given 1, expected 0) (ArgumentError)
bin/rails: warning: Exception in finalizer #<Proc:0x00007f4e0e01c558 /home/dwheeler/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/vcr-5.0.0/lib/vcr/library_hooks/webmock.rb:36 (lambda)>
/home/dwheeler/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/vcr-5.0.0/lib/vcr/library_hooks/webmock.rb:36:in `block in global_hook_disabled_requests': wrong number of arguments (given 1, expected 0) (ArgumentError)
bin/rails: warning: Exception in finalizer #<Proc:0x00007f4e0ecda380 /home/dwheeler/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/vcr-5.0.0/lib/vcr/library_hooks/webmock.rb:36 (lambda)>
/home/dwheeler/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/vcr-5.0.0/lib/vcr/library_hooks/webmock.rb:36:in `block in global_hook_disabled_requests': wrong number of arguments (given 1, expected 0) (ArgumentError)
bin/rails: warning: Exception in finalizer #<Proc:0x00007f4e14583040 /home/dwheeler/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/vcr-5.0.0/lib/vcr/library_hooks/webmock.rb:36 (lambda)>
/home/dwheeler/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/vcr-5.0.0/lib/vcr/library_hooks/webmock.rb:36:in `block in global_hook_disabled_requests': wrong number of arguments (given 1, expected 0) (ArgumentError)
Running via Spring preloader in process 200343

# Running tests with run options --seed 35653:

......DEPRECATION WARNING: Setting action_dispatch.show_exceptions to false is deprecated. Set to :none instead. (called from call at /home/dwheeler/best-practices-badge/config/initializers/canonical_trailing_slash.rb:30)
DEPRECATION WARNING: Setting action_dispatch.show_exceptions to false is deprecated. Set to :none instead. (called from call at /home/dwheeler/best-practices-badge/config/initializers/canonical_trailing_slash.rb:30)
.................................................................................................................................................................................................................................................................................................................................................

Finished tests in 126.464355s, 2.7122 tests/s, 120.6980 assertions/s.


343 tests, 15264 assertions, 0 failures, 0 errors, 0 skips
Coverage report generated for Minitest to /home/dwheeler/best-practices-badge/coverage.
Line Coverage: 96.08% (2060 / 2144)
/home/dwheeler/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/spring-4.2.1/lib/spring/application.rb:190: warning: Exception in finalizer #<Proc:0x00007f973477fec0 /home/dwheeler/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/vcr-5.0.0/lib/vcr/library_hooks/webmock.rb:36 (lambda)>
/home/dwheeler/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/vcr-5.0.0/lib/vcr/library_hooks/webmock.rb:36:in `block in global_hook_disabled_requests': wrong number of arguments (given 1, expected 0) (ArgumentError)
	from /home/dwheeler/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/spring-4.2.1/lib/spring/application.rb:190:in `fork'
	from /home/dwheeler/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/spring-4.2.1/lib/spring/application.rb:190:in `serve'
	from /home/dwheeler/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/spring-4.2.1/lib/spring/application.rb:153:in `block in run'
	from <internal:kernel>:187:in `loop'
	from /home/dwheeler/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/spring-4.2.1/lib/spring/application.rb:147:in `run'
	from /home/dwheeler/.rbenv/versions/3.3.6/lib/ruby/gems/3.3.0/gems/spring-4.2.1/lib/spring/application/boot.rb:25:in `<top (required)>'
	from <internal:/home/dwheeler/.rbenv/versions/3.3.6/lib/ruby/site_ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
	from <internal:/home/dwheeler/.rbenv/versions/3.3.6/lib/ruby/site_ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:136:in `require'
	from -e:1:in `<main>'

@david-a-wheeler
Copy link
Collaborator Author

I don't know if #2212 will solve this problem, but it seems like a good thing to merge for now. I hope to remove the monkeypatch eventually no matter what.

@andrewfader
Copy link
Collaborator

Yeah, #2212 will silence those warning/errors, but I don't know about the codecov issue with rails 7.1. I suspect we should look into what has changed in rails 7.1 and see if it might be something we have or use or is part of an old version of another gem. We could also try upgrading other gems that are loaded in the path of the codecov run

@andrewfader
Copy link
Collaborator

@david-a-wheeler I guess it fixed it! Or it just didn't even run codecov this time? where's the result?

@andrewfader
Copy link
Collaborator

Nevermind, still same problem!

@david-a-wheeler
Copy link
Collaborator Author

CodeCov results are here: https://app.codecov.io/gh/coreinfrastructure/best-practices-badge (you can get there using the little badge on the README of the best practices badge project).

@andrewfader
Copy link
Collaborator

I see it now, it just didn't load right away. Until it loads it looks like it passed with 7 checks, before the 8th shows up

@david-a-wheeler
Copy link
Collaborator Author

The build runs the tests & the tests pass.

The CodeCov results for this pull request are shown here: https://app.codecov.io/gh/coreinfrastructure/best-practices-badge/pull/2219
It looks like CodeCov is getting some of our data, but not all of our data.

@david-a-wheeler
Copy link
Collaborator Author

While it'd be nice to have CodeCov working properly, what matters is that we have tests working properly. build-deploy runs all the tests, and while I'll double-check, it looks like they're all passing.

@andrewfader
Copy link
Collaborator

@david-a-wheeler we could try moving the SimpleCov.start line to bin/rails as suggested in the readme https://github.com/simplecov-ruby/simplecov

@andrewfader
Copy link
Collaborator

@david-a-wheeler
Copy link
Collaborator Author

I looked at build-deploy which is the task that actually runs all the tests. Details.

The "run test suite (both system and non-system tests)" runs this command: bundle exec rails test:system test. I think I should double-check that this two-argument command will still run both. If it's running fewer tests that would explain less test coverage :-).

It reports some missing extensions, as well as a deprecation that must be dealt with before upgrading to Rails 7.2.

Source locally installed gems is ignoring #<Bundler::StubSpecification name=puma version=6.4.3 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=msgpack version=1.7.3 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=json version=2.7.6 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=json version=2.8.2 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=date version=3.4.0 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=puma version=6.4.3 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=msgpack version=1.7.3 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=json version=2.7.6 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=json version=2.8.2 platform=ruby> because it is missing extensions
Source locally installed gems is ignoring #<Bundler::StubSpecification name=date version=3.4.0 platform=ruby> because it is missing extensions
DEPRECATION WARNING: Your `secret_key_base` is configured in `Rails.application.secrets`, which is deprecated in favor of `Rails.application.credentials` and will be removed in Rails 7.2. (called from <top (required)> at /home/circleci/coreinfrastructure/best-practices-badge/config/environment.rb:11)

@david-a-wheeler
Copy link
Collaborator Author

CodeCov continues to show up late for the party, reporting only partial coverage. Hmmm.

This StackOverflow answer says that what we're doing (rails rails test:system test) is correct, at least for Rails 6. However, I'm wondering if the semantics have changed, and that this isn't true for Rails 7.

The documentation for Rails 7.1 says: "If you are using System Tests, bin/rails test will not run them, since they can be slow. To also run them, add an another CI step that runs bin/rails test:system, or change your first step to bin/rails test:all, which runs all tests including system tests." Rails 8 says something similar.

Let's switch to test:all. If nothing else, it's clearer, and this may actually matter.

@andrewfader
Copy link
Collaborator

@david-a-wheeler worth a try but also take a look at that simplecov issue I just posted above

@david-a-wheeler
Copy link
Collaborator Author

Oh, I didn't see your SimpleCov comment earlier. That definitely looks like something to check out, yes yes yes.

@andrewfader
Copy link
Collaborator

Actually, looks like you fixed it!

@david-a-wheeler
Copy link
Collaborator Author

Yes indeed! It does look like it's fixed.

We had a Stack Overflow answer that didn't work on a later version of some software. Let's just say I've seen that situation before :-). I was suspicious because I didn't see multi-argument support documented in the rails documentation.

@david-a-wheeler
Copy link
Collaborator Author

@andrewfader - Thanks so much for your help.

Merging now. Of course, I'll need to turn out around and fix the deprecations so that we can upgrade further, but that's a later step.

@david-a-wheeler david-a-wheeler merged commit bcbb111 into main Dec 19, 2024
9 checks passed
@david-a-wheeler
Copy link
Collaborator Author

The weirdest thing about this was that I first needed to switch PaperTrail to use jsonb. Without that, it couldn't load old stored values, because it was storing in YAML and trying to create time objects in a format no longer supported. JSON doesn't allow arbitrary types, so switching to JSON meant we eliminated that problem. It's more efficient anyway (I'm using jsonb in PostgreSQL).

@andrewfader
Copy link
Collaborator

+1 json in pg is the way to go

@david-a-wheeler
Copy link
Collaborator Author

+1 json in pg is the way to go

I agree. PaperTrail defaults to YAML, presumably because it can back any type (so it's a more general solution). But in many cases the correct answer is JSONB.

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.

2 participants