-
-
Notifications
You must be signed in to change notification settings - Fork 909
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
WIP #547
WIP #547
Conversation
@@ -747,7 +747,7 @@ def have_and_belong_to_many(name) | |||
# @private | |||
class AssociationMatcher | |||
delegate :reflection, :model_class, :associated_class, :through?, | |||
:join_table, :polymorphic?, to: :reflector | |||
:join_table_name, :polymorphic?, to: :reflector |
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.
Align the parameters of a method call if they span more than one line.
Thanks @Adam89, do you want to rename the commit message? |
@mcmire this is a work in progress commit. I think I should rename it as soon as it's ready to be reviewed. |
This is taking me a really long time and am sorry about that. Just having trouble figuring out how to test all the different cases for |
Now `has_and_belongs_to_many` has a `join_table` option that matches correctly on existing join tables.
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 blank line detected.
@Adam89 Ah ok. No worries then. Take your time :) |
@mcmire could you suggest some other cases I should test, like rejecting a invalid join_table name with the correct error message? |
@@ -830,8 +830,24 @@ def having_one_non_existent(model_name, assoc_name, options = {}) | |||
expect(having_and_belonging_to_many_relatives). | |||
to have_and_belong_to_many(:relatives).validate(false) | |||
end | |||
|
|||
it 'accepts a valid association with a join_table' do | |||
create_table :developers_relatives, id: false do |t| |
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.
Would it be a good idea to choose a different name for this table than the default, so as to prevent false positives?
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.
That makes sense, thank you
Hmm... I've never tried to test for this before. Let's see...
|
Instead of using the default name of the join_table choose a different one to prevent false positives.
Thanks man this has been really interesting. |
Any idea why the build failed, seems irrelevant to the work I did in this pr Could not find gem 'jquery-rails (>= 0) ruby' in the gems available on this |
@Adam89 I think I broke master again :( I'll get it fixed shortly. |
No problem @mcmire I thought I broke the build and it only worked on my machine, nothing worse than that type of failure. |
Any updates? |
And what about |
Hi @simonoff I hope to work on this over the weekend and try to finish the pr off. As for |
def initialize(join_table, name) | ||
@join_table = join_table | ||
@name = name | ||
@missing_option = '' |
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.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
One of my specs fails when I run the version below; BUNDLE_GEMFILE=/Users/Adam/code/projects/shoulda-matchers/gemfiles/4.1.gemfile bundle exec rspec spec/shoulda/matchers/active_record/association_matcher_spec.rb:834
The interesting thing is no other version of the gemfiles fail. After some investigating it turns out that in rails 4.1.0
Whereas when we run rails 4.0.1
Am not sure what change in rails 4.1 caused this issue, maybe this issue has something to do with it rails/rails#15671 ? cc @mcmire |
If I had to guess, I'd say it's a result of changing Maybe we need a convenience method in ModelReflection to work around this? |
Also it looks like I misunderstood what you meant before -- you were trying to figure out what tests to write.
|
Why do we have to make a change ModelReflection, when the failure is caused by a change in the way reflect_on_association works in rails 4.1? The tests pass for every other version of rails but for rails 4.1 reflect_on_association returns a instance of ThroughMatcher.
|
Its a bug in rails 4.1.0 that causes the spec to fail and it was addressed in rails/rails#15753, so by updating to rails 4.1.4 all the specs pass. What should I do @mcmire, should I update the version in the gem file to a specific patch? |
Great now another spec fails after upgrading to rails 4.1.4, this is slowly starting to get more and more complex.
|
I don't see how this has to do with rails/rails#15753. If it did, then you'd be getting In Rails 4.1, class Person < ActiveRecord::Base
has_and_belongs_to_many :relatives
end is like saying: class HABTM_Relatives
belongs_to :left_side, class: Person
belongs_to :relative
end
class Person < ActiveRecord::Base
has_many :people_relatives, class: HABTM_Relatives, source: :left_side
has_many :relatives, through: :people_relatives, source: :relative
end So when you access the reflection for the association, you're actually going to get the reflection for the But let's stay focused. I don't see how the tests magically pass under 4.1.4. Are you sure you're running the test under the proper gemset? i.e.:
|
Thanks for the explanation on how In order to make sure that tests did not pass on rails 4.1.4, I deleted my local version of shoulda-matchers and cloned it again. Then I ran the following command |
Thanks for the update. That's interesting... let me play with your branch and get back to you. I don't want to upgrade to 4.1.4 in this PR, that should be done in another PR, so maybe there is a way to get this to work without upgrading just yet. |
Some developers might want to pass a :join_table option to their HABTM association declarations (e.g., `has_and_belongs_to_many :posts, join_table: :users_and_their_posts). Those same developers, may want to explicitly test the existence of the join table. Make this possible.
Well, it looks like me and @Adam89 have been duplicating efforts a little bit. I was working on implementation a join table matcher as well, and I think it's been merged into master. |
Ahhh... I see. I guess this does foil your efforts @Adam89, doesn't it... What do you think about letting @jacobsimeon take this over, Adam? |
Yeah that's fine @mcmire, it was a great learning experience and I hope to be able to solve issues more swiftly next time. Thanks for informing @jacobsimeon |
Some developers might want to pass a :join_table option to their HABTM association declarations (e.g., `has_and_belongs_to_many :posts, join_table: :users_and_their_posts). Those same developers, may want to explicitly test the existence of the join table. Make this possible.
Some developers might want to pass a :join_table option to their HABTM association declarations (e.g., `has_and_belongs_to_many :posts, join_table: :users_and_their_posts). Those same developers, may want to explicitly test the existence of the join table. Make this possible.
join_table
on matcher tojoin_table_name