From d1f2eceb7993f2e7a7cc887e653abc77be144ae8 Mon Sep 17 00:00:00 2001 From: Michael Fairley Date: Mon, 19 Sep 2011 10:44:16 -0700 Subject: [PATCH] Delegate == to the decorated models --- lib/draper/base.rb | 7 +++++++ spec/base_spec.rb | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/lib/draper/base.rb b/lib/draper/base.rb index baca161..07de141 100644 --- a/lib/draper/base.rb +++ b/lib/draper/base.rb @@ -125,6 +125,13 @@ module Draper @model end + # Delegates == to the decorated models + # + # @return [Boolean] true if other's model == self's model + def ==(other) + @model == other.model + end + private def select_methods specified = self.allowed || (model.public_methods.map{|s| s.to_sym} - denied.map{|s| s.to_sym}) diff --git a/spec/base_spec.rb b/spec/base_spec.rb index 08defda..cba2af5 100644 --- a/spec/base_spec.rb +++ b/spec/base_spec.rb @@ -132,6 +132,13 @@ describe Draper::Base do end end + context('.==') do + it "should compare the decorated models" do + other = Draper::Base.new(source) + subject.should == other + end + end + describe "a sample usage with denies" do let(:subject_with_denies){ DecoratorWithDenies.new(source) }