Decorate empty collections

This commit is contained in:
Andrew Haines 2012-12-11 19:49:39 +00:00
parent 7efeaa492b
commit 597fbdf0c8
2 changed files with 7 additions and 5 deletions

View File

@ -10,7 +10,7 @@ module Draper
end end
def call def call
return undecorated if undecorated.nil? || undecorated == [] return undecorated if undecorated.nil?
decorate decorate
end end

View File

@ -22,10 +22,11 @@ describe Draper::DecoratedAssociation do
end end
context "when the association is empty" do context "when the association is empty" do
it "doesn't decorate the collection" do it "returns an empty collection decorator" do
source.stub(:similar_products).and_return([]) source.stub(:similar_products).and_return([])
subject.should_not be_a Draper::CollectionDecorator subject.should be_a Draper::CollectionDecorator
subject.should be_empty subject.should be_empty
subject.first.should be_nil
end end
end end
end end
@ -44,10 +45,11 @@ describe Draper::DecoratedAssociation do
end end
context "when the association is empty" do context "when the association is empty" do
it "doesn't decorate the collection" do it "returns an empty collection decorator" do
source.stub(:poro_similar_products).and_return([]) source.stub(:poro_similar_products).and_return([])
subject.should_not be_a Draper::CollectionDecorator subject.should be_a Draper::CollectionDecorator
subject.should be_empty subject.should be_empty
subject.first.should be_nil
end end
end end
end end