-
Notifications
You must be signed in to change notification settings - Fork 176
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
Mongoid 6 conflicts #197
Mongoid 6 conflicts #197
Conversation
The check should really run once. Maybe take a dependency on https://github.com/mongoid/mongoid-compatibility and fix using that? We also really need mongoid versions in the test matrix - that repo has a good example on how to do that. |
@dblock added mongoid versions test using mongoid-compatibility. Please Let me know if I missed something. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant to add mongoid-compatibility that adds methods such as mongoid6?
and removing any such code here. LMK if I am making no sense :)
lib/mongoid/rspec.rb
Outdated
@@ -38,3 +38,14 @@ module Matchers | |||
include Mongoid::Matchers::Validations | |||
end | |||
end | |||
|
|||
module Mongoid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't exist anymore, it would come from mongoid-compatibility.
spec/compatibility/version_spec.rb
Outdated
@@ -0,0 +1,33 @@ | |||
require 'spec_helper' | |||
|
|||
RSpec.describe Mongoid::Compatibility::Version do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to be testing mongoid-compatibility here?
More importantly we/you want to update the .travis.yml configuration here to run against multiple versions of mongoid. |
Bump @saumyamehta17 |
@dblock Sorry for delay in reply, I am bit occupied with my office work. Honestly, I am new to open source contribution and might be asking obvious (dumb) questions/doubts :) What I understood:
Please let me know if there is any gap. |
No worries, I'm here to help! You got it right. Just keep iterating and I'll try to make things clearer as we make progress. Hang in there. |
Looks like there're real failures with Mongoid 5, trying to use classes that don't exist in that version. I think instead of creating separate gemfiles you want something like what we do in https://github.com/mongoid/mongoid-compatibility. Maybe copy from there? |
lib/matchers/indexes.rb
Outdated
@@ -0,0 +1,84 @@ | |||
module Mongoid | |||
module Matchers | |||
class HaveIndexForMongoid3 # :nodoc: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class should be the same name for different versions. Make lib/matchers/indexes/v3/have_index_for.rb
and lib/matchers/indexes/v4/have_index_for.rb
for example and include the right file. This will reduce the switching.
I've added the Danger token to Travis-CI, so that should be working now. |
.gitignore
Outdated
@@ -4,3 +4,47 @@ | |||
Gemfile.lock | |||
pkg/* | |||
|
|||
*.rbc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't just copy-paste a bunch of stuff, only things that are needed. See what is being created during build and exclude those.
lib/matchers/associations.rb
Outdated
@@ -1,5 +1,4 @@ | |||
require 'mongoid/relations' | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space is cheap, put this back :)
lib/matchers/indexes.rb
Outdated
@klass = klass.is_a?(Class) ? klass : klass.class | ||
@errors = [] | ||
|
||
if @klass.respond_to?(:index_options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this code is quite different for different versions, break this up into v3/have_index_for.rb, v4/have_index_for.rb, etc. If the index is backward compatible, eg. index for v5 works for v6, just include that one as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to inherit common code, so Mongoid::Matchers::HaveIndexFor < Mongoid::Matchers::HaveIndexFor::Base
or something like that.
lib/matchers/indexes.rb
Outdated
end | ||
|
||
def have_index_for(index_fields) | ||
HaveIndexForMongoid3.new(index_fields) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To inherit this you can do self.new
in the base class.
lib/mongoid/rspec.rb
Outdated
@@ -38,3 +42,14 @@ module Matchers | |||
include Mongoid::Matchers::Validations | |||
end | |||
end | |||
|
|||
# module Mongoid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete this.
Here's an example of a CHANGELOG.md entry: * [#197](https://github.com/mongoid/mongoid-rspec/pull/197): Mongoid 6 conflicts - [@saumyamehta17](https://github.com/saumyamehta17). Generated by 🚫 danger |
Danger is now working, if you want to enable it as part of this PR it needs a CHANGELOG file. Usually I got back a little and try to dig up history from Rubygems, but you can also do this later. Otherwise this build is green, see my comments above. Lets finish it? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good progress on subclassing HaveIndexFor
, but there's still code that does if
in the child class between versions of mongoid that needs to be in version-specific classes. You also have to make Danger happy or just remove it from this PR for now and make that a separate PR in the future (recommended).
@@ -0,0 +1,18 @@ | |||
module Mongoid | |||
module Matchers | |||
module Base |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modules are namespaces, so Base
isn't a great choice for a module because it doesn't make great sense to organize all base classes together. If all matchers have a base class then just make this class Mongoid::Matchers::Base
. If all HaveIndexFor
have a base, you can call it Mongoid::Matchers::HaveIndexForBase
or even Mongoid::Matchers::HaveIndexFor::Base
(just declare HaveIndexFor
as a Class
for the last case).
@index_options = index_options | ||
self | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra line.
|
||
def matches?(klass) | ||
@klass = klass.is_a?(Class) ? klass : klass.class | ||
@errors = [] | ||
|
||
if @klass.respond_to?(:index_options) | ||
# Mongoid 3 | ||
unless @klass.index_options[@index_fields] | ||
@errors.push "no index for #{@index_fields}" | ||
unless @klass.index_options[@index_key] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this code was here before, but it's a good idea to use a property from the base class, so index_key
instead of @index_key
and klass
instead of @klass
. Properties should be declared like attr_reader
.
if !@index_options.nil? && !@index_options.empty? | ||
@index_options.each do |option, option_value| | ||
if denormalising_options(@klass.index_options[@index_key])[option] != option_value | ||
@errors.push "index for #{@index_key.inspect} with options of #{@klass.index_options[@index_key].inspect}" | ||
end | ||
end | ||
end | ||
end | ||
else | ||
# Mongoid 4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in a version-specific class.
def have_index_for(index_fields) | ||
HaveIndexForMongoid3.new(index_fields) | ||
end | ||
# Class Ends here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a very useful comment ;)
lib/mongoid/rspec.rb
Outdated
@@ -29,10 +29,11 @@ | |||
require 'matchers/be_dynamic_document' | |||
require 'matchers/be_stored_in' | |||
require 'matchers/have_field' | |||
require 'matchers/indexes/have_index_for' | |||
if Mongoid::Compatibility::Version.mongoid4_or_newer? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicking, but it's probably better to check whether it's mongoid3?
and switch the if
around. It's a more exact if
.
…ed unwanted lines and comments
Merged. Thanks for your excellent work @saumyamehta17 and for hanging in there. You can/should tackle the following next if you want that weren't blockers:
|
Thanks. I will be working.
Regards,
Saumya Mehta
…On Fri, Jan 5, 2018 at 12:34 AM, Daniel Doubrovkine (dB.) @dblockdotorg < ***@***.***> wrote:
Merged. Thanks for your excellent work @saumyamehta17
<https://github.com/saumyamehta17> and for hanging in there.
You can/should tackle the following next if you want that weren't blockers:
- Compatibility section needs to be updated in README. This gem now
works for all the versions out of the box.
- There's still code that says this gem is compatible with Mongoid 2
(Gemfile, .gemspec), however we no longer test against mongoid 2. Either
put it back and have a passing build or remove it from everywhere.
- Links to badges/Travis-CI/codeclimate look wrong in README.
- Writing a CHANGELOG and re-adding Danger.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#197 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AD169LK2RW_iZudUcfhgrRDjmk62CjUTks5tHSCggaJpZM4QTf7e>
.
|
Nice fix. FYI - I noticed that I needed to add the
I see that it is included in the .gemspec file as a dependency, but my rails project did not pick it up. Maybe has something to do with including |
@khaight What happens without? You should raise a bug. We include that dependency in https://github.com/mongoid/mongoid-rspec/blob/master/mongoid-rspec.gemspec#L24 and it shouldn't be required. |
@dblock without adding
|
No description provided.