Guest User

Untitled

a guest
May 24th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. diff --git a/lib/clearance/authentication.rb b/lib/clearance/authentication.rb
  2. index b8e3c1d..750beef 100644
  3. --- a/lib/clearance/authentication.rb
  4. +++ b/lib/clearance/authentication.rb
  5. @@ -64,7 +64,7 @@ module Clearance
  6. if user
  7. cookies[:remember_token] = {
  8. :value => user.remember_token,
  9. - :expires => Clearance.configuration.cookie_expiration.call
  10. + :expires => self.instance_eval(&Clearance.configuration.cookie_expiration)
  11. }
  12. self.current_user = user
  13. end
  14. diff --git a/test/controllers/sessions_controller_test.rb b/test/controllers/sessions_controller_test.rb
  15. index 040eb7e..63a6e33 100644
  16. --- a/test/controllers/sessions_controller_test.rb
  17. +++ b/test/controllers/sessions_controller_test.rb
  18. @@ -94,6 +94,29 @@ class SessionsControllerTest < ActionController::TestCase
  19. end
  20. end
  21.  
  22. + context "on POST to #create with good credentials - cookie duration passed as parameter" do
  23. + custom_duration = 5.months.from_now.utc
  24. +
  25. + setup do
  26. + Clearance.configuration.cookie_expiration = lambda { params[:duration] }
  27. + # this lambda will work only if 'self' is the current controller and therefore has access to 'params'
  28. + @user = Factory(:email_confirmed_user)
  29. + @user.update_attribute(:remember_token, "old-token4")
  30. + post :create, :duration => custom_duration, :session => {
  31. + :email => @user.email,
  32. + :password => @user.password }
  33. + end
  34. +
  35. + should_set_cookie("remember_token", "old-token4", custom_duration)
  36. +
  37. + teardown do
  38. + # restore default Clearance configuration
  39. + Clearance.configuration = nil
  40. + Clearance.configure {}
  41. + end
  42. + end
  43. +
  44. +
  45. context "on POST to #create with good credentials and a session return url" do
  46. setup do
  47. @user = Factory(:email_confirmed_user)
Add Comment
Please, Sign In to add comment