Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
require 'test_helper' | ||
|
||
class SessionsControllerTest < ActionController::TestCase | ||
|
||
tests Clearance::SessionsController | ||
|
||
should_filter_params :password | ||
|
@@ -46,11 +45,55 @@ class SessionsControllerTest < ActionController::TestCase | |
|
||
should_set_cookie("remember_token", "old-token", Clearance.configuration.cookie_expiration.call) | ||
|
||
should "have a default of 1 year from now" do | ||
assert_in_delta Clearance.configuration.cookie_expiration.call, 1.year.from_now, 100 | ||
end | ||
|
||
should "not change the remember token" do | ||
assert_equal "old-token", @user.reload.remember_token | ||
end | ||
end | ||
|
||
context "on POST to #create with good credentials - cookie duration set to 2 weeks" do | ||
custom_duration = 2.weeks.from_now.utc | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rnewman57
|
||
|
||
setup do | ||
Clearance.configuration.cookie_expiration = lambda { custom_duration } | ||
@user = Factory(:email_confirmed_user) | ||
@user.update_attribute(:remember_token, "old-token2") | ||
post :create, :session => { | ||
:email => @user.email, | ||
:password => @user.password } | ||
end | ||
|
||
should_set_cookie("remember_token", "old-token2", custom_duration) | ||
|
||
teardown do | ||
# restore default Clearance configuration | ||
Clearance.configuration = nil | ||
Clearance.configure {} | ||
end | ||
end | ||
|
||
context "on POST to #create with good credentials - cookie expiration set to nil (session cookie)" do | ||
setup do | ||
Clearance.configuration.cookie_expiration = lambda { nil } | ||
@user = Factory(:email_confirmed_user) | ||
@user.update_attribute(:remember_token, "old-token3") | ||
post :create, :session => { | ||
:email => @user.email, | ||
:password => @user.password } | ||
end | ||
|
||
should_set_cookie("remember_token", "old-token3", nil) | ||
|
||
teardown do | ||
# restore default Clearance configuration | ||
Clearance.configuration = nil | ||
Clearance.configure {} | ||
end | ||
end | ||
|
||
context "on POST to #create with good credentials and a session return url" do | ||
setup do | ||
@user = Factory(:email_confirmed_user) | ||
|
2 comments
on commit 49efd7c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concerning lines 57 - 95
Sorry, I actually meant the tests where custom_duration is set to two different values, 2 weeks and nil.
Reason for two different tests is because nil is a special case, i.e. a session cookie. However, I think these two tests are testing if the remember_token gets assigned the value nil or the custom_duration. And the essence really is if the value gets assigned or not. I am just trying to clarify just for my personal knowledge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, three separate things are being tested here:
- the unconfigured default behavior (which should be a 1 year expiration)
- an explicitly configured (non-nil) expiration time
- an explicitly configured nil expiration time (session cookie)
All three tests are important.
These two tests are doing the same thing aren't they. The basically test that the value that is supplied via the cookie_expiration gets assigned or the reason to have two tests is because they could lead to fence post errors? Please enlighten.