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
52 post login_path, :params => { :username => " #{user.display_name}", :password => "test" }
53 assert_response :redirect
54 assert_redirected_to root_path
56 post login_path, :params => { :username => "#{user.display_name} ", :password => "test" }
57 assert_response :redirect
58 assert_redirected_to root_path
61 def test_logout_without_referer
63 assert_response :redirect
64 assert_redirected_to root_path
67 def test_logout_with_referer
68 post logout_path, :params => { :referer => "/test" }
69 assert_response :redirect
70 assert_redirected_to "/test"
73 def test_logout_fallback_without_referer
75 assert_response :success
76 assert_template "sessions/destroy"
77 assert_select "input[name=referer]:not([value])"
80 def test_logout_fallback_with_referer
81 get logout_path, :params => { :referer => "/test" }
82 assert_response :success
83 assert_template "sessions/destroy"
84 assert_select "input[name=referer][value=?]", "/test"
87 def test_logout_removes_session_token
88 user = build(:user, :pending)
89 post user_new_path, :params => { :user => user.attributes }
90 post user_save_path, :params => { :read_ct => 1, :read_tou => 1 }
92 assert_difference "User.find_by(:email => user.email).tokens.count", -1 do
95 assert_response :redirect
96 assert_redirected_to root_path