Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Matt Slawson
11,406 PointsNameError
I'm having trouble with the following test from "Working with Associations"
''' test "that creating friendships on a user works" do users(:jason).friends << users(:mike) users(:jason).friends.reload assert users(:jason).friends.include?(users(:mike)) end '''
When I run the test I'm receiving the following error:
'''
Running tests:
.........E.
Finished tests in 0.159214s, 69.0894 tests/s, 100.4937 assertions/s.
1) Error:
test_that_creating_friendships_on_a_user_works(UserTest):
NameError: uninitialized constant User::Friend
/Users/matt/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/inheritance.rb:111:in compute_type'
/Users/matt/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/reflection.rb:172:inklass'
/Users/matt/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/associations/association.rb:202:in raise_on_type_mismatch'
/Users/matt/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/associations/has_many_through_association.rb:33:inblock in concat'
/Users/matt/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/associations/has_many_through_association.rb:32:in each'
/Users/matt/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/associations/has_many_through_association.rb:32:inconcat'
/Users/matt/.rbenv/versions/1.9.3-rc1/lib/ruby/gems/1.9.1/gems/activerecord-3.2.6/lib/active_record/associations/collection_proxy.rb:116:in <<'
test/unit/user_test.rb:60:inblock in <class:UserTest>'
11 tests, 16 assertions, 0 failures, 1 errors, 0 skips '''
I know that the fixtures are created properly. Any ideas Jason Seifer ? Thanks for the help!
3 Answers
Jason Seifer
Treehouse Guest TeacherHey Matt Slawson what do your association lines in your User model look like? It can't find the Friend constant which leads me to think that maybe your has_many :friends, through: :user_friendships line may be a bit out of whack.
Matt Slawson
11,406 PointsI got it sorted. Thanks Jason Seifer
John Murphy
1,122 PointsHey Matt - I'm having the exact same issue. Can you please describe what you did to fix it?
Thanks
Matt Slawson
11,406 PointsJohn - It's been a long time, I'll have to take a look back and see if I can see what I did. Should've documented it here. I'll get back to you.
John Murphy
1,122 PointsOk no problem - thanks Matt. I've exhausted all of my Ruby knowledge trying to figure this out so any help would be great.
Matt Slawson
11,406 PointsI got it sorted. Thanks Jason Seifer