3 class SessionsControllerTest < ActionDispatch::IntegrationTest
5 # test all routes which lead to this controller
8 { :path => "/login", :method => :get },
9 { :controller => "sessions", :action => "new" }
12 { :path => "/login", :method => :post },
13 { :controller => "sessions", :action => "create" }
16 { :controller => "sessions", :action => "new", :format => "html" },
17 { :path => "/login.html", :method => :get }
21 { :path => "/logout", :method => :get },
22 { :controller => "sessions", :action => "destroy" }
25 { :path => "/logout", :method => :post },
26 { :controller => "sessions", :action => "destroy" }
29 { :controller => "sessions", :action => "destroy", :format => "html" },
30 { :path => "/logout.html", :method => :get }
38 assert_response :redirect
39 assert_redirected_to login_path(:cookie_test => true)
41 assert_response :success
42 assert_template "sessions/new"
44 get login_path, :params => { :username => user.display_name, :password => "test" }
45 assert_response :success
46 assert_template "sessions/new"
48 post login_path, :params => { :username => user.display_name, :password => "test" }
49 assert_response :redirect
50 assert_redirected_to root_path
53 def test_logout_without_referer
55 assert_response :redirect
56 assert_redirected_to root_path
59 def test_logout_with_referer
60 post logout_path, :params => { :referer => "/test" }
61 assert_response :redirect
62 assert_redirected_to "/test"
65 def test_logout_fallback_without_referer
67 assert_response :success
68 assert_template "sessions/destroy"
69 assert_select "input[name=referer]:not([value])"
72 def test_logout_fallback_with_referer
73 get logout_path, :params => { :referer => "/test" }
74 assert_response :success
75 assert_template "sessions/destroy"
76 assert_select "input[name=referer][value=?]", "/test"
79 def test_logout_removes_session_token
80 user = build(:user, :pending)
81 post user_new_path, :params => { :user => user.attributes }
82 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
84 assert_difference "User.find_by(:email => user.email).tokens.count", -1 do
87 assert_response :redirect
88 assert_redirected_to root_path