diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2010-04-28 16:24:47 -0300 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-04-28 23:12:03 +0200 |
commit | ce48b3103acd2f58931aa42b93073592b291114e (patch) | |
tree | 3276a234bafc808e1a8f1f9d871733b49e3b0c7a /activemodel | |
parent | b9ab4c780af82c1c60d63c50f040a55da5bfa8db (diff) | |
download | rails-ce48b3103acd2f58931aa42b93073592b291114e.tar.gz rails-ce48b3103acd2f58931aa42b93073592b291114e.tar.bz2 rails-ce48b3103acd2f58931aa42b93073592b291114e.zip |
Makes validates_acceptance_of to not override database fields [#4460 state:committed]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/validations.rb | 3 | ||||
-rw-r--r-- | activemodel/lib/active_model/validations/acceptance.rb | 6 |
2 files changed, 7 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index 708557f4ae..c69cabc888 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -133,6 +133,9 @@ module ActiveModel _validators[attribute.to_sym] end + def attribute_method?(attribute) + method_defined?(attribute) + end private def _merge_attributes(attr_names) diff --git a/activemodel/lib/active_model/validations/acceptance.rb b/activemodel/lib/active_model/validations/acceptance.rb index 0423fcd17f..fbd622eb6d 100644 --- a/activemodel/lib/active_model/validations/acceptance.rb +++ b/activemodel/lib/active_model/validations/acceptance.rb @@ -14,8 +14,10 @@ module ActiveModel def setup(klass) # Note: instance_methods.map(&:to_s) is important for 1.9 compatibility # as instance_methods returns symbols unlike 1.8 which returns strings. - new_attributes = attributes.reject { |name| klass.instance_methods.map(&:to_s).include?("#{name}=") } - klass.send(:attr_accessor, *new_attributes) + attr_readers = attributes.reject { |name| klass.attribute_method?(name) } + attr_writers = attributes.reject { |name| klass.attribute_method?("#{name}=") } + klass.send(:attr_reader, *attr_readers) + klass.send(:attr_writer, *attr_writers) end end |