@@ -289,8 +289,7 @@ class Parent < Person
289
289
end
290
290
291
291
additional_hash = { users : [ { id : 1 , name : 'John' } , { id : 2 , name : 'Jay' } ] ,
292
- admins : [ { id : 3 , name : 'Jack' } , { id : 4 , name : 'James' } ]
293
- }
292
+ admins : [ { id : 3 , name : 'Jack' } , { id : 4 , name : 'James' } ] }
294
293
expect ( subject . represent ( additional_hash ) . serializable_hash ) . to eq (
295
294
profiles : additional_hash [ :users ] + additional_hash [ :admins ] ,
296
295
awesome : { just_a_key : 'value' , just_another_key : 'value' }
@@ -354,20 +353,20 @@ class Parent < Person
354
353
355
354
subject . expose :birthday , format_with : :timestamp
356
355
357
- model = { birthday : Time . gm ( 2012 , 2 , 27 ) }
356
+ model = { birthday : Time . gm ( 2012 , 2 , 27 ) }
358
357
expect ( subject . new ( double ( model ) ) . as_json [ :birthday ] ) . to eq '02/27/2012'
359
358
end
360
359
361
360
it 'formats an exposure with a :format_with lambda that returns a value from the entity instance' do
362
361
object = { }
363
362
364
- subject . expose ( :size , format_with : -> ( _value ) { self . object . class . to_s } )
363
+ subject . expose ( :size , format_with : -> ( _value ) { object . class . to_s } )
365
364
expect ( subject . represent ( object ) . value_for ( :size ) ) . to eq object . class . to_s
366
365
end
367
366
368
367
it 'formats an exposure with a :format_with symbol that returns a value from the entity instance' do
369
368
subject . format_with :size_formatter do |_date |
370
- self . object . class . to_s
369
+ object . class . to_s
371
370
end
372
371
373
372
object = { }
@@ -378,7 +377,7 @@ class Parent < Person
378
377
379
378
it 'works global on Grape::Entity' do
380
379
Grape ::Entity . format_with :size_formatter do |_date |
381
- self . object . class . to_s
380
+ object . class . to_s
382
381
end
383
382
object = { }
384
383
@@ -609,14 +608,14 @@ class Parent < Person
609
608
end
610
609
611
610
it 'returns multiple entities if called with a collection' do
612
- representation = subject . represent ( 4 . times . map { Object . new } )
611
+ representation = subject . represent ( Array . new ( 4 ) { Object . new } )
613
612
expect ( representation ) . to be_kind_of Array
614
613
expect ( representation . size ) . to eq ( 4 )
615
614
expect ( representation . reject { |r | r . is_a? ( subject ) } ) . to be_empty
616
615
end
617
616
618
617
it 'adds the collection: true option if called with a collection' do
619
- representation = subject . represent ( 4 . times . map { Object . new } )
618
+ representation = subject . represent ( Array . new ( 4 ) { Object . new } )
620
619
representation . each { |r | expect ( r . options [ :collection ] ) . to be true }
621
620
end
622
621
@@ -628,7 +627,7 @@ class Parent < Person
628
627
629
628
it 'returns a serialized array of hashes of multiple objects if serializable: true' do
630
629
subject . expose ( :awesome ) { |_ | true }
631
- representation = subject . represent ( 2 . times . map { Object . new } , serializable : true )
630
+ representation = subject . represent ( Array . new ( 2 ) { Object . new } , serializable : true )
632
631
expect ( representation ) . to eq ( [ { awesome : true } , { awesome : true } ] )
633
632
end
634
633
@@ -903,7 +902,7 @@ class Parent < Person
903
902
subject . present_collection true
904
903
subject . expose :items
905
904
906
- representation = subject . represent ( 4 . times . map { Object . new } )
905
+ representation = subject . represent ( Array . new ( 4 ) { Object . new } )
907
906
expect ( representation ) . to be_kind_of ( subject )
908
907
expect ( representation . object ) . to be_kind_of ( Hash )
909
908
expect ( representation . object ) . to have_key :items
@@ -915,7 +914,7 @@ class Parent < Person
915
914
subject . present_collection true , :my_items
916
915
subject . expose :my_items
917
916
918
- representation = subject . represent ( 4 . times . map { Object . new } , serializable : true )
917
+ representation = subject . represent ( Array . new ( 4 ) { Object . new } , serializable : true )
919
918
expect ( representation ) . to be_kind_of ( Grape ::Entity ::Exposure ::NestingExposure ::OutputBuilder )
920
919
expect ( representation ) . to be_kind_of ( Hash )
921
920
expect ( representation ) . to have_key :my_items
@@ -941,7 +940,7 @@ class Parent < Person
941
940
942
941
context 'with an array of objects' do
943
942
it 'allows a root element name to be specified' do
944
- representation = subject . represent ( 4 . times . map { Object . new } )
943
+ representation = subject . represent ( Array . new ( 4 ) { Object . new } )
945
944
expect ( representation ) . to be_kind_of Hash
946
945
expect ( representation ) . to have_key 'things'
947
946
expect ( representation [ 'things' ] ) . to be_kind_of Array
@@ -952,13 +951,13 @@ class Parent < Person
952
951
953
952
context 'it can be overridden' do
954
953
it 'can be disabled' do
955
- representation = subject . represent ( 4 . times . map { Object . new } , root : false )
954
+ representation = subject . represent ( Array . new ( 4 ) { Object . new } , root : false )
956
955
expect ( representation ) . to be_kind_of Array
957
956
expect ( representation . size ) . to eq 4
958
957
expect ( representation . reject { |r | r . is_a? ( subject ) } ) . to be_empty
959
958
end
960
959
it 'can use a different name' do
961
- representation = subject . represent ( 4 . times . map { Object . new } , root : 'others' )
960
+ representation = subject . represent ( Array . new ( 4 ) { Object . new } , root : 'others' )
962
961
expect ( representation ) . to be_kind_of Hash
963
962
expect ( representation ) . to have_key 'others'
964
963
expect ( representation [ 'others' ] ) . to be_kind_of Array
@@ -984,7 +983,7 @@ class Parent < Person
984
983
985
984
context 'with an array of objects' do
986
985
it 'allows a root element name to be specified' do
987
- representation = subject . represent ( 4 . times . map { Object . new } )
986
+ representation = subject . represent ( Array . new ( 4 ) { Object . new } )
988
987
expect ( representation ) . to be_kind_of Array
989
988
expect ( representation . size ) . to eq 4
990
989
expect ( representation . reject { |r | r . is_a? ( subject ) } ) . to be_empty
@@ -1005,7 +1004,7 @@ class Parent < Person
1005
1004
1006
1005
context 'with an array of objects' do
1007
1006
it 'allows a root element name to be specified' do
1008
- representation = subject . represent ( 4 . times . map { Object . new } )
1007
+ representation = subject . represent ( Array . new ( 4 ) { Object . new } )
1009
1008
expect ( representation ) . to be_kind_of Hash
1010
1009
expect ( representation ) . to have_key ( 'things' )
1011
1010
expect ( representation [ 'things' ] ) . to be_kind_of Array
@@ -1030,7 +1029,7 @@ class Parent < Person
1030
1029
1031
1030
it 'inherits array root root' do
1032
1031
child_class = Class . new ( subject )
1033
- representation = child_class . represent ( 4 . times . map { Object . new } )
1032
+ representation = child_class . represent ( Array . new ( 4 ) { Object . new } )
1034
1033
expect ( representation ) . to be_kind_of Hash
1035
1034
expect ( representation ) . to have_key ( 'things' )
1036
1035
expect ( representation [ 'things' ] ) . to be_kind_of Array
0 commit comments