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 Before Filters

Edward Poon
Edward Poon
9,313 Points

Question about the test

So we wrote some tests for should "should_get_new" and i was wondering why doesn't the test run for when we are logged in?

Does it have something to do with the before_filter? If so, does the before_filter :authenticate_user!, only [:new] just automatically make the test pass for new if the user is authenticated?

Thanks

1 Answer

Brandon Barrette
Brandon Barrette
20,485 Points

So the before filter is going to check the method you provide before it gets to the new method.

before_filter :authenticate_user!, only [:new]

So here, it checks to see that the user is logged in, but only for the new method. It is basically checking to see if the current_user is set (which gets assigned by Devise when you log in).

If you did the same thing with the index method, you wouldn't require a user to be logged in to view that page here. If you remove the only [:new], then you would require a user for ALL methods in that controller.