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

Charles Tobias
3,690 PointsAssign a user friendship failure
In the accepting friendships video of the adding states lesson, I get this failure at the beginning of the video when we added the should assign a user_friendship test the the when logged in context of the #accept context of the user friendships controller test. 1) Failure: test: #accept when logged in should assign a user_friendship. (UserFriendshipsControllerTest) [test/functional/user_friendships_controller_test.rb:182]: Failed assertion, no message given.
My #accept context reads as follows:
context "#accept" do
context "when not logged in" do
should "redirect to the login page" do
put :accept, id: 1
assert_response :redirect
assert_redirected_to login_path
end
end
context "when logged in" do
setup do
@user_friendship = create(:pending_user_friendship, user: users(:jason))
sign_in users(:jason)
put :accept, id: @user_friendship
@user_friendship.reload
end
should "assign a user_friendship" do
assert assigns(:user_friendship)
assert_equal @user_friendship, assigns(:user_friendship)
end
end
end
and the accept method of user_friendships_controller.rb reads as follows:
def accept
@user_friendships = current_user.user_friendships.find(params[:id])
redirect_to user_friendships_path
end
Jason also edited the routes file, so here is the user_friendships resource:
resources :user_friendships do
member do
put :accept
end
end
1 Answer

Jason Seifer
Treehouse Guest TeacherHey Charles Tobias you have a typo in your "accept" method. It should be
@user_friendship = current_user.user_friendships.find(params[:id])
Hope that helps!