aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/secure_token_test.rb14
-rw-r--r--activerecord/test/models/user.rb3
-rw-r--r--activerecord/test/schema/schema.rb1
3 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/secure_token_test.rb b/activerecord/test/cases/secure_token_test.rb
index e731443fc2..239b975d82 100644
--- a/activerecord/test/cases/secure_token_test.rb
+++ b/activerecord/test/cases/secure_token_test.rb
@@ -29,4 +29,18 @@ class SecureTokenTest < ActiveRecord::TestCase
assert_equal @user.token, "custom-secure-token"
end
+
+ def test_failing_if_condition_does_not_set_token
+ @user.token_condition = false
+ @user.save
+
+ assert_nil @user.conditional_token
+ end
+
+ def test_passing_if_condition_sets_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
diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb
index 025184f63a..4a74137c00 100644
--- a/activerecord/test/schema/schema.rb
+++ b/activerecord/test/schema/schema.rb
@@ -1007,6 +1007,7 @@ ActiveRecord::Schema.define do
create_table :users, force: true do |t|
t.string :token
t.string :auth_token
+ t.string :conditional_token
end
create_table :test_with_keyword_column_name, force: true do |t|