aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2012-01-17 03:01:54 -0800
committerJosé Valim <jose.valim@gmail.com>2012-01-17 03:01:54 -0800
commit4280b20cde6d0ec4694f25288832d098c83cceba (patch)
tree981f57e28a2c14b3eee85d0e6c0e9c2822652ec1
parent5f8274efe128ffeec8fa3179460f5167a078f007 (diff)
parent7c3a5ec49942928ecef1007b21a1cbc3d89ebbf2 (diff)
downloadrails-4280b20cde6d0ec4694f25288832d098c83cceba.tar.gz
rails-4280b20cde6d0ec4694f25288832d098c83cceba.tar.bz2
rails-4280b20cde6d0ec4694f25288832d098c83cceba.zip
Merge pull request #4494 from Dreamfa11/patch-0
Validates method should not change options argument
-rw-r--r--activemodel/lib/active_model/validations/validates.rb8
-rw-r--r--activemodel/test/cases/validations_test.rb6
2 files changed, 10 insertions, 4 deletions
diff --git a/activemodel/lib/active_model/validations/validates.rb b/activemodel/lib/active_model/validations/validates.rb
index 8e09f6ac35..3713fc828e 100644
--- a/activemodel/lib/active_model/validations/validates.rb
+++ b/activemodel/lib/active_model/validations/validates.rb
@@ -59,7 +59,7 @@ module ActiveModel
#
# validates :name, :'film/title' => true
#
- # The validators hash can also handle regular expressions, ranges,
+ # The validators hash can also handle regular expressions, ranges,
# arrays and strings in shortcut form, e.g.
#
# validates :email, :format => /@/
@@ -70,7 +70,7 @@ module ActiveModel
# validator's initializer as +options[:in]+ while other types including
# regular expressions and strings are passed as +options[:with]+
#
- # Finally, the options +:if+, +:unless+, +:on+, +:allow_blank+, +:allow_nil+ and +:strict+
+ # Finally, the options +:if+, +:unless+, +:on+, +:allow_blank+, +:allow_nil+ and +:strict+
# can be given to one specific validator, as a hash:
#
# validates :password, :presence => { :if => :password_required? }, :confirmation => true
@@ -80,7 +80,7 @@ module ActiveModel
# validates :password, :presence => true, :confirmation => true, :if => :password_required?
#
def validates(*attributes)
- defaults = attributes.extract_options!
+ defaults = attributes.extract_options!.dup
validations = defaults.slice!(*_validates_default_keys)
raise ArgumentError, "You need to supply at least one attribute" if attributes.empty?
@@ -102,7 +102,7 @@ module ActiveModel
end
# This method is used to define validation that can not be corrected by end user
- # and is considered exceptional.
+ # and is considered exceptional.
# So each validator defined with bang or <tt>:strict</tt> option set to <tt>true</tt>
# will always raise <tt>ActiveModel::InternalValidationFailed</tt> instead of adding error
# when validation fails
diff --git a/activemodel/test/cases/validations_test.rb b/activemodel/test/cases/validations_test.rb
index 2f4376bd41..ed4d8fcdca 100644
--- a/activemodel/test/cases/validations_test.rb
+++ b/activemodel/test/cases/validations_test.rb
@@ -330,4 +330,10 @@ class ValidationsTest < ActiveModel::TestCase
Topic.new.valid?
end
end
+
+ def test_does_not_modify_options_argument
+ options = {:presence => true}
+ Topic.validates :title, options
+ assert_equal({:presence => true}, options)
+ end
end