Permalink
Browse files

Prevent infinit method_missing loop on attribute methods

If a klass has acceptance validation and then
`klass.undefine_attribute_methods` is happened before an attribute
method is called, infinit loop is caused on the `method_missing` defined
by the `LazilyDefineAttributes`.

https://travis-ci.org/rails/rails/jobs/467053984#L1409

To prevent the infinit loop, the `method_missing` should ensure
`klass.define_attribute_methods`.
  • Loading branch information...
kamipo committed Dec 15, 2018
1 parent d57841b commit ce48b5a366482d4b4c4c053e1e39e79d71987197
Showing with 1 addition and 0 deletions.
  1. +1 −0 activemodel/lib/active_model/validations/acceptance.rb
@@ -54,6 +54,7 @@ def matches?(method_name)
def define_on(klass)
attr_readers = attributes.reject { |name| klass.attribute_method?(name) }
attr_writers = attributes.reject { |name| klass.attribute_method?("#{name}=") }
klass.define_attribute_methods
klass.send(:attr_reader, *attr_readers)
klass.send(:attr_writer, *attr_writers)
end

0 comments on commit ce48b5a

Please sign in to comment.