@@ -70,7 +70,7 @@ class BogusEntity < Grape::Entity
70
70
71
71
context 'with parameters passed to the block' do
72
72
it 'sets the :proc option in the exposure options' do
73
- block = lambda { | _ | true }
73
+ block = -> ( _ ) { true }
74
74
subject . expose :name , using : 'Awesome' , &block
75
75
expect ( subject . exposures [ :name ] ) . to eq ( proc : block , using : 'Awesome' )
76
76
end
@@ -112,8 +112,8 @@ class BogusEntity < Grape::Entity
112
112
113
113
it 'does not represent nested exposures whose conditions are not met' do
114
114
subject . expose :awesome do
115
- subject . expose ( :condition_met , if : lambda { | _ , _ | true } ) { |_ | 'value' }
116
- subject . expose ( :condition_not_met , if : lambda { | _ , _ | false } ) { |_ | 'value' }
115
+ subject . expose ( :condition_met , if : -> ( _ , _ ) { true } ) { |_ | 'value' }
116
+ subject . expose ( :condition_not_met , if : -> ( _ , _ ) { false } ) { |_ | 'value' }
117
117
end
118
118
119
119
expect ( subject . represent ( { } ) . send ( :value_for , :awesome ) ) . to eq ( condition_met : 'value' )
@@ -228,7 +228,7 @@ class Parent < Person
228
228
end
229
229
230
230
context 'register formatters' do
231
- let ( :date_formatter ) { lambda { | date | date . strftime ( '%m/%d/%Y' ) } }
231
+ let ( :date_formatter ) { -> ( date ) { date . strftime ( '%m/%d/%Y' ) } }
232
232
233
233
it 'registers a formatter' do
234
234
subject . format_with :timestamp , &date_formatter
@@ -261,7 +261,7 @@ class Parent < Person
261
261
it 'formats an exposure with a :format_with lambda that returns a value from the entity instance' do
262
262
object = { }
263
263
264
- subject . expose ( :size , format_with : lambda { | _value | self . object . class . to_s } )
264
+ subject . expose ( :size , format_with : -> ( _value ) { self . object . class . to_s } )
265
265
expect ( subject . represent ( object ) . send ( :value_for , :size ) ) . to eq object . class . to_s
266
266
end
267
267
@@ -364,7 +364,7 @@ class Parent < Person
364
364
end
365
365
366
366
it 'merges nested :if option' do
367
- match_proc = lambda { | _obj , _opts | true }
367
+ match_proc = -> ( _obj , _opts ) { true }
368
368
369
369
subject . class_eval do
370
370
# Symbol
@@ -389,7 +389,7 @@ class Parent < Person
389
389
end
390
390
391
391
it 'merges nested :unless option' do
392
- match_proc = lambda { | _ , _ | true }
392
+ match_proc = -> ( _ , _ ) { true }
393
393
394
394
subject . class_eval do
395
395
# Symbol
@@ -433,10 +433,10 @@ class Parent < Person
433
433
end
434
434
435
435
it 'overrides nested :proc option' do
436
- match_proc = lambda { | _obj , _opts | 'more awesomer' }
436
+ match_proc = -> ( _obj , _opts ) { 'more awesomer' }
437
437
438
438
subject . class_eval do
439
- with_options ( proc : lambda { | _obj , _opts | 'awesome' } ) do
439
+ with_options ( proc : -> ( _obj , _opts ) { 'awesome' } ) do
440
440
expose :awesome_thing , proc : match_proc
441
441
end
442
442
end
@@ -773,8 +773,8 @@ class Parent < Person
773
773
774
774
it "does not expose attributes that don't exist on the object, even with criteria" do
775
775
fresh_class . expose :email
776
- fresh_class . expose :nonexistent_attribute , safe : true , if : lambda { false }
777
- fresh_class . expose :nonexistent_attribute2 , safe : true , if : lambda { true }
776
+ fresh_class . expose :nonexistent_attribute , safe : true , if : -> { false }
777
+ fresh_class . expose :nonexistent_attribute2 , safe : true , if : -> { true }
778
778
779
779
res = fresh_class . new ( model ) . serializable_hash
780
780
expect ( res ) . to have_key :email
@@ -798,9 +798,9 @@ class Parent < Person
798
798
end
799
799
800
800
it 'does not expose attributes that are generated by a block but have not passed criteria' do
801
- fresh_class . expose :nonexistent_attribute , proc : lambda { | _model , _opts |
802
- 'I exist, but it is not yet my time to shine'
803
- } , if : lambda { | _model , _opts | false }
801
+ fresh_class . expose :nonexistent_attribute ,
802
+ proc : -> ( _model , _opts ) { 'I exist, but it is not yet my time to shine' } ,
803
+ if : -> ( _model , _opts ) { false }
804
804
res = fresh_class . new ( model ) . serializable_hash
805
805
expect ( res ) . not_to have_key :nonexistent_attribute
806
806
end
@@ -820,9 +820,9 @@ class TestEntity < Grape::Entity
820
820
end
821
821
822
822
it 'does not expose attributes that are generated by a block but have not passed criteria' do
823
- fresh_class . expose :nonexistent_attribute , proc : lambda { | _ , _ |
824
- 'I exist, but it is not yet my time to shine'
825
- } , if : lambda { | _ , _ | false }
823
+ fresh_class . expose :nonexistent_attribute ,
824
+ proc : -> ( _ , _ ) { 'I exist, but it is not yet my time to shine' } ,
825
+ if : -> ( _ , _ ) { false }
826
826
res = fresh_class . new ( model ) . serializable_hash
827
827
expect ( res ) . not_to have_key :nonexistent_attribute
828
828
end
@@ -901,7 +901,7 @@ def timestamp(date)
901
901
date . strftime ( '%m/%d/%Y' )
902
902
end
903
903
904
- expose :fantasies , format_with : lambda { | f | f . reverse }
904
+ expose :fantasies , format_with : -> ( f ) { f . reverse }
905
905
end
906
906
end
907
907
@@ -1238,7 +1238,7 @@ class UserEntity < Grape::Entity
1238
1238
end
1239
1239
1240
1240
it 'only passes through proc :if exposure if it returns truthy value' do
1241
- exposure_options = { if : lambda { | _ , opts | opts [ :true ] } }
1241
+ exposure_options = { if : -> ( _ , opts ) { opts [ :true ] } }
1242
1242
1243
1243
expect ( subject . send ( :conditions_met? , exposure_options , true : false ) ) . to be false
1244
1244
expect ( subject . send ( :conditions_met? , exposure_options , true : true ) ) . to be true
@@ -1256,7 +1256,7 @@ class UserEntity < Grape::Entity
1256
1256
end
1257
1257
1258
1258
it 'only passes through proc :unless exposure if it returns falsy value' do
1259
- exposure_options = { unless : lambda { | _ , options | options [ :true ] == true } }
1259
+ exposure_options = { unless : -> ( _ , opts ) { opts [ :true ] == true } }
1260
1260
1261
1261
expect ( subject . send ( :conditions_met? , exposure_options , true : false ) ) . to be true
1262
1262
expect ( subject . send ( :conditions_met? , exposure_options , true : true ) ) . to be false
0 commit comments