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
Allan Evans
9,501 PointsManaging Friendships, problems with the UI and displaying the correct statuses.
Hey guys, just trying to clean up the ruby code, but I'm having several errors, but I can't seem to find the right way to fix them.
Here's a failure for the user_test:
1) Failure:
test: #has_blocked? should return true if a user has blocked another user. (Use
Test) [test/unit/user_test.rb:73]:
Failed assertion, no message given.
Here's the code it mentions:
context "#has_blocked?" do
should "return true if a user has blocked another user" do
> assert users(:allan).has_blocked?(users(:blocked_friend))
end
user_friendship_controller_test, 2 different errors:
test: #index when logged in accepted friendships should get the index without error. (UserFriendshipsControllerTest):NoMethodError: undefined method accepted_user_friendships' for #<User:0x4cc9ba8
test: #index when logged in should display date information on an accepted friendship. (UserFriendshipsControllerTest): ArgumentError: Invalid selector: .
Here's the failures:
test: #index when logged in pending friendships should not display pending or active friend's names. (UserFriendshipsControllerTest) [test/functional/user_friendships_controller_test.rb:77]:
</Blocked/> expected to not match
test: #index when logged in requested friendships should not display pending or active friend's names. (UserFriendshipsControllerTest) [test/functional/user_friendships_controller_test.rb:96]: </Blocked/> expected to not match
The line of code it mentions:
should "not display pending or active friend's names" do
> assert_no_match /Blocked/, response.body
assert_no_match /Active/, response.body
end
should "not display pending or active friend's names" do
> assert_no_match /Blocked/, response.body
assert_no_match /Active/, response.body
end
Sorry it's so long, I've been having a hard time finding the answers so I went ahead and finished the entire lesson. If you need any more info let me know, thanks.
4 Answers
Maxwell Muir
4,760 PointsHey, I was getting a similar error to yours. I've been following along with the coding in the videos and missed something in the user.rb on the has-many associations. Since he copied and pasted all the way down, I missed some of the changes that were done in the process (or they weren't done on screen). Anyway, check your has_many setups and make sure the "through" sections are properly updated.
Incorrect code (caused the same error you got):
has_many :blocked_user_friendships, class_name: 'UserFriendship',
foreign_key: :user_id,
conditions: { state: 'blocked' }
has_many :blocked_friends, through: :pending_user_friendships, source: :friend
Corrected:
has_many :blocked_user_friendships, class_name: 'UserFriendship',
foreign_key: :user_id,
conditions: { state: 'blocked' }
has_many :blocked_friends, through: :blocked_user_friendships, source: :friend
Jason Seifer
Treehouse Guest TeacherHey Allan Evans can you post a link to your code up on GitHub so I can take a look?
Allan Evans
9,501 PointsHey Jason, finally got it working properly. I found the massive mistake that was staring at me for the last couple of months, lets just say it was treebook within another treebook. Thanks for your help.
Allan Evans
9,501 PointsOk, I git pushed it to the repository, my user name is aevans27, thanks again!
Allan Evans
9,501 PointsHey Jason, any luck finding where my errors are? I built a new PC and just downloaded the treehouse files I saved in git hub. Thanks again.
Allan Evans
9,501 PointsAllan Evans
9,501 PointsThanks, I had that error as well, I also finally realized I had a huge mistake when I brought the treebook folder on my new computer.
Alvis Hall
2,997 PointsAlvis Hall
2,997 PointsThanks Max, this helped! I found my problem in the user.rb. I did not have:
has_many :accepted_user_friendships, class_name: 'UserFriendship', foreign_key: :user_id, conditions: { state: 'accepted' } has_many :accepted_friends, through: :accepted_user_friendships, source: :friend