diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2016-01-09 23:28:34 +0100 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2016-01-09 23:28:34 +0100 |
commit | 2c1ac375c02eddd05616c4cd80b58c9167a02ee3 (patch) | |
tree | 8e548715e2464ec3350bc52f79f2f89e7245072d /activerecord/lib | |
parent | a3ab6ad00872d24d4d87637f93fdae798d0edc79 (diff) | |
download | rails-2c1ac375c02eddd05616c4cd80b58c9167a02ee3.tar.gz rails-2c1ac375c02eddd05616c4cd80b58c9167a02ee3.tar.bz2 rails-2c1ac375c02eddd05616c4cd80b58c9167a02ee3.zip |
Revert "Switch `has_secure_token` to `before_save`."
Mistakenly interpreted the test case as a sign that we should switch to
before_save, when the original pitch use case was intended as before_create.
Revert a3ab6ad00872d24d4d87637f93fdae798d0edc79.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/secure_token.rb | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/secure_token.rb b/activerecord/lib/active_record/secure_token.rb index 80a5018f22..f10f7a1515 100644 --- a/activerecord/lib/active_record/secure_token.rb +++ b/activerecord/lib/active_record/secure_token.rb @@ -41,14 +41,13 @@ module ActiveRecord # Note that it's still possible to generate a race condition in the database in the same way that # {validates_uniqueness_of}[rdoc-ref:Validations::ClassMethods#validates_uniqueness_of] can. # You're encouraged to add a unique index in the database to deal with this even more unlikely scenario. - def has_secure_token(attribute = :token, **before_save_options) + def has_secure_token(attribute = :token, **before_create_options) # Load securerandom only when has_secure_token is used. require 'active_support/core_ext/securerandom' define_method("regenerate_#{attribute}") { update! attribute => self.class.generate_unique_secure_token } - - before_save(before_save_options) do - send("#{attribute}=", self.class.generate_unique_secure_token) unless send("#{attribute}?") + before_create(before_create_options) do + self.send("#{attribute}=", self.class.generate_unique_secure_token) unless self.send("#{attribute}?") end end |