fix bug: unitialized constant NilClassDecorator no need to decorate an empty array anyways

This commit is contained in:
Alex Okolish 2012-10-20 15:20:14 -07:00
parent 9f869ab84c
commit 5dd5757b25
2 changed files with 19 additions and 1 deletions

View File

@ -60,7 +60,7 @@ module Draper
define_method(association_symbol) do
orig_association = model.send(association_symbol)
return orig_association if orig_association.nil?
return orig_association if orig_association.nil? || orig_association == []
return decorated_associations[association_symbol] if decorated_associations[association_symbol]
orig_association = orig_association.send(options[:scope]) if options[:scope]

View File

@ -198,6 +198,24 @@ describe Draper::Decorator do
end
end
context "when the association returns an empty collection" do
before(:each) do
subject.class_eval{ decorates_association :poro_similar_products }
source.stub(:poro_similar_products ){ [] }
end
context "when find_association_reflection returns nil" do
before(:each) do
subject.stub(:find_association_reflection => nil)
end
it "causes the association's method to return the empty collection" do
subject.poro_similar_products.should eq([])
subject.poro_similar_products.should be_instance_of(Array)
end
end
end
context "#find" do
before(:each){ subject.class_eval{ decorates_association :similar_products } }
context "with a block" do