Skip to content

Commit 4d6ec46

Browse files
author
Michael Bleigh
committed
Entity#serializable_hash works when nil is passed in. Closes ruby-grape#71
1 parent 883295c commit 4d6ec46

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/grape/entity.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def exposures
118118
# representation, this is where you can trigger things from conditional options
119119
# etc.
120120
def serializable_hash(runtime_options = {})
121-
opts = options.merge(runtime_options)
121+
opts = options.merge(runtime_options || {})
122122
exposures.inject({}) do |output, (attribute, exposure_options)|
123123
output[key_for(attribute)] = value_for(attribute, opts) if conditions_met?(exposure_options, opts)
124124
output

spec/grape/entity_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
subject{ fresh_class.new(model) }
8888

8989
describe '#serializable_hash' do
90+
it 'should not throw an exception if a nil options object is passed' do
91+
expect{ fresh_class.new(model).serializable_hash(nil) }.not_to raise_error
92+
end
9093
end
9194

9295
describe '#value_for' do

0 commit comments

Comments
 (0)