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!
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 PointsDestroying friendships (not literally, just the lesson) delete method error
Hey got a error when defining 'destroy' on the "friendships_controller" saying that the delete method isn't defined.
1) Error:
test: #destroy when logged in should delete user friendships. (UserFriendshipsCo
ntrollerTest):
NoMethodError: undefined method `delete' for nil:NilClass
So I was wondering should I make an empty "def delete" in the friendships controller?
Also here's the argument that it's complaining about,
should "delete user friendships" do
assert_difference 'UserFriendship.count', -2 do
delete :destroy, id: @user_friendship
end
5 Answers

Allan Evans
9,501 PointsOops found it, I should have had the users(:drew) actually = users(:allan). Once again it's a typing error on my part.

Yonatan Schultz
12,045 PointsLooks like it's having trouble finding @user_friendship. Have you tried just giving it an id:? Maybe id: 1?

Allan Evans
9,501 PointsHmm, I tried that out and got a different error saying that it couldn't find the id "1", but I thought it would be able to find @user_friendship due to the 'context'.
context "when logged in" do
setup do
@friend = create(:user)
@user_friendship = create(:accepted_user_friendship, friend: @friend, user: users(:allan))
create(:accepted_user_friendship, friend: users(:drew), user: @friend)
sign_in users(:allan)
end
should "delete user friendships" do
assert_difference 'UserFriendship.count', -2 do
delete :destroy, id: @user_friendship
end
end
should "set the flash" do
delete :destroy, id: @user_friendship
assert_equal "Friendship destroyed", flash[:success]
end
end
4th line, it shows a created '@user_friendship and what is inside.

Yonatan Schultz
12,045 PointsNice! Glad to hear you found the culprit. Debugging is turning my brain to mush. I think it's time for a day of comic books and soda pop.

Allan Evans
9,501 PointsYeah been playing to much bioshock myself.