commit
970f3a3b67
|
@ -21,6 +21,10 @@ module Draper::Decoratable
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ===(other)
|
||||||
|
super || (other.respond_to?(:source) && super(other.source))
|
||||||
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
def decorate(options = {})
|
def decorate(options = {})
|
||||||
decorator_class.decorate_collection(self.scoped, options)
|
decorator_class.decorate_collection(self.scoped, options)
|
||||||
|
@ -32,5 +36,9 @@ module Draper::Decoratable
|
||||||
rescue NameError
|
rescue NameError
|
||||||
raise Draper::UninferrableDecoratorError.new(self)
|
raise Draper::UninferrableDecoratorError.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ===(other)
|
||||||
|
super || (other.respond_to?(:source) && super(other.source))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -45,6 +45,75 @@ describe Draper::Decoratable do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#===" do
|
||||||
|
context "with itself" do
|
||||||
|
it "returns true" do
|
||||||
|
(subject === subject).should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with another instance" do
|
||||||
|
it "returns false" do
|
||||||
|
(subject === Product.new).should be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a decorated version of itself" do
|
||||||
|
it "returns true" do
|
||||||
|
decorator = double(source: subject)
|
||||||
|
(subject === decorator).should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a decorated other instance" do
|
||||||
|
it "returns false" do
|
||||||
|
decorator = double(source: Product.new)
|
||||||
|
(subject === decorator).should be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe ".====" do
|
||||||
|
context "with an instance" do
|
||||||
|
it "returns true" do
|
||||||
|
(Product === Product.new).should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a derived instance" do
|
||||||
|
it "returns true" do
|
||||||
|
(Product === Widget.new).should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with an unrelated instance" do
|
||||||
|
it "returns false" do
|
||||||
|
(Product === Object.new).should be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a decorated instance" do
|
||||||
|
it "returns true" do
|
||||||
|
decorator = double(source: Product.new)
|
||||||
|
(Product === decorator).should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a decorated derived instance" do
|
||||||
|
it "returns true" do
|
||||||
|
decorator = double(source: Widget.new)
|
||||||
|
(Product === decorator).should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a decorated unrelated instance" do
|
||||||
|
it "returns false" do
|
||||||
|
decorator = double(source: Object.new)
|
||||||
|
(Product === decorator).should be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe ".decorate" do
|
describe ".decorate" do
|
||||||
it "returns a collection decorator" do
|
it "returns a collection decorator" do
|
||||||
Product.stub(:scoped).and_return([Product.new])
|
Product.stub(:scoped).and_return([Product.new])
|
||||||
|
|
|
@ -219,9 +219,66 @@ describe Draper::Decorator do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#==" do
|
describe "#==" do
|
||||||
it "compares the decorated models" do
|
context "with itself" do
|
||||||
other = Draper::Decorator.new(source)
|
it "returns true" do
|
||||||
subject.should == other
|
(subject == subject).should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with another decorator having the same source" do
|
||||||
|
it "returns true" do
|
||||||
|
(subject == ProductDecorator.new(source)).should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with another decorator having a different source" do
|
||||||
|
it "returns false" do
|
||||||
|
(subject == ProductDecorator.new(Object.new)).should be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with the source object" do
|
||||||
|
it "returns true" do
|
||||||
|
(subject == source).should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with another object" do
|
||||||
|
it "returns false" do
|
||||||
|
(subject == Object.new).should be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#===" do
|
||||||
|
context "with itself" do
|
||||||
|
it "returns true" do
|
||||||
|
(subject === subject).should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with another decorator having the same source" do
|
||||||
|
it "returns true" do
|
||||||
|
(subject === ProductDecorator.new(source)).should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with another decorator having a different source" do
|
||||||
|
it "returns false" do
|
||||||
|
(subject === ProductDecorator.new(Object.new)).should be_false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with the source object" do
|
||||||
|
it "returns true" do
|
||||||
|
(subject === source).should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with another object" do
|
||||||
|
it "returns false" do
|
||||||
|
(subject === Object.new).should be_false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue