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:
parent
9f49e1c7b3
commit
eefd7d09ca
2 changed files with 28 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue