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

has_and_belongs_to_many .join_table not working with symbolized table name #1321

Closed
allisonphillips opened this issue Jul 23, 2020 · 1 comment · Fixed by #1323
Closed

has_and_belongs_to_many .join_table not working with symbolized table name #1321

allisonphillips opened this issue Jul 23, 2020 · 1 comment · Fixed by #1323

Comments

@allisonphillips
Copy link

allisonphillips commented Jul 23, 2020

I am experiencing errors when trying to add shoulda matcher specs for has_and_belongs_to_many relationships for classes that are not dependent on any gem. At first I thought I had forgotten to configure something, but then I reproduced by writing the same example for similar classes that has long been functioning in a production environment without issue. All this syntax works:

# class
has_and_belongs_to_many :association_name,
  class_name:              '::AssociationClass',
  join_table:              :join_table_name_that_definitely_exists,
  foreign_key:             foreign_key_id,
  association_foreign_key: association_foreign_key_id

# spec
it do
  should have_and_belong_to_many(:association_name)
    .class_name('::AssociationClass')
    .with_foreign_key(:foreign_key_id)
    .with_foreign_key(:association_foreign_key_id)
end

But as soon as I add .join_table(:join_table_name_that_definitely_exists) to the example block in the spec, I get the equivalent of this message:

"Expected #{described_class} to have a has_and_belongs_to_many association " \
"called #{association_name} (join table #{join_table_name} doesn't exist)"

I eventually figured out that the matcher works if you pass the join table name as a string. It appears that the matcher doesn't support table names as a symbol.

Originally posted by @allisonphillips in #625 (comment)

@mcmire
Copy link
Collaborator

mcmire commented Jul 25, 2020

Thanks for submitting this separately! I've got a fix for this in #1323.

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

Successfully merging a pull request may close this issue.

2 participants