Implement Decoratable#==

Now model == decorator as well as decorator == model
This commit is contained in:
Andrew Haines 2012-12-11 19:56:50 +00:00
parent 7efeaa492b
commit 46f8a6823c
2 changed files with 29 additions and 1 deletions

View File

@ -21,7 +21,7 @@ module Draper::Decoratable
false
end
def ===(other)
def ==(other)
super || (other.respond_to?(:source) && super(other.source))
end

View File

@ -45,6 +45,34 @@ describe Draper::Decoratable do
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 itself" do
it "returns true" do