Fix wrong UninferrableDecoratorError error raising
This commit is contained in:
parent
45e18569d9
commit
de2ae4a7d3
|
@ -74,10 +74,10 @@ module Draper
|
|||
decorator_name = "#{prefix}Decorator"
|
||||
decorator_name.constantize
|
||||
rescue NameError => error
|
||||
raise unless error.missing_name?(decorator_name)
|
||||
if superclass.respond_to?(:decorator_class)
|
||||
superclass.decorator_class
|
||||
else
|
||||
raise unless error.missing_name?(decorator_name)
|
||||
raise Draper::UninferrableDecoratorError.new(self)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -182,6 +182,15 @@ module Draper
|
|||
end
|
||||
end
|
||||
|
||||
context "when the decorator contains name error" do
|
||||
it "throws an NameError" do
|
||||
# We imitate ActiveSupport::Autoload behavior here in order to cause lazy NameError exception raising
|
||||
allow_any_instance_of(Module).to receive(:const_missing) { Class.new { any_nonexisting_method_name } }
|
||||
|
||||
expect{Model.decorator_class}.to raise_error { |error| expect(error).to be_an_instance_of(NameError) }
|
||||
end
|
||||
end
|
||||
|
||||
context "when the decorator can't be inferred" do
|
||||
it "throws an UninferrableDecoratorError" do
|
||||
expect{Model.decorator_class}.to raise_error UninferrableDecoratorError
|
||||
|
|
Loading…
Reference in New Issue