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

jadaml
jadaml
11,593 Points

Requiring Login - Testing Failure - Build Simple Rails App

I get the following error to the recently added test_should_be_redirected_when_not_logged_in(StatusesControllerTest) [test/functional/statuses_controller_test.rb:16]:

Expected response to be a <:redirect>, but was <200>

Can anyone explain to me why I'm getting this.

4 Answers

Nick Pettit
STAFF
Nick Pettit
Treehouse Teacher

Hi Jadam L,

I'm not sure why you're getting this error, but Jason Seifer should be able to answer your question. He's speaking at a web conference this week, but he should be able to get back to you soon! Sorry for the delay, but Jason will have the best answer. :)

Nick

Yonatan Schultz
Yonatan Schultz
12,045 Points

Looks like your Statuses controller is not checking to see if the user is logged in prior to rendering the Status.new

Check out statuses_controller.rb and make sure that your before_filter is filtering for :new as below:

before_filter :authenticate_user!, only [:new, :create, :edit, :update]

I hope that helps!

Itay Banner
Itay Banner
1,922 Points

I'm getting something quite similar. The test is written exactly like it's written in the video itself:

test "should be logged in to post a status" do
  sign_in users(:itay)
  post :create, status: { content: "Hello. This is a test status" }
  assert_response :redirect
  assert_redirected_to new_user_session_path # <=This is the failure line
end

But somehow it fails:

Expected response to be ab redirect to <http://test.host/users/sign_in> but was a redirect to <http://test.host/statuses/980190963>

And my before_filter is updated just like Yonatan here said. And the wierdest thing is, when I take the server up and go to the app itself, I am redirected to /users/sign_in when I try to post a new message

Any ideas?

Itay Banner
Itay Banner
1,922 Points

I'm such a moron. Of course the test failed, because I forgot to remove the "sign in users(:user)" line. Can't remember now how it got there.

Removed it and all's fine now.

Jadam L , maybe you've got the same symptoms? :-)