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_many :as tests #735

Closed
amnesia7 opened this issue Jun 16, 2015 · 4 comments
Closed

have_many :as tests #735

amnesia7 opened this issue Jun 16, 2015 · 4 comments

Comments

@amnesia7
Copy link

I was wondering if :as should be added to have_many.

I have

has_many :favourites, as: :favourable, dependent: :destroy

and am testing it using:

it { should have_many(:favourites).dependent(:destroy) }

Since :as isn't currently available in shoulda-matchers I've also added the following test to my spec file but I'm not sure if I should really be testing anything more as part of :as

it { should respond_to(:favourable) }

Thanks

@maurogeorge
Copy link
Contributor

We are talking here about polymorphic associations right?

I think the it { should have_many(:favourites).dependent(:destroy) } is enough. Since if you change your associations to has_many :favourites, dependent: :destroy you will receive a error like:

     Failure/Error: it { is_expected.to have_many(:favourites).dependent(:destroy) }
       Expected Model to have a has_many association called favourites (Favourite does not have a model_id foreign key.)

Maybe we can add a note on the docs, like we have on the belong_to.

What you think?

@amnesia7
Copy link
Author

Just tested without :as and failed as you say so a note on the docs sounds fine to me.

@mcmire
Copy link
Collaborator

mcmire commented Jun 16, 2015

Yeah, I think a note in the docs makes sense here.

@mcmire
Copy link
Collaborator

mcmire commented Feb 18, 2019

This was fixed a long time ago, and it looks like I forgot to close this. The commit that fixed this was: 670f154

@mcmire mcmire closed this as completed Feb 18, 2019
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

3 participants