B Seven
B Seven

Reputation: 45943

How to do integration testing in Rails 3?

I tried using the code in the RailsGuides and some other code I found on Google, but nothing is working.

How do you do a simple integration test in Rails 3 using Test::Unit? How do you make the session persist across http requests?

The following code fails because Expected response to be a <:success>, but was <302>. I think it is because the session is lost after the post request.

class UserFlowsTest < ActionDispatch::IntegrationTest
  fixtures :all

  test "client can get client dashboard" do
    post '/login', :login=> users(:client).login, :password => 'thepassword' 
    get '/dash'    
    assert_response :success    
  end

end

Working in Rails 3.07.

Thanks.

Upvotes: 1

Views: 670

Answers (1)

B Seven
B Seven

Reputation: 45943

It turns out the above code is correct.

I had changed part of the user validation code, causing a redirect to the login form when I did not intend. That's why the response was 302 (redirect).

Upvotes: 1

Related Questions