Permalink
Browse files

Makes validates_acceptance_of to not override database fields [#4460

…state:committed]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent b9ab4c7 commit ce48b3103acd2f58931aa42b93073592b291114e @spastorino spastorino committed with josevalim Apr 28, 2010
@@ -133,6 +133,9 @@ def validators_on(attribute)
_validators[attribute.to_sym]
end
+ def attribute_method?(attribute)
+ method_defined?(attribute)
+ end
private
def _merge_attributes(attr_names)
@@ -14,8 +14,10 @@ def validate_each(record, attribute, value)
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
@@ -931,6 +931,10 @@ def reset_column_information_and_inheritable_attributes_for_all_subclasses#:nodo
subclasses.each { |klass| klass.reset_inheritable_attributes; klass.reset_column_information }
end
+ def attribute_method?(attribute)
+ super || column_names.include?(attribute.to_s.sub(/=$/, ''))
+ end
+
# Set the lookup ancestors for ActiveModel.
def lookup_ancestors #:nodoc:
klass = self

0 comments on commit ce48b31

Please sign in to comment.