File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -388,10 +388,14 @@ def self.key_for(attribute)
388
388
exposures [ attribute . to_sym ] [ :as ] || name_for ( attribute )
389
389
end
390
390
391
+ def self . nested_exposures_for ( attribute )
392
+ exposures . select { |a , _ | a . to_s =~ /^#{ attribute } __/ }
393
+ end
394
+
391
395
def value_for ( attribute , options = { } )
392
396
exposure_options = exposures [ attribute . to_sym ]
393
397
394
- nested_exposures = exposures . select { | a , _ | a . to_s =~ /^ #{ attribute } __/ }
398
+ nested_exposures = self . class . nested_exposures_for ( attribute )
395
399
396
400
if exposure_options [ :using ]
397
401
using_options = options . dup
@@ -438,6 +442,8 @@ def delegate_attribute(attribute)
438
442
end
439
443
440
444
def valid_exposure? ( attribute , exposure_options )
445
+ nested_exposures = self . class . nested_exposures_for ( attribute )
446
+ ( nested_exposures . any? && nested_exposures . all? { |a , o | valid_exposure? ( a , o ) } ) || \
441
447
exposure_options . has_key? ( :proc ) || \
442
448
!exposure_options [ :safe ] || \
443
449
object . respond_to? ( self . class . name_for ( attribute ) )
Original file line number Diff line number Diff line change @@ -105,6 +105,21 @@ class BogusEntity < Grape::Entity
105
105
another_nested : "value"
106
106
}
107
107
end
108
+
109
+ it 'is safe if its nested exposures are safe' do
110
+ subject . with_options safe : true do
111
+ subject . expose :awesome do
112
+ subject . expose ( :nested ) { |_ | "value" }
113
+ end
114
+ subject . expose :not_awesome do
115
+ subject . expose :nested
116
+ end
117
+ end
118
+
119
+ valid_keys = subject . represent ( { } ) . valid_exposures . keys
120
+ valid_keys . include? ( :awesome ) . should == true && \
121
+ valid_keys . include? ( :not_awesome ) . should == false
122
+ end
108
123
end
109
124
end
110
125
You can’t perform that action at this time.
0 commit comments