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

NoMethodError when testing with join_table #476

Closed
coding-brigadier opened this issue Apr 13, 2014 · 20 comments
Closed

NoMethodError when testing with join_table #476

coding-brigadier opened this issue Apr 13, 2014 · 20 comments

Comments

@coding-brigadier
Copy link

I have the following line in my code:
has_and_belongs_to_many :future_cars, :join_table => :users_future_cars, :class_name => "Car"

The test line is
it { should have_and_belong_to_many(:future_cars).join_table(:users_future_cars).class_name("Car") }, but for some reason this throws the following error:

Failure/Error: it { should have_and_belong_to_many(:future_cars).join_table(:users_future_cars).class_name("Car") }
     NoMethodError:
       undefined method `reflect_on_association' for NilClass:Class

All the tables do exist and everything works with manual testing.

@mcmire
Copy link
Collaborator

mcmire commented Apr 13, 2014

Thanks for the report. Which version of Rails are you on?

@coding-brigadier
Copy link
Author

Rails 4.1 with Ruby 2.1.1

@mcmire mcmire added the Bug label Apr 14, 2014
@mcmire mcmire added this to the 2.7.0 milestone Apr 14, 2014
@whatyouhide
Copy link

+1 (Rails 4.0.1, Ruby 2.1.1)

@mcmire mcmire modified the milestones: 2.6.1, 2.7.0 Apr 16, 2014
@mcmire
Copy link
Collaborator

mcmire commented Apr 16, 2014

So join_table is actually not an option. It does exist as a method, but it cannot be used to test a custom join table.

@mcmire mcmire closed this as completed Apr 16, 2014
@coding-brigadier
Copy link
Author

@mcmire So what you are saying is that the method exists, but is unusable?

@mcmire
Copy link
Collaborator

mcmire commented Apr 17, 2014

Yup -- it's a method that's internal to the matcher. Unfortunately when the name was chosen we didn't realize that it's also an option to habtm.

I'll actually reopen this issue as it is a legitimate usability bug.

@mcmire mcmire reopened this Apr 17, 2014
@mcmire mcmire modified the milestones: 2.6.1, 2.7.0 Apr 18, 2014
@jacobsimeon
Copy link
Contributor

What about renaming join_table to join_table_name and adding support for the join_table option?

@mcmire
Copy link
Collaborator

mcmire commented Apr 28, 2014

That would be fine with me. I don't have time for this right now but if you want to take a crack at it that would be great!

@jacobsimeon
Copy link
Contributor

Sounds good. I'll get on it, but I'd prefer to wait until we come to a conclusion on #511.

@mrageh mrageh self-assigned this May 28, 2014
@mrageh
Copy link

mrageh commented Jun 13, 2014

Has anyone started to work on this issue?

@mrageh
Copy link

mrageh commented Jun 13, 2014

@mcmire I don't fully understand what the problem is, we have defined model_reflection#join_table and it seems to work as expected. If you could give me some more insight I could try to fix this over the weekend.

@mcmire
Copy link
Collaborator

mcmire commented Jun 13, 2014

@Adam89 The problem is that the OP expected join_table to be an option, something you could call on the chain. This makes sense because there's a :join_table option on has_and_belong_to_many.

join_table is a method on our matcher but it isn't an option. The fix is to rename the current join_table method to something else and then, separately, implement join_table as an option.

@mrageh
Copy link

mrageh commented Jun 25, 2014

I am working through this issue and the strange thing is I keep on getting a message of

Username for 'https://github.com': Adam89
Password for 'https://[email protected]':
remote: Permission to thoughtbot/shoulda-matchers.git denied to Adam89.
fatal: unable to access 'https://github.com/thoughtbot/shoulda-matchers.git/': The requested URL returned error: 403

Any help is appreciated

cc @mcmire

@mrageh
Copy link

mrageh commented Jun 25, 2014

A I understand what the problem is, I am now going to have to make a fork and the push to my own fork since I am no longer a collaborator.

Thanks

@mrageh mrageh mentioned this issue Jun 25, 2014
Closed
@jacobsimeon
Copy link
Contributor

Ok, so now that we have a join table sub-matcher, I think it will be simple enough to implement this feature. @Adam89 are you still working on it? Would you mind if i give it a go?

@mcmire mcmire modified the milestones: 2.7.0, 2.7.1 Sep 3, 2014
@mcmire mcmire removed this from the 2.7.0 milestone Sep 3, 2014
@GolfyMcG
Copy link

+1 on this issue for me. Was a resolution ever reached?

PS. Rails 4.1.8, Ruby 2.1.4

@mcmire
Copy link
Collaborator

mcmire commented Dec 12, 2014

No, there's a PR open for it (#556) but it needs to be finished out.

@GolfyMcG
Copy link

Oh - thank you for the heads up. I'll check it out.

@maurogeorge
Copy link
Contributor

@mcmire I think we can close this, since the af85ac1 was merged, the full PR to get more context #556.

@mcmire
Copy link
Collaborator

mcmire commented Apr 21, 2015

You're right, thanks!

@mcmire mcmire closed this as completed Apr 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants