File tree 3 files changed +10
-1
lines changed
3 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ Next Release
2
2
============
3
3
4
4
* Your contribution here.
5
+ * [ #110 ] ( https://github.com/intridea/grape-entity/pull/110 ) : Fixed safe exposure when using ` Hash ` models - [ @croeck ] ( https://github.com/croeck ) .
5
6
* [ #109 ] ( https://github.com/intridea/grape-entity/pull/109 ) : Add unexpose method - [ @jonmchan ] ( https://github.com/jonmchan ) .
6
7
* [ #98 ] ( https://github.com/intridea/grape-entity/pull/98 ) : Add nested conditionals - [ @zbelzer ] ( https://github.com/zbelzer ) .
7
8
* [ #91 ] ( https://github.com/intridea/grape-entity/pull/91 ) : Fix OpenStruct serializing - [ @etehtsea ] ( https://github.com/etehtsea ) .
Original file line number Diff line number Diff line change @@ -576,7 +576,8 @@ def valid_exposure?(attribute, exposure_options)
576
576
( nested_exposures . any? && nested_exposures . all? { |a , o | valid_exposure? ( a , o ) } ) || \
577
577
exposure_options . key? ( :proc ) || \
578
578
!exposure_options [ :safe ] || \
579
- object . respond_to? ( self . class . name_for ( attribute ) )
579
+ object . respond_to? ( self . class . name_for ( attribute ) ) || \
580
+ object . is_a? ( Hash ) && object . key? ( self . class . name_for ( attribute ) )
580
581
end
581
582
582
583
def conditions_met? ( exposure_options , options )
Original file line number Diff line number Diff line change @@ -683,6 +683,13 @@ class Parent < Person
683
683
expect ( res ) . to have_key :name
684
684
end
685
685
686
+ it 'does expose attributes marked as safe if model is a hash object' do
687
+ fresh_class . expose :name , safe : true
688
+
689
+ res = fresh_class . new ( name : 'myname' ) . serializable_hash
690
+ expect ( res ) . to have_key :name
691
+ end
692
+
686
693
it "does not expose attributes that don't exist on the object, even with criteria" do
687
694
fresh_class . expose :email
688
695
fresh_class . expose :nonexistent_attribute , safe : true , if : lambda { false }
You can’t perform that action at this time.
0 commit comments