unit testing - Why isn't my delete_via_redirect test working in Rails? -


i can't logout test work, yet works in browser. cannot see wrong.

  test "logout user"     chloe = login(:starrychloe, 'passpasspass')     chloe.delete_via_redirect "/users/logout"     chloe.assert_equal '/', chloe.path     chloe.assert_equal "logged out!", chloe.flash.notice, chloe.flash.to_a     chloe.assert_select '.button' |elem|       puts elem     end     chloe.assert_select '.button', 'login' 

here error. still thinks logged in, though session destroyed , user_id no longer in session:

started delete "/users/logout" 127.0.0.1 @ 2014-05-31 23:28:17 -0400 processing userscontroller#logout html ******************** {"session_id"=>"174289eb62bf8679db7f7b04e28c0822", "invalidlogin"=>0, "user_id"=>1, "flash"=>{"discard"=>["notice"], "flashes"=>{"notice"=>"logged in! last seen 172.196.66.44."}}, "_csrf_token"=>"ikyw4ljvzu/1jrw7p6nnzho2epms3udde4eh/y5brjm="} ******************** {"session_id"=>"7dbc9379256566a5bb642c91a9301501"} redirected http://www.example.com:443/ completed 302 found in 2ms (activerecord: 0.0ms) started "/" 127.0.0.1 @ 2014-05-31 23:28:17 -0400 completed 200 ok in 8ms (views: 6.8ms | activerecord: 0.0ms) <div class="button"><a href="/">all</a></div> <div class="button"><a data-method="delete" href="/users/logout" rel="nofollow">logout</a></div> f    1) failure: userflowstest#test_logout_user [test/integration/user_flows_test.rb:43]: <login> expected <all>.. expected 0 >= 1.  1 runs, 0 assertions, 1 failures, 0 errors, 0 skips 

here controller method

  def logout puts "******************** #{session.to_hash}"         reset_session puts "******************** #{session.to_hash}"         redirect_to root_url, :notice => "logged out!" 

i changed method: :post method: :delete. tried redirect_to :root didn't help.

ok found bug in rails. added puts chloe.response.body , saw printing correct non-logged in page, reason, assert_select still using page before! fixed problem creating new html::document element response.body , selecting on text directly.

puts chloe.response.body doc = html::document.new chloe.response.body chloe.assert_select doc.root, '.button' |elem|   puts elem end chloe.assert_select doc.root, '.button', 'login' 

now correctly lists links new user see

<div class="button"><a href="/">all</a></div> <div class="button"><a data-no-turbolink="true" href="/users/login">login</a></div> <div class="button"><a data-no-turbolink="true" href="/users/new">register</a></div> 

here issue: https://github.com/rails/rails/issues/15454


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -