diff --git a/lib/draper/decoratable.rb b/lib/draper/decoratable.rb index 7b5e414..4f97f2f 100644 --- a/lib/draper/decoratable.rb +++ b/lib/draper/decoratable.rb @@ -21,7 +21,7 @@ module Draper::Decoratable false end - def ===(other) + def ==(other) super || (other.respond_to?(:source) && super(other.source)) end diff --git a/spec/draper/decoratable_spec.rb b/spec/draper/decoratable_spec.rb index a894f60..cd063e8 100644 --- a/spec/draper/decoratable_spec.rb +++ b/spec/draper/decoratable_spec.rb @@ -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