@@ -203,7 +203,7 @@ class BogusEntity < Grape::Entity
203
203
end
204
204
205
205
describe '.with_options' do
206
- it 'should apply the options to all exposures inside' do
206
+ it 'applies the options to all exposures inside' do
207
207
subject . class_eval do
208
208
with_options ( if : { awesome : true } ) do
209
209
expose :awesome_thing , using : 'Awesome'
@@ -213,7 +213,7 @@ class BogusEntity < Grape::Entity
213
213
subject . exposures [ :awesome_thing ] . should == { if : { awesome : true } , using : 'Awesome' }
214
214
end
215
215
216
- it 'should allow for nested .with_options' do
216
+ it 'allows for nested .with_options' do
217
217
subject . class_eval do
218
218
with_options ( if : { awesome : true } ) do
219
219
with_options ( using : 'Something' ) do
@@ -225,7 +225,7 @@ class BogusEntity < Grape::Entity
225
225
subject . exposures [ :awesome_thing ] . should == { if : { awesome : true } , using : 'Something' }
226
226
end
227
227
228
- it 'should override nested :as option' do
228
+ it 'overrides nested :as option' do
229
229
subject . class_eval do
230
230
with_options ( as : :sweet ) do
231
231
expose :awesome_thing , as : :extra_smooth
@@ -235,7 +235,7 @@ class BogusEntity < Grape::Entity
235
235
subject . exposures [ :awesome_thing ] . should == { as : :extra_smooth }
236
236
end
237
237
238
- it "should merge nested :if option" do
238
+ it "merges nested :if option" do
239
239
match_proc = lambda { |obj , opts | true }
240
240
241
241
subject . class_eval do
@@ -260,7 +260,7 @@ class BogusEntity < Grape::Entity
260
260
}
261
261
end
262
262
263
- it 'should merge nested :unless option' do
263
+ it 'merges nested :unless option' do
264
264
match_proc = lambda { |obj , opts | true }
265
265
266
266
subject . class_eval do
@@ -285,7 +285,7 @@ class BogusEntity < Grape::Entity
285
285
}
286
286
end
287
287
288
- it 'should override nested :using option' do
288
+ it 'overrides nested :using option' do
289
289
subject . class_eval do
290
290
with_options ( using : 'Something' ) do
291
291
expose :awesome_thing , using : 'SomethingElse'
@@ -295,7 +295,7 @@ class BogusEntity < Grape::Entity
295
295
subject . exposures [ :awesome_thing ] . should == { using : 'SomethingElse' }
296
296
end
297
297
298
- it 'should override nested :proc option' do
298
+ it 'overrides nested :proc option' do
299
299
match_proc = lambda { |obj , opts | 'more awesomer' }
300
300
301
301
subject . class_eval do
@@ -307,7 +307,7 @@ class BogusEntity < Grape::Entity
307
307
subject . exposures [ :awesome_thing ] . should == { proc : match_proc }
308
308
end
309
309
310
- it 'should override nested :documentation option' do
310
+ it 'overrides nested :documentation option' do
311
311
subject . class_eval do
312
312
with_options ( documentation : { desc : 'Description.' } ) do
313
313
expose :awesome_thing , documentation : { desc : 'Other description.' }
@@ -517,7 +517,7 @@ class BogusEntity < Grape::Entity
517
517
end
518
518
519
519
context "without safe option" do
520
- it 'should throw an exception when an attribute is not found on the object' do
520
+ it 'throws an exception when an attribute is not found on the object' do
521
521
fresh_class . expose :name , :nonexistent_attribute
522
522
expect { fresh_class . new ( model ) . serializable_hash } . to raise_error
523
523
end
@@ -651,7 +651,6 @@ def timestamp(date)
651
651
652
652
context 'child representations' do
653
653
it 'disables root key name for child representations' do
654
-
655
654
module EntitySpec
656
655
class FriendEntity < Grape ::Entity
657
656
root 'friends' , 'friend'
@@ -690,6 +689,7 @@ class FriendEntity < Grape::Entity
690
689
rep . first . serializable_hash . should ==
{ name :
'Friend 1' , email :
'[email protected] ' }
691
690
rep . last . serializable_hash . should ==
{ name :
'Friend 2' , email :
'[email protected] ' }
692
691
end
692
+
693
693
it "passes through the proc which returns single object with custom options(:using)" do
694
694
module EntitySpec
695
695
class FriendEntity < Grape ::Entity
@@ -708,6 +708,7 @@ class FriendEntity < Grape::Entity
708
708
rep . should be_kind_of EntitySpec ::FriendEntity
709
709
rep . serializable_hash . should ==
{ name :
'Friend 1' , email :
'[email protected] ' }
710
710
end
711
+
711
712
it "passes through the proc which returns empty with custom options(:using)" do
712
713
module EntitySpec
713
714
class FriendEntity < Grape ::Entity
@@ -772,7 +773,6 @@ class FriendEntity < Grape::Entity
772
773
rep . first . serializable_hash [ :email ] . should ==
'[email protected] '
773
774
rep . last . serializable_hash [ :email ] . should ==
'[email protected] '
774
775
end
775
-
776
776
end
777
777
778
778
it 'calls through to the proc if there is one' do
@@ -807,6 +807,37 @@ def name
807
807
rep . send ( :value_for , :name ) . should == "cooler name"
808
808
rep . send ( :value_for , :email ) . should ==
"[email protected] "
809
809
end
810
+
811
+ context "using" do
812
+ before do
813
+ module EntitySpec
814
+ class UserEntity < Grape ::Entity
815
+ expose :name , :email
816
+ end
817
+ end
818
+ end
819
+ it "string" do
820
+ fresh_class . class_eval do
821
+ expose :friends , using : "EntitySpec::UserEntity"
822
+ end
823
+
824
+ rep = subject . send ( :value_for , :friends )
825
+ rep . should be_kind_of Array
826
+ rep . size . should == 2
827
+ rep . all? { |r | r . is_a? ( EntitySpec ::UserEntity ) } . should be_true
828
+ end
829
+
830
+ it 'class' do
831
+ fresh_class . class_eval do
832
+ expose :friends , using : EntitySpec ::UserEntity
833
+ end
834
+
835
+ rep = subject . send ( :value_for , :friends )
836
+ rep . should be_kind_of Array
837
+ rep . size . should == 2
838
+ rep . all? { |r | r . is_a? ( EntitySpec ::UserEntity ) } . should be_true
839
+ end
840
+ end
810
841
end
811
842
812
843
describe '#documentation' do
@@ -951,13 +982,12 @@ def name
951
982
instance . entity . object . should == instance
952
983
end
953
984
954
- it 'should instantiate with options if provided' do
985
+ it 'instantiates with options if provided' do
955
986
instance . entity ( awesome : true ) . options . should == { awesome : true }
956
987
end
957
988
end
958
989
end
959
990
end
960
991
end
961
-
962
992
end
963
993
end
0 commit comments