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_redirected_to login_path(:cookie_test => true)
40 assert_response :success
41 assert_template "sessions/new"
43 get login_path, :params => { :username => user.display_name, :password => "test" }
44 assert_response :success
45 assert_template "sessions/new"
47 post login_path, :params => { :username => user.display_name, :password => "test" }
48 assert_redirected_to root_path
50 post login_path, :params => { :username => " #{user.display_name}", :password => "test" }
51 assert_redirected_to root_path
53 post login_path, :params => { :username => "#{user.display_name} ", :password => "test" }
54 assert_redirected_to root_path
57 def test_login_remembered
60 post login_path, :params => { :username => user.display_name, :password => "test", :remember_me => "yes" }
61 assert_redirected_to root_path
63 assert_equal 28 * 86400, session[:_remember_for]
66 def test_login_not_remembered
69 post login_path, :params => { :username => user.display_name, :password => "test", :remember_me => "0" }
70 assert_redirected_to root_path
72 assert_nil session[:_remember_for]
75 def test_logout_without_referer
77 assert_redirected_to root_path
80 def test_logout_with_referer
81 post logout_path, :params => { :referer => "/test" }
82 assert_redirected_to "/test"
85 def test_logout_fallback_without_referer
87 assert_response :success
88 assert_template "sessions/destroy"
89 assert_select "input[name=referer]:not([value])"
92 def test_logout_fallback_with_referer
93 get logout_path, :params => { :referer => "/test" }
94 assert_response :success
95 assert_template "sessions/destroy"
96 assert_select "input[name=referer][value=?]", "/test"
99 def test_logout_removes_session_token
100 user = build(:user, :pending)
101 post user_new_path, :params => { :user => user.attributes }
102 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
104 assert_redirected_to root_path