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_logout_without_referer
59 assert_redirected_to root_path
62 def test_logout_with_referer
63 post logout_path, :params => { :referer => "/test" }
64 assert_redirected_to "/test"
67 def test_logout_fallback_without_referer
69 assert_response :success
70 assert_template "sessions/destroy"
71 assert_select "input[name=referer]:not([value])"
74 def test_logout_fallback_with_referer
75 get logout_path, :params => { :referer => "/test" }
76 assert_response :success
77 assert_template "sessions/destroy"
78 assert_select "input[name=referer][value=?]", "/test"
81 def test_logout_removes_session_token
82 user = build(:user, :pending)
83 post user_new_path, :params => { :user => user.attributes }
84 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
86 assert_redirected_to root_path