Rename UninferrableSourceError to UninferrableObjectError (#768)
Since source has been renamed to object, it is better for consistency to have UninferrableObjectError class name with the error message mentioning 'object' property instead of 'source'.
This commit is contained in:
parent
9b6106fed0
commit
8cb7c1a930
|
@ -55,9 +55,11 @@ module Draper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class UninferrableSourceError < NameError
|
class UninferrableObjectError < NameError
|
||||||
def initialize(klass)
|
def initialize(klass)
|
||||||
super("Could not infer a source for #{klass}.")
|
super("Could not infer an object for #{klass}.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
UninferrableSourceError = UninferrableObjectError # TODO: deprecate this
|
||||||
end
|
end
|
||||||
|
|
|
@ -72,7 +72,7 @@ module Draper
|
||||||
# Checks whether this decorator class has a corresponding {object_class}.
|
# Checks whether this decorator class has a corresponding {object_class}.
|
||||||
def self.object_class?
|
def self.object_class?
|
||||||
object_class
|
object_class
|
||||||
rescue Draper::UninferrableSourceError
|
rescue Draper::UninferrableObjectError
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -256,7 +256,7 @@ module Draper
|
||||||
name.constantize
|
name.constantize
|
||||||
rescue NameError => error
|
rescue NameError => error
|
||||||
raise if name && !error.missing_name?(name)
|
raise if name && !error.missing_name?(name)
|
||||||
raise Draper::UninferrableSourceError.new(self)
|
raise Draper::UninferrableObjectError.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.collection_decorator_name
|
def self.collection_decorator_name
|
||||||
|
|
|
@ -181,21 +181,25 @@ module Draper
|
||||||
protect_class Namespaced::ProductDecorator
|
protect_class Namespaced::ProductDecorator
|
||||||
|
|
||||||
context "when not set by .decorates" do
|
context "when not set by .decorates" do
|
||||||
it "raises an UninferrableSourceError for a so-named 'Decorator'" do
|
it "raises an UninferrableObjectError for a so-named 'Decorator'" do
|
||||||
|
expect{Decorator.object_class}.to raise_error UninferrableObjectError
|
||||||
|
end
|
||||||
|
|
||||||
|
it "supports UninferrableSourceError alias for a backward compatibility" do
|
||||||
expect{Decorator.object_class}.to raise_error UninferrableSourceError
|
expect{Decorator.object_class}.to raise_error UninferrableSourceError
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an UninferrableSourceError for anonymous decorators" do
|
it "raises an UninferrableObjectError for anonymous decorators" do
|
||||||
expect{Class.new(Decorator).object_class}.to raise_error UninferrableSourceError
|
expect{Class.new(Decorator).object_class}.to raise_error UninferrableObjectError
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an UninferrableSourceError for a decorator without a model" do
|
it "raises an UninferrableObjectError for a decorator without a model" do
|
||||||
skip
|
skip
|
||||||
expect{OtherDecorator.object_class}.to raise_error UninferrableSourceError
|
expect{OtherDecorator.object_class}.to raise_error UninferrableObjectError
|
||||||
end
|
end
|
||||||
|
|
||||||
it "raises an UninferrableSourceError for other naming conventions" do
|
it "raises an UninferrableObjectError for other naming conventions" do
|
||||||
expect{ProductPresenter.object_class}.to raise_error UninferrableSourceError
|
expect{ProductPresenter.object_class}.to raise_error UninferrableObjectError
|
||||||
end
|
end
|
||||||
|
|
||||||
it "infers the source for '<Model>Decorator'" do
|
it "infers the source for '<Model>Decorator'" do
|
||||||
|
@ -227,7 +231,7 @@ module Draper
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false when .object_class is not inferrable" do
|
it "returns false when .object_class is not inferrable" do
|
||||||
allow(Decorator).to receive(:object_class).and_raise(UninferrableSourceError.new(Decorator))
|
allow(Decorator).to receive(:object_class).and_raise(UninferrableObjectError.new(Decorator))
|
||||||
|
|
||||||
expect(Decorator.object_class?).to be_falsey
|
expect(Decorator.object_class?).to be_falsey
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue