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

have_and_belongs_to_many and inherited models? #914

Closed
Arpsara opened this issue Mar 10, 2016 · 2 comments
Closed

have_and_belongs_to_many and inherited models? #914

Arpsara opened this issue Mar 10, 2016 · 2 comments

Comments

@Arpsara
Copy link

Arpsara commented Mar 10, 2016

Hi!

First of all, thank you for providing this great gem! :)

It seems I have an issue when I try to use a "have_and_belongs_to_many" matcher in an inherited model.

My models:

class User < ActiveRecord::Base
end

class Partner < ActiveRecord::Base
    has_and_belongs_to_many :customers
end

class Customer < User
    has_and_belongs_to_many :partners
end

My rspec tests:

RSpec.describe Customer, type: :model do
  it { should have_and_belongs_to_many(:partners) }
end

The it { should have_and_belongs_to_many(:partners) } raise me that failure:
expected #<Customer:0x00000006278818> to respond tohas_and_belongs_to_many?`

I have the same failure when trying to use it the partner model:
expected #<Partner:0x00000008e9b8c8> to respond tohas_and_belongs_to_many?`

RSpec.describe Partner, :type => :model do
  it { should have_and_belongs_to_many :customers }
end

I tried with a has_one and has_many association, the matchers seems to work fine.

@Arpsara Arpsara changed the title shoulda-matchers and inherited models? has_and_belongs_to_many and inherited models? Mar 10, 2016
@Arpsara Arpsara changed the title has_and_belongs_to_many and inherited models? have_and_belongs_to_many and inherited models? Mar 10, 2016
@adammcfadden
Copy link

@Arpsara - Try dropping the "s". It looks like you have have_and_belongs_to_many, the method you want is have_and_belong_to_many

http://matchers.shoulda.io/docs/v3.1.1/Shoulda/Matchers/ActiveRecord.html#have_and_belong_to_many-instance_method

@Arpsara
Copy link
Author

Arpsara commented Mar 14, 2016

Oh, thank you Adam, that was the problem! :Thanks a lot for your help!

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

No branches or pull requests

2 participants