diff --git a/lib/draper/factory.rb b/lib/draper/factory.rb index 0c0f17f..c76422c 100644 --- a/lib/draper/factory.rb +++ b/lib/draper/factory.rb @@ -75,7 +75,7 @@ module Draper end def collection? - object.respond_to?(:first) + object.respond_to?(:first) && !object.is_a?(Struct) end def decoratable? diff --git a/spec/draper/factory_spec.rb b/spec/draper/factory_spec.rb index 1038ef4..3936f10 100644 --- a/spec/draper/factory_spec.rb +++ b/spec/draper/factory_spec.rb @@ -190,6 +190,17 @@ module Draper end end end + + context "when the object is a struct" do + it "returns a singular decorator" do + object = Struct.new(:stuff).new("things") + + decorator_class = Class.new(Decorator) + worker = Factory::Worker.new(decorator_class, object) + + expect(worker.decorator).to eq decorator_class.method(:decorate) + end + end end context "for a collection object" do