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

Ruby

Code challenge : testing controller assignments in ruby on rails treebook app

http://teamtreehouse.com/library/building-social-features-in-ruby-on-rails-2/building-the-friendship-ui/testing-controller-assignments I have trouble with part 2/2 of this challenge, here's my code, can someone help me out ?

class UserFriendshipsControllerTest < ActionController::TestCase
  context "#new" do
    context "when logged in" do
      setup do
        sign_in users(:jason)
      end

      should "assign a friend" do
        get :new, friend_id: users(:jim).id
        assert_equal users(:jim), assigns(:friend)

      end

      should "assign a user friendship" do
        get :new, friend_id: users(:jim).id
        assert_response : success
      end
    end
  end
end

2 Answers

Rodrigo Soares
Rodrigo Soares
2,460 Points

Salut Natacha!

Here's the code that made it pass:

assert assigns(:user_friendship)

Merci Rodrigo ! It was so easy, i can't believe i missed that !