Skip to content

Add Ruby 2.3, 2.4, 2.5, and 2.6 and Mongoid 6 and 7 #20

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

Merged
merged 8 commits into from
May 14, 2019
Merged

Add Ruby 2.3, 2.4, 2.5, and 2.6 and Mongoid 6 and 7 #20

merged 8 commits into from
May 14, 2019

Conversation

yuki24
Copy link
Collaborator

@yuki24 yuki24 commented May 14, 2019

It seems like this repo is a bit behind the pace and I thought we should test against more recent versions of Ruby and Mongoid. I got most of the new builds green except for Mongoid 7.

@yuki24
Copy link
Collaborator Author

yuki24 commented May 14, 2019

I had to drop builds for Ruby 1.9.3. It doesn't seem to install on Travis any more and it's very old, so I don't think there's a good reason to maintain support for that.

yuki24 added 2 commits May 14, 2019 01:20
This fixes the error below:

  An error occurred while loading ./spec/array_spec.rb.
  Failure/Error: include ActiveSupport::Callbacks

  NoMethodError:
    undefined method `class_attribute' for Mongoid::CachedJson::Config:Module
@@ -5,7 +5,12 @@ class JsonManager
field :name
field :ssn, default: '123-45-6789'
has_many :json_employees
belongs_to :supervisor, class_name: 'JsonSupervisor'

if Mongoid::VERSION < "6.0.0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not a valid comparison! Use https://github.com/mongoid/mongoid-compatibility 's Mongoid::Compatibility::Version.mongoid6_or_older?

Copy link
Collaborator Author

@yuki24 yuki24 May 14, 2019

Choose a reason for hiding this comment

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

It is totally a valid comparison that people think is silly that works totally fine:

"6.0.1" < "6.0.0" # => false
"6.0.0" < "6.0.0" # => false
"5.10.10" < "6.0.0" # => true
"5.9.9" < "6.0.0" # => true

I don't think we need a dependency.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's take a dependency?

"6.0.0" > "6.0"
# => true

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also note that the dependency would only be for tests.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Another example that fails.

"6.0.0" < "6.0.0.beta" 
# => true

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd use Gem::Version if a more accurate comparison is necessary:

Gem::Version.new("6.0.0") < Gem::Version.new("6.0") # => false
Gem::Version.new("6.0.1") < Gem::Version.new("6.0.0") # => false
Gem::Version.new("6.0.0") < Gem::Version.new("6.0.0") # => false
Gem::Version.new("5.10.10") < Gem::Version.new("6.0.0") # => true
Gem::Version.new("5.9.9") < Gem::Version.new("6.0.0") # => true

Copy link
Collaborator

@dblock dblock May 14, 2019

Choose a reason for hiding this comment

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

That's what mongoid-compatibility does, but smarter and future-proof as it checks major version only and has semantic verbs like mongoid6_or_older? which are easier to read. It just has been convention in mongoid projects since we were doing these comparisons in 10 different ways all over the place.

https://github.com/mongoid/mongoid-compatibility/blob/master/lib/mongoid/compatibility/version.rb

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

as it checks major version only and has semantic verbs like mongoid6_or_older? which are easier to read.

This doesn't sound like a strong counter objection when the Gem::Version comparizon is very simple and easy to understand. Is this something that might take more than an hour to understand, or something that really requires encapsulation?

since we were doing these comparisons in 10 different ways all over the place.

Here we are not trying to understand 10 different sorting algorithms, but just a version comparison, basically a number comparison internally in Gem::Version. Also, could you actually really list 10 different examples? I have seen a few, but I'm sure it doesn't exceed 10.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I noticed it's already a dependency of this project, so I just switched it anyway. However, I'm not convinced that this is a better way as Gem::Version is a more generic abstraction that can be used almost anywhere else, and it doesn't require any specific knowledge about Mongoid.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's all a small deal and either works!

Rakefile Outdated
@@ -1,7 +1,9 @@
# frozen_string_literal: true
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think these should go away, we either do it everywhere or nowhere.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Rubocop disagrees. What would you prefer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually it stopped complaining about it after running with a --auto-gen-config config, so this should be good now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm ok with it.

Personally, I like these to be consistent. So I generally don't have the #frozen in there and disable it in Rubocop or --auto-gen-config. This was added in this diff, that's why I am calling it out. You could revert this file and re-run --auto-gen-config and it would be better.

Rakefile Outdated
@@ -31,4 +33,8 @@ end
require 'rubocop/rake_task'
RuboCop::RakeTask.new

task default: [:rubocop, :spec]
if RUBY_VERSION >= '2.6'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why? Just to save Running rubocop? This feels like it assumes content in .travis.yml and will be hard to debug. Furthermore anyone contributing on Ruby 2.5.3 will forget that Rubocop runs until they push and get a failure. How about changing the rake parameters in .travis.yml and running rubocop for only one matrix line in there?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Alright, I was able to add a separate build that only runs rake rubocop and the default rake now only runs the spec task.

CHANGELOG.md Outdated
------------

* Your contribution here.
* Compatibility with Ruby 2.3, 2.4, 2.5 and 2.6 - [@yuki24](http://github.com/yuki24).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Care to prefix these with a PR link?

[#20](https://github.com/mongoid/mongoid-cached-json/pull/20): Compatibility ...

Copy link
Collaborator

@dblock dblock left a comment

Choose a reason for hiding this comment

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

Thanks!

The README contains a Compatibility section that also needs to be updated. Also since it no longer works, please get rid of the gemnasium badge while you're there.

@dblock
Copy link
Collaborator

dblock commented May 14, 2019

@yuki24 I also invited you to collaborators on this repo cause I know you're dying to co-maintain this and make the next release :) Drop me your rubygems email to dblock at dblock dot org?

peon = manager.json_employees.create(name: 'Peon')
manager.json_employees.create(name: 'Indentured servant')
manager.json_employees.create(name: 'Serf', nickname: 'Vince')
manager = JsonManager.create!(name: 'Boss')
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

CHANGELOG.md Outdated
@@ -1,7 +1,10 @@
1.5.4 (Next)
2.0.0 (Next)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Bump version.rb or undo.

Since the next version is actually compatible with newer mongoid's without changes, and the only "breaking" change is that we drop testing or support on 1.9.3, I would just leave it as 1.5.4, but up to you.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, the next version will probably be compatible with 1.9.3. What version would you prefer? 1.6.0 or you still prefer 1.5.4?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've picked up 1.6.0 to follow semver, but let me know if you have any other preferences.

Copy link
Collaborator

Choose a reason for hiding this comment

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

That works!

- rvm: 2.1.10
env: MONGOID_VERSION=7
allow_failures:
- env: MONGOID_VERSION=7
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just to be clear, I couldn't get the builds for Mongoid 7 so leaving this here for now, but I would like to get them pass once I have enough time to fix them.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok let's deal with that next.

@@ -31,4 +31,4 @@ end
require 'rubocop/rake_task'
RuboCop::RakeTask.new

task default: [:rubocop, :spec]
task default: :spec
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@dblock are you okay with this? I think this might be suprizing for people who use Rubocop regularly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would leave the default as is and run both. This is just because it has been this way for a long time and we like having rubocop in the mongoid org.

@dblock dblock merged commit 0c9c6a6 into mongoid:master May 14, 2019
@dblock
Copy link
Collaborator

dblock commented May 14, 2019

I merged this as is. Let's deal with the other issues next.

@dblock
Copy link
Collaborator

dblock commented May 14, 2019

Thanks for your good work @yuki24 !

@dblock
Copy link
Collaborator

dblock commented May 14, 2019

For Mongoid 7, the changes should be minimal with Mongoid::Relations becoming associations. See https://github.com/mongoid/mongoid-history/pull/221/files for some examples.

@yuki24 yuki24 deleted the test-against-more-mongoids branch May 18, 2019 01:12
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

2 participants