diff options
author | Gareth Rees <gareth@mysociety.org> | 2014-10-20 10:43:52 +0100 |
---|---|---|
committer | Gareth Rees <gareth@mysociety.org> | 2014-10-29 13:01:11 +0000 |
commit | 3d1f4dcbab13e08743be48c541298b4f71d93446 (patch) | |
tree | 121ef207da386a156ef3543485ea537804143ab3 | |
parent | e942acb6cf95facf4ab267bbc1da48f03b770b4a (diff) |
Extract after_initialize methods in PostRedirect
Use separate methods to explicitly state what’s happening
-rw-r--r-- | app/models/post_redirect.rb | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/app/models/post_redirect.rb b/app/models/post_redirect.rb index fbf52059b..8049349d0 100644 --- a/app/models/post_redirect.rb +++ b/app/models/post_redirect.rb @@ -31,7 +31,8 @@ class PostRedirect < ActiveRecord::Base # Optional, does a login confirm before redirect for use in email links. belongs_to :user - after_initialize :generate_token + after_initialize :generate_token, + :generate_email_token # Makes a random token, suitable for using in URLs e.g confirmation # messages. @@ -81,17 +82,15 @@ class PostRedirect < ActiveRecord::Base private + # The token is used to return you to what you are doing after the login + # form. def generate_token - # The token is used to return you to what you are doing after the login - # form. - unless token - self.token = PostRedirect.generate_random_token - end + self.token = PostRedirect.generate_random_token unless token + end - # There is a separate token to use in the URL if we send a confirmation - # email. - unless email_token - self.email_token = PostRedirect.generate_random_token - end + # There is a separate token to use in the URL if we send a confirmation + # email. + def generate_email_token + self.email_token = PostRedirect.generate_random_token unless email_token end end |