File tree Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Expand file tree Collapse file tree 3 files changed +16
-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
+ * [ #91 ] ( https://github.com/intridea/grape-entity/pull/91 ) : Fix OpenStruct serializing - [ @etehtsea ] ( https://github.com/etehtsea ) .
5
6
6
7
0.4.4 (2014-08-17)
7
8
==================
Original file line number Diff line number Diff line change @@ -554,7 +554,7 @@ def delegate_attribute(attribute)
554
554
elsif object . respond_to? ( :fetch , true )
555
555
object . fetch ( name )
556
556
else
557
- raise ArgumentError
557
+ object . send ( name )
558
558
end
559
559
end
560
560
end
Original file line number Diff line number Diff line change 1
1
require 'spec_helper'
2
+ require 'ostruct'
2
3
3
4
describe Grape ::Entity do
4
5
@@ -442,6 +443,19 @@ class Parent < Person
442
443
representation = subject . represent ( { awesome : true } , serializable : true )
443
444
expect ( representation ) . to eq ( awesome : true )
444
445
end
446
+
447
+ it 'returns a serialized hash of an OpenStruct' do
448
+ subject . expose ( :awesome )
449
+ representation = subject . represent ( OpenStruct . new , serializable : true )
450
+ expect ( representation ) . to eq ( awesome : nil )
451
+ end
452
+
453
+ it 'raises error if field not found' do
454
+ subject . expose ( :awesome )
455
+ expect {
456
+ subject . represent ( Object . new , serializable : true )
457
+ } . to raise_error ( NoMethodError )
458
+ end
445
459
end
446
460
447
461
describe '.present_collection' do
You can’t perform that action at this time.
0 commit comments