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
Andre Hitchman
11,550 PointsDestroy when logged in error ...
After following the destroying friendships badge on "Building social features on ruby on rails". I stumbled across this error ...
1) Failure:
test: #destroy when logged in should set the flash. (UserFriendshipsControllerTest) [test/functional/user_friendships_controller_test.rb:256]:
<"Friendship destroyed"> expected but was
<"friendship destroyed">.
This is my #delete tests
context "#destroy" do
context "when not logged in" do
should "redirect to the login page" do
delete :destroy, id: 1
assert_response :redirect
assert_redirected_to login_path
end
end
context "when logged in" do
setup do
@friend = create(:user)
@user_friendship = create(:accepted_user_friendship, friend: @friend, user: users(:sammy))
create(:accepted_user_friendship, friend: users(:sammy), user: @friend)
sign_in users(:sammy)
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
end
Any idea why this error shows up?
2 Answers
Ivan Dimitrov
10,587 PointsMay be in your user_friendship_controller.rb file at the #destroy you have set the flash[:success] = 'friendship destroyed' instead of flash[:success] = 'Friendship destroyed'.
Andre Hitchman
11,550 PointsThanks Ivan!, that seemed to have done the trick :)