开发者

How to do integration testing in Rails 3?

开发者 https://www.devze.com 2023-04-10 08:54 出处:网络
I tried using the code in the RailsGuides and some other code I found on Google, but nothing is working.

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 integ开发者_JAVA技巧ration 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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消