diff options
author | Griffin Smith <wildgriffin45@gmail.com> | 2015-07-10 11:32:18 -0400 |
---|---|---|
committer | Griffin Smith <wildgriffin45@gmail.com> | 2016-01-09 14:49:00 -0500 |
commit | 21c0a1f3016b1de81f455f2a242803db91f96f17 (patch) | |
tree | ddd93f8de3d51333bd0ab18fb2f7181368c5500e /activerecord/test | |
parent | 9d681fc74c6251d5f2b93fa9576c9b2113116680 (diff) | |
download | rails-21c0a1f3016b1de81f455f2a242803db91f96f17.tar.gz rails-21c0a1f3016b1de81f455f2a242803db91f96f17.tar.bz2 rails-21c0a1f3016b1de81f455f2a242803db91f96f17.zip |
Support :if and :unless in has_secure_token
Pass through :if and :unless options from has_secure_token to the
generated before_create callback
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/secure_token_test.rb | 10 | ||||
-rw-r--r-- | activerecord/test/models/user.rb | 3 |
2 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/test/cases/secure_token_test.rb b/activerecord/test/cases/secure_token_test.rb index e731443fc2..ff0072d59c 100644 --- a/activerecord/test/cases/secure_token_test.rb +++ b/activerecord/test/cases/secure_token_test.rb @@ -29,4 +29,14 @@ class SecureTokenTest < ActiveRecord::TestCase assert_equal @user.token, "custom-secure-token" end + + def test_token_with_if_condition_checks_condition_on_save + @user.token_condition = false + @user.save + assert_nil @user.conditional_token + + @user.token_condition = true + @user.save + assert_not_nil @user.conditional_token + end end diff --git a/activerecord/test/models/user.rb b/activerecord/test/models/user.rb index f5dc93e994..a40385e047 100644 --- a/activerecord/test/models/user.rb +++ b/activerecord/test/models/user.rb @@ -1,6 +1,9 @@ class User < ActiveRecord::Base has_secure_token has_secure_token :auth_token + has_secure_token :conditional_token, if: :token_condition + + attr_accessor :token_condition end class UserWithNotification < User |