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 Build a Simple Ruby on Rails Application Testing the Whole App Requiring Login

Nathaniel Lough
Nathaniel Lough
9,215 Points

Signing In a User without password

Jason,

When you have use write this test:

test "should render the new page when logged in" do

    sign_in users(:Nathan)

    get :new

    assert_response :success

end

I would think that this wouldn't work...

I think this because the Jason fixture has 4 attributes. But none of these attributes are a password. Is this because the sign_in helper method does not require a password? Or is something else at play.

Second, I'm still confused about why you had us write

   user: Jason

in the statuses.yml file for one: and two:. Can you elaborate?

Thanks

3 Answers

Brandon Barrette
Brandon Barrette
20,485 Points

To answer your second question first.. By defining user: Jason you are saying that the status is being assigned to the user: Jason. Remember that status belongs_to :user.

For your first question, if I recall correctly there is a users.yml file where user: Jason is defined. I don't have these tests anymore, but my guess is that the attributes are assigned there. You should see first_name, last_name, profile_name, password, etc. By using the users.yml file, you make it easy to quickly sign_in a user.

Hope that helps!

Nathaniel Lough
Nathaniel Lough
9,215 Points

Oh yeah I totally get why the users.yml file has some entries. But these entries ( from the video ) do not include password attributes. Which is why I'm confused about how these users can be "signed in" with the sign_in method.

Your first answer makes perfect sense. Thank you

Brandon Barrette
Brandon Barrette
20,485 Points

So the sign_in is just telling the test that the user is signed in. It's not actually signing in the user like you would by filling out the sign in form. See here:

https://github.com/plataformatec/devise

and scroll down to the test. Sign_in is give by devise. My understanding of this is not entirely clear because I'm now using rspec and capybara for testing (which is what Jason uses in the ODOT application).