mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Accept array of attributes as arg also, like 2.3
This commit is contained in:
parent
763f32ab47
commit
2ba6049506
2 changed files with 17 additions and 11 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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,8 +33,14 @@ 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
|
||||
|
@ -36,8 +48,6 @@ class PresenceValidationTest < ActiveModel::TestCase
|
|||
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,8 +60,6 @@ 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
|
||||
|
@ -64,7 +72,5 @@ class PresenceValidationTest < ActiveModel::TestCase
|
|||
|
||||
p[:karma] = "Cold"
|
||||
assert p.valid?
|
||||
ensure
|
||||
CustomReader.reset_callbacks(:validate)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue