grape
grape copied to clipboard
Undefined method 'merge' for empty hash
# works
present :aggregations, []
# raises an <NoMethodError: undefined method `merge' for :aggregations:Symbol>
present :aggregations, {}
"Framework Trace": [
{
"exception_object_id": 70108428652700,
"id": 0,
"trace": "grape (1.2.4) lib/grape/dsl/inside_route.rb:332:in `present'"
},
{
"exception_object_id": 70108428652700,
"id": 2,
"trace": "grape (1.2.4) lib/grape/endpoint.rb:57:in `call'"
},
{
"exception_object_id": 70108428652700,
"id": 3,
"trace": "grape (1.2.4) lib/grape/endpoint.rb:57:in `block (2 levels) in generate_api_method'"
},
{
"exception_object_id": 70108428652700,
"id": 4,
"trace": "activesupport (6.0.0) lib/active_support/notifications.rb:182:in `instrument'"
},
{
"exception_object_id": 70108428652700,
"id": 5,
"trace": "grape (1.2.4) lib/grape/endpoint.rb:56:in `block in generate_api_method'"
},
{
"exception_object_id": 70108428652700,
"id": 6,
"trace": "grape (1.2.4) lib/grape/endpoint.rb:263:in `block in run'"
},
{
"exception_object_id": 70108428652700,
"id": 7,
"trace": "activesupport (6.0.0) lib/active_support/notifications.rb:182:in `instrument'"
},
I've made a temp solution:
present :aggregations, {}, with: GrapeSerializer
# frozen_string_literal: true
class GrapeSerializer
def self.represent(object, *)
object.as_json
end
end
What's the stack for this error?
Try writing a unit test in Grape?