From b84818cb5f9f5cbc4b186a5041f049368359125e Mon Sep 17 00:00:00 2001 From: Chris Ledet Date: Wed, 26 Oct 2011 14:49:38 -0400 Subject: [PATCH] added better specs and allow equality to be checked for both decorator and decorator#model --- lib/draper/base.rb | 2 +- lib/draper/decorated_enumerable_proxy.rb | 4 ---- spec/base_spec.rb | 8 ++++---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/draper/base.rb b/lib/draper/base.rb index 88899a7..c4cdb0c 100644 --- a/lib/draper/base.rb +++ b/lib/draper/base.rb @@ -127,7 +127,7 @@ module Draper # # @return [Boolean] true if other's model == self's model def ==(other) - @model == other.model + @model == (other.respond_to?(:model) ? other.model : other) end def respond_to?(method, include_private = false) diff --git a/lib/draper/decorated_enumerable_proxy.rb b/lib/draper/decorated_enumerable_proxy.rb index 4c05f61..352e06b 100644 --- a/lib/draper/decorated_enumerable_proxy.rb +++ b/lib/draper/decorated_enumerable_proxy.rb @@ -22,10 +22,6 @@ module Draper super || @wrapped_collection.respond_to?(method) end - def include?(member) - @wrapped_collection.include?(member) - end - def to_s "#" end diff --git a/spec/base_spec.rb b/spec/base_spec.rb index c6adcfb..f3d84c3 100644 --- a/spec/base_spec.rb +++ b/spec/base_spec.rb @@ -218,10 +218,10 @@ describe Draper::Base do it "should return whether the member is in the array for a decorated wrapped collection" do # This tests that include? is defined for the DecoratedEnumerableProxy member = paged_array.first - decorator = ProductDecorator.decorate(paged_array) - decorator.respond_to?(:include?) - decorator.include?(member).should == true - decorator.include?(Product.new).should == false + subject.respond_to?(:include?) + subject.include?(member).should == true + subject.include?(subject.first).should == true + subject.include?(Product.new).should == false end end