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
marco berardini
1,340 PointsTreebook undefined method pending_friends
I am working on testing factories I added pending_friends to all file exactly like the video and I get an errors about pending_friends as follows in the user_test.rb getting similar errors in user_friendships_controller_test.rb
ERROR test_that_creating_friendships_on_a_user_works(UserTest): NoMethodError: undefined method `pending_friends' for #<User:0x007ff3f5b65f80>
ERROR test: when logged in with no friend_id with a valid friend_id should create a friendship. (UserFriendshipsControllerTest): NoMethodError: undefined method `pending_friends' for #<User:0x007f8aefa709c8>
2) Failure: test: when logged in with no friend_id with a valid friend_id should set the flash success message. (UserFriendshipsControllerTest) [test/functional/user_friendships_controller_test.rb:115]: Failed assertion, no message given.
2 Answers
marco berardini
1,340 PointsI am using rails 3.2.14
Chris Gray
10,305 PointsHi marco, I've just solved this, it seems there was a jump or something because as soon as I added this
has_many :friends, through: :user_friendships,
conditions: { user_friendships: { state: 'accepted' } }
has_many :pending_user_friendships, class_name: 'UserFriendship',
foreign_key: :user_id,
conditions: { state: 'pending' }
has_many :pending_friends, through: :pending_user_friendships, source: :friend
into the user.rb file everything worked fine.
Hope this helps