aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/validations.rb2
-rw-r--r--activemodel/test/cases/validations/presence_validation_test.rb26
2 files changed, 17 insertions, 11 deletions
diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb
index 7f6748a660..ba8648f8c9 100644
--- a/activemodel/lib/active_model/validations.rb
+++ b/activemodel/lib/active_model/validations.rb
@@ -137,7 +137,7 @@ module ActiveModel
def _merge_attributes(attr_names)
options = attr_names.extract_options!
- options.merge(:attributes => attr_names)
+ options.merge(:attributes => attr_names.flatten)
end
end
diff --git a/activemodel/test/cases/validations/presence_validation_test.rb b/activemodel/test/cases/validations/presence_validation_test.rb
index 8b9795a90c..c4d787dadb 100644
--- a/activemodel/test/cases/validations/presence_validation_test.rb
+++ b/activemodel/test/cases/validations/presence_validation_test.rb
@@ -10,6 +10,12 @@ require 'models/custom_reader'
class PresenceValidationTest < ActiveModel::TestCase
include ActiveModel::TestsDatabase
+ teardown do
+ Topic.reset_callbacks(:validate)
+ Person.reset_callbacks(:validate)
+ CustomReader.reset_callbacks(:validate)
+ end
+
def test_validate_presences
Topic.validates_presence_of(:title, :content)
@@ -27,17 +33,21 @@ class PresenceValidationTest < ActiveModel::TestCase
t.content = "like stuff"
assert t.save
- ensure
- Topic.reset_callbacks(:validate)
+ end
+
+ test 'accepts array arguments' do
+ Topic.validates_presence_of %w(title content)
+ t = Topic.new
+ assert !t.valid?
+ assert_equal ["can't be blank"], t.errors[:title]
+ assert_equal ["can't be blank"], t.errors[:content]
end
def test_validates_acceptance_of_with_custom_error_using_quotes
- Person.validates_presence_of :karma, :message=> "This string contains 'single' and \"double\" quotes"
+ Person.validates_presence_of :karma, :message => "This string contains 'single' and \"double\" quotes"
p = Person.new
assert !p.valid?
assert_equal "This string contains 'single' and \"double\" quotes", p.errors[:karma].last
- ensure
- Person.reset_callbacks(:validate)
end
def test_validates_presence_of_for_ruby_class
@@ -50,10 +60,8 @@ class PresenceValidationTest < ActiveModel::TestCase
p.karma = "Cold"
assert p.valid?
- ensure
- Person.reset_callbacks(:validate)
end
-
+
def test_validates_presence_of_for_ruby_class_with_custom_reader
CustomReader.validates_presence_of :karma
@@ -64,7 +72,5 @@ class PresenceValidationTest < ActiveModel::TestCase
p[:karma] = "Cold"
assert p.valid?
- ensure
- CustomReader.reset_callbacks(:validate)
end
end