Permalink
Browse files

fix remembering of attributes defined as an array

In rails it's also possible to write:

  validates_presence_of [ :foo, :bar ]

However we have to flatten this argument array before
we try to remember them.
  • Loading branch information...
1 parent a2bcc8c commit cd8bd618ea8d902b1045d4cc12438176039732ff @duritong duritong committed Nov 25, 2009
Showing with 4 additions and 1 deletion.
  1. +1 −1 lib/validation_reflection.rb
  2. +3 −0 test/validation_reflection_test.rb
@@ -121,7 +121,7 @@ def reflect_on_validations_for(attr_name)
#
def remember_validation_metadata(validation_type, *attr_names)
configuration = attr_names.last.is_a?(::Hash) ? attr_names.pop : {}
- attr_names.each do |attr_name|
+ attr_names.flatten.each do |attr_name|
self.write_inheritable_array :validations,
[::ActiveRecord::Reflection::MacroReflection.new(validation_type, attr_name.to_sym, configuration, self)]
end
@@ -42,6 +42,8 @@ def columns
[
create_fake_column('col0'),
create_fake_column('col1'),
+ create_fake_column('col1a'),
+ create_fake_column('col1b'),
create_fake_column('col2', false, 100),
create_fake_column('col3'),
create_fake_column('col4'),
@@ -55,6 +57,7 @@ def columns
has_one :nothing
validates_presence_of :col1
+ validates_presence_of [ :col1a, :col1b ]
validates_length_of :col2, :maximum => 100
validates_format_of :col3, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
validates_numericality_of :col4, :only_integer => true

0 comments on commit cd8bd61

Please sign in to comment.