fix bug: unitialized constant NilClassDecorator no need to decorate an empty array anyways
This commit is contained in:
parent
9f869ab84c
commit
5dd5757b25
|
@ -60,7 +60,7 @@ module Draper
|
||||||
define_method(association_symbol) do
|
define_method(association_symbol) do
|
||||||
orig_association = model.send(association_symbol)
|
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]
|
return decorated_associations[association_symbol] if decorated_associations[association_symbol]
|
||||||
|
|
||||||
orig_association = orig_association.send(options[:scope]) if options[:scope]
|
orig_association = orig_association.send(options[:scope]) if options[:scope]
|
||||||
|
|
|
@ -198,6 +198,24 @@ describe Draper::Decorator do
|
||||||
end
|
end
|
||||||
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
|
context "#find" do
|
||||||
before(:each){ subject.class_eval{ decorates_association :similar_products } }
|
before(:each){ subject.class_eval{ decorates_association :similar_products } }
|
||||||
context "with a block" do
|
context "with a block" do
|
||||||
|
|
Loading…
Reference in New Issue