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

Test against rails 8.0 #3702

Merged
merged 7 commits into from
Nov 23, 2024
Merged

Test against rails 8.0 #3702

merged 7 commits into from
Nov 23, 2024

Conversation

jewilmeer
Copy link
Contributor

As rails 8 came out, and not a lot has changed internally since 7.2, it might just work :-)

platforms :ruby, :mswin, :mingw, :x64_mingw do
gem "mysql2", ">= 0.3.14"
gem "pg", ">= 1.0.0"
gem "sqlite3", "~> 1.3"

Choose a reason for hiding this comment

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

https://github.com/railsadminteam/rails_admin/actions/runs/11738544873/job/32701267375?pr=3702#step:7:30

From Rails 8.0, it looks like the version of sqlite3 needs to be upgraded to v2.1 or higher.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

indeed, I upgraded it, and now it seems to work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like sqlite3 2.2 requires ruby 3.1.

What would be the best approach? Require ruby 3.1 for the next release, or stay backwards compatible?

Copy link

@k-tsuchiya-jp k-tsuchiya-jp Nov 20, 2024

Choose a reason for hiding this comment

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

@jewilmeer
Thank you for your support with Rails 8.0! It’s really helpful!

Seems like sqlite3 2.2 requires ruby 3.1.

This might help you.
In RailsAdmin, we use gem 'appraisal' to manage gems for each Rails version.
https://github.com/thoughtbot/appraisal?tab=readme-ov-file#setup

For versions other than Rails 8.0, there are no issues with the traditional gem versions, and no changes to Gemfile are necessary.
Instead, since bee3539#diff-4fc39a0aadaf0ef5048e145a93b08c08740e7efd36c6890426664cea221a622eR51 is explicitly mentioned, this alone should make the Rails 8.0 tests work.

What would be the best approach? Require ruby 3.1 for the next release, or stay backwards compatible?

This is just my opinion, but since Ruby 3.1 hasn't reached EOL yet, I think it's fine to include Ruby 3.1 in the next release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. I've changed the Gemfile back to the older sqlite3 version, and in the appraisal file I've made an exception for rails 8

@jewilmeer
Copy link
Contributor Author

It looks like a lot of unrelated things are broken, not sure how to proceed.

@dsinn
Copy link

dsinn commented Nov 15, 2024

@jewilmeer Indeed, I was able to reproduce the issue on master. I suspect that because the json gem isn't pinned, the latest CI runs install a version that is greater than 2.7.6, the newer versions' JSON.pretty_generate({}) behaves differently, as it no longer contains a newline. Compare:

Old behaviourNew behaviour
$ irb
irb(main):001> require "json"
=> true
irb(main):002> JSON::VERSION
=> "2.7.6"
irb(main):003> puts JSON.pretty_generate({})
{
}
=> nil
$ irb
irb(main):001> require "json"
=> true
irb(main):002> JSON::VERSION
=> "2.8.2"
irb(main):003> puts JSON.pretty_generate({})
{}
=> nil

The test fails because RailsAdmin's Json field class calls JSON.pretty_generate, and the test's regex is expecting at least one newline from its result. As a quick test, I made the following change, and the tests pass:

diff --git a/spec/rails_admin/config/fields/types/json_spec.rb b/spec/rails_admin/config/fields/types/json_spec.rb
index a1e03958..a749d930 100644
--- a/spec/rails_admin/config/fields/types/json_spec.rb
+++ b/spec/rails_admin/config/fields/types/json_spec.rb
@@ -24,7 +24,7 @@ RSpec.describe RailsAdmin::Config::Fields::Types::Json do
     it 'returns correct value for empty json' do
       allow(object).to receive(:json_field) { {} }
       actual = field.with(bindings).formatted_value
-      expect(actual).to match(/{\n+}/)
+      expect(actual).to match(/{\n*}/)
     end
 
     it 'retuns correct value' do
@@ -72,7 +72,7 @@ RSpec.describe RailsAdmin::Config::Fields::Types::Json do
     it 'returns correct value for empty json' do
       allow(object).to receive(:json_field) { {} }
       actual = field.with(bindings).export_value
-      expect(actual).to match(/{\n+}/)
+      expect(actual).to match(/{\n*}/)
     end
 
     it 'returns correct value' do

I don't see any need for the newline, so I'd lean towards just updating the test (whether to split the change into a separate PR is up to you and the maintainers), but I'm also not a frequent user of RailsAdmin.

@jewilmeer
Copy link
Contributor Author

@dsinn Thanks for figuring this out. I'm not sure what the idea of the gem versioning of the gem is. Pinning certain gems at a higher version might force some of the gem users to upgrade. Not sure if the idea is to keep it as wide as possible.

But I'm also not sure if the json spec makes a lot of sense. We might want to test if the result is parseable as JSON, instead of matching against a string with regexp.

Gemfile Outdated
@@ -49,7 +49,7 @@ group :active_record do
platforms :ruby, :mswin, :mingw, :x64_mingw do
gem 'mysql2', '>= 0.3.14'
gem 'pg', '>= 1.0.0'
gem 'sqlite3', '~> 1.3'
gem 'sqlite3', '~> 2.2'
Copy link
Member

Choose a reason for hiding this comment

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

Changing a Gemfile entry causes every files under gemfiles/ to change, once you run appraisal generate. If your intention is to use sqlite3 ~> 2.2 only for Rails 8, you need to move this to Appraisal so other Rails versions can stay on sqlite 1.x.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've upgraded the sqlite version for all.

Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't. That's why builds for older Rails versions are failing.
https://github.com/railsadminteam/rails_admin/actions/runs/11931789920/job/33255380343?pr=3702

Choose a reason for hiding this comment

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

@jewilmeer
Please check, as this #3702 (comment) is linked with @mshibuya's comment.

@mshibuya
Copy link
Member

I support the JSON spec change #3702 (comment) proposed by @dsinn, as the existence of newline is irrelevant to the purpose of the spec here.

@jewilmeer
Copy link
Contributor Author

I've managed to update to sqlite3 2.2 only for rails 8, but the dummy app in the specs is not happy with in. I don't have the knowledge to resolve it myself. Can any of you help out?

@mshibuya
Copy link
Member

OK I can take care of the rest. Thanks.

@mshibuya mshibuya merged commit 5412857 into railsadminteam:master Nov 23, 2024
20 of 25 checks passed
mshibuya added a commit that referenced this pull request Nov 23, 2024
- Fix Rails 7.0/7.1 builds
- Remove spec/dummy_app/Gemfile.rails6, as it's not used much
@k-tsuchiya-jp
Copy link

@mshibuya
Thank you for your contribution.
Could you kindly let me know when it will be released?

@codealchemy codealchemy mentioned this pull request Dec 7, 2024
@mshibuya
Copy link
Member

mshibuya commented Dec 8, 2024

Just released 3.3.0, which includes this change 🚀

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.

4 participants