-
-
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
shoulda-matchers looking for join table names including schema #625
Comments
Hmm, interesting. What does your model look like? |
I should add what is almost certainly involved: I'm using the Apartment gem, which implements multitenancy via multiple schemas, and Region and User are two excluded classes that are always referenced through the public schema. In fact, having read through more of Apartment, that is absolutely involved here. I'm just not sure how. I can also post this as a bug report on their repository too. Even though I don't think it's gonna help, I want to answer your question anyway:
|
I see. Well, it is certainly odd to me that you're getting that message. It at least should say
As far as the join table is concerned, it pulls that from the association itself, that is, it should be getting an association called |
I'm getting a strange error, it may be related. If you don't think so I can open another issue: class Course < ActiveRecord::Base
has_and_belongs_to_many :categories, join_table: :course_categories
end
class Category < ActiveRecord::Base
has_and_belongs_to_many :courses, join_table: :course_categories
end
RSpec.describe Course, type: :model do
describe 'associations' do
it { is_expected.to have_and_belong_to_many(:categories).join_table(:course_categories) }
end
end Error: Failure/Error: it { is_expected.to have_and_belong_to_many(:categories).join_table(:course_categories) }
Expected Course to have a has_and_belongs_to_many association called categories (join table course_categories doesn't exist) Using version 3.0.1 |
Obvious question, but just to be sure -- I'm assuming that |
@mcmire yup! its in the schema and I've tried dropping the db, creating again, checked for typos and all that :) |
@yogodoshi Okay, weird. This may be related, but go ahead and make a new issue for this. If you can re-create this bug in a fresh Rails app and then post it up in a repo, that'll help me zero in on what the deal is here. |
@pcragone please were you able to resolve this issue in your app, I have run into the same problem, class User < ApplicationRecord
has_and_belongs_to_many :markets
end
class Market < ApplicationRecord
has_and_belongs_to_many :administrators, class_name: 'User'
end
describe User, type: :model do
it { is_expected.to have_and_belong_to_many :markets }
end Error
|
I have the same problem. Did you get a fix? |
I am also experiencing this when trying to add shoulda matcher specs for # 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 "Expected #{described_class} to have a has_and_belongs_to_many association " \
"called #{association_name} (join table #{join_table_name} doesn't exist)" Was another issue ever opened for this? Update: I 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. Leaving that here in case it helps others. |
@allisonphillips Yes, this was already answered here: #914 (comment) Try dropping the "s". It looks like you have have_and_belongs_to_many, the method you want is have_and_belong_to_many Million thanks to @adammcfadden for solution! |
@nimeshnikum I'm confused... is that supposed to be in response to me? I did not pluralize 'belongs' in my matcher example code, nor did the other commenters. The references to |
Hi @allisonphillips, I don't think an Issue has been created yet around the problem you're seeing (using a symbol with |
I'm going to close this issue since this is pretty rare and (although I can't say for certain) I don't think it's the fault of shoulda-matchers. The |
|
So I've got two models with habtm between them; called Region and User. So I need a join table called "regions_users"; however, doing:
Gives me the error:
Obviously that's not accurate postgres syntax, and the code works as it should. Please correct me if I'm wrong, but it seems to be a problem with shoulda-matcher.
The text was updated successfully, but these errors were encountered: