1
0
Fork 0
mirror of https://github.com/drapergem/draper synced 2023-03-27 23:21:17 -04:00

Fix CollectionDecorator#to_s

Previously it could raise an error when set to infer each item's
decorator.
This commit is contained in:
Andrew Haines 2012-12-26 12:20:42 +00:00
parent 9f49e1c7b3
commit eefd7d09ca
2 changed files with 28 additions and 1 deletions

View file

@ -55,7 +55,13 @@ module Draper
end
def to_s
"#<CollectionDecorator of #{decorator_class} for #{source.inspect}>"
klass = begin
decorator_class
rescue Draper::UninferrableDecoratorError
"inferred decorators"
end
"#<CollectionDecorator of #{klass} for #{source.inspect}>"
end
def context=(value)

View file

@ -286,4 +286,25 @@ describe Draper::CollectionDecorator do
end
end
describe "#to_s" do
subject { Draper::CollectionDecorator.new(source, options) }
let(:source) { ["a", "b", "c"] }
context "when :with option was given" do
let(:options) { {with: ProductDecorator} }
it "returns a string representation of the CollectionDecorator" do
subject.to_s.should == '#<CollectionDecorator of ProductDecorator for ["a", "b", "c"]>'
end
end
context "when :with option was not given" do
let(:options) { {} }
it "returns a string representation of the CollectionDecorator" do
subject.to_s.should == '#<CollectionDecorator of inferred decorators for ["a", "b", "c"]>'
end
end
end
end