提交 cc69a14e 编写于 作者: R Ryuta Kamizono

Fix multi-threaded issue for `AcceptanceValidator`

上级 0f65f150
......@@ -31,6 +31,7 @@ def initialize(attributes)
end
def included(klass)
@lock = Mutex.new
mod = self
define_method(:respond_to_missing?) do |method_name, include_private = false|
......@@ -54,14 +55,20 @@ def matches?(method_name)
end
def define_on(klass)
remove_method :respond_to_missing?
remove_method :method_missing
@lock&.synchronize do
return unless @lock
attr_readers = attributes.reject { |name| klass.attribute_method?(name) }
attr_writers = attributes.reject { |name| klass.attribute_method?("#{name}=") }
attr_readers = attributes.reject { |name| klass.attribute_method?(name) }
attr_writers = attributes.reject { |name| klass.attribute_method?("#{name}=") }
attr_reader(*attr_readers)
attr_writer(*attr_writers)
attr_reader(*attr_readers)
attr_writer(*attr_writers)
remove_method :respond_to_missing?
remove_method :method_missing
@lock = nil
end
end
def ==(other)
......
......@@ -122,7 +122,13 @@ def test_lazy_attributes_respond_to?
klass = define_test_class(Topic)
klass.validates_acceptance_of(:terms_of_service)
topic = klass.new
assert topic.respond_to?(:terms_of_service)
threads = []
2.times do
threads << Thread.new do
assert topic.respond_to?(:terms_of_service)
end
end
threads.each(&:join)
end
private
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册