File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed
Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -143,16 +143,16 @@ def self.root(plural, singular=nil)
143143 # entity. Pass nil or false to represent the object or objects with no
144144 # root name even if one is defined for the entity.
145145 def self . represent ( objects , options = { } )
146- inner = if objects . is_a? ( Array )
147- objects . map { |o | self . new ( o , { :collection => true } . merge ( options ) ) }
146+ inner = if objects . respond_to? ( :to_ary )
147+ objects . to_ary ( ) . map { |o | self . new ( o , { :collection => true } . merge ( options ) ) }
148148 else
149149 self . new ( objects , options )
150150 end
151151
152152 root_element = if options . has_key? ( :root )
153153 options [ :root ]
154154 else
155- objects . is_a? ( Array ) ? @collection_root : @root
155+ objects . respond_to? ( :to_ary ) ? @collection_root : @root
156156 end
157157 root_element ? { root_element => inner } : inner
158158 end
Original file line number Diff line number Diff line change 4646 subject . represent ( Object . new ) . should be_kind_of ( subject )
4747 end
4848
49+ it 'should return a single entity if called with a hash' do
50+ subject . represent ( Hash . new ) . should be_kind_of ( subject )
51+ end
52+
4953 it 'should return multiple entities if called with a collection' do
5054 representation = subject . represent ( 4 . times . map { Object . new } )
5155 representation . should be_kind_of ( Array )
You can’t perform that action at this time.
0 commit comments