Created
May 14, 2016 07:30
-
-
Save aamax/62b6125a7fa4760b313ce5e033b5fe0f to your computer and use it in GitHub Desktop.
AR association tests not passing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
has_many :lead_offers | |
has_many :leads, through: :lead_offers | |
end | |
class Lead < ActiveRecord::Base | |
has_many :lead_offers, dependent: :destroy | |
has_many :users, :through => :lead_offer | |
end | |
class LeadOffer < ActiveRecord::Base | |
belongs_to :lead | |
belongs_to :user | |
end | |
class LeadTest < ActiveSupport::TestCase | |
should have_many(:lead_offers) | |
should have_many(:users) | |
end | |
class LeadOfferTest < ActiveSupport::TestCase | |
should belong_to(:lead) | |
should belong_to(:user) | |
end | |
test results... | |
Error: | |
LeadTest#test_: Lead should have many users. : | |
NoMethodError: undefined method `klass' for nil:NilClass | |
NOTES: | |
I found an issue on the web where someone got this error and the person said they missing an association: | |
"You're saying that Subject.has_many :photos, through: :subject_photo_assignments, but you don't have a :subject_photo_assignments association." | |
I've looked at this for a while and am not seeing what is missing... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@aamax:
https://gist.github.com/aamax/62b6125a7fa4760b313ce5e033b5fe0f#file-models-associations-and-tests-L8
Line 8 should be
has_many :users, :through => :lead_offers
, note the pluralization