Skip to content

Commit

Permalink
Make the "remember me" option work as intended
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Nov 5, 2024
1 parent e15a92a commit 035e996
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def new
end

def create
session[:remember_me] ||= params[:remember_me]
session[:remember_me] = params[:remember_me] == "yes"

referer = safe_referer(params[:referer]) if params[:referer]

Expand Down
18 changes: 18 additions & 0 deletions test/controllers/sessions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ def test_login
assert_redirected_to root_path
end

def test_login_remembered
user = create(:user)

post login_path, :params => { :username => user.display_name, :password => "test", :remember_me => "yes" }
assert_redirected_to root_path

assert_equal 28 * 86400, session[:_remember_for]
end

def test_login_not_remembered
user = create(:user)

post login_path, :params => { :username => user.display_name, :password => "test", :remember_me => "0" }
assert_redirected_to root_path

assert_nil session[:_remember_for]
end

def test_logout_without_referer
post logout_path
assert_redirected_to root_path
Expand Down

0 comments on commit 035e996

Please sign in to comment.