aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2014-07-02 14:39:41 -0700
committerGodfrey Chan <godfreykfc@gmail.com>2014-07-02 15:07:57 -0700
commit9eb15ed6a08f76ef683bb10a84f824b9dc379e3a (patch)
tree4a1fd93686918c86744cfa6feca63340a8046152 /activemodel
parent6ee17968db8f8a078e843cb97eb5ab62e3d021d5 (diff)
downloadrails-9eb15ed6a08f76ef683bb10a84f824b9dc379e3a.tar.gz
rails-9eb15ed6a08f76ef683bb10a84f824b9dc379e3a.tar.bz2
rails-9eb15ed6a08f76ef683bb10a84f824b9dc379e3a.zip
Only automatically include validations when enabled
This is a follow up to #16024.
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/secure_password.rb3
-rw-r--r--activemodel/test/cases/secure_password_test.rb14
2 files changed, 5 insertions, 12 deletions
diff --git a/activemodel/lib/active_model/secure_password.rb b/activemodel/lib/active_model/secure_password.rb
index 88e578e626..7e179cf4b7 100644
--- a/activemodel/lib/active_model/secure_password.rb
+++ b/activemodel/lib/active_model/secure_password.rb
@@ -1,7 +1,6 @@
module ActiveModel
module SecurePassword
extend ActiveSupport::Concern
- include ActiveModel::Validations
# BCrypt hash function can handle maximum 72 characters, and if we pass
# password of length more than 72 characters it ignores extra characters.
@@ -65,6 +64,8 @@ module ActiveModel
include InstanceMethodsOnActivation
if options.fetch(:validations, true)
+ include ActiveModel::Validations
+
# This ensures the model has a password by checking whether the password_digest
# is present, so that this works with both new and existing records. However,
# when there is an error, the message is added to the password attribute instead
diff --git a/activemodel/test/cases/secure_password_test.rb b/activemodel/test/cases/secure_password_test.rb
index 9e68cceb5f..6b21bc68fa 100644
--- a/activemodel/test/cases/secure_password_test.rb
+++ b/activemodel/test/cases/secure_password_test.rb
@@ -20,20 +20,12 @@ class SecurePasswordTest < ActiveModel::TestCase
ActiveModel::SecurePassword.min_cost = @original_min_cost
end
- test "user object should respond to valid?" do
- assert_respond_to @visitor, :valid?
+ test "automatically include ActiveModel::Validations when validations are enabled" do
assert_respond_to @user, :valid?
end
- test "create/update without validations" do
- assert @visitor.valid?(:create), 'visitor should be valid'
- assert @visitor.valid?(:update), 'visitor should be valid'
-
- @visitor.password = '123'
- @visitor.password_confirmation = '456'
-
- assert @visitor.valid?(:create), 'visitor should be valid'
- assert @visitor.valid?(:update), 'visitor should be valid'
+ test "don't include ActiveModel::Validations when validations are disabled" do
+ assert_not_respond_to @visitor, :valid?
end
test "create a new user with validations and valid password/confirmation" do