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


Assign 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

    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

        should "assign a user_friendship" do
            assert assigns(:user_friendship)
            assert_equal @user_friendship, assigns(:user_friendship)

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

Jason also edited the routes file, so here is the user_friendships resource:

resources :user_friendships do
    member do
      put :accept

1 Answer

Jason Seifer
Jason Seifer
Treehouse Guest Teacher

Hey 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!