-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Description
So, given this hypothetical scenario (using grape
v1.0.1):
params do
requires :foo, type: Symbol, values: [:a, :b]
given foo: ->(val) { val == :a } do
optional :bar, type: Symbol, default: :my_default
end
end
put do
binding.pry # Setting a breakpoint to highlight the following examples
end
I get the following when foo
is :a
, as expected:
> request.url
=> "http://example.com/api?foo=a"
> params
=> {"foo"=>:a, "bar"=>:my_default}
However, when foo
is :b
, this seems unexpected:
> request.url
=> "http://example.com/api?foo=b"
> params
=> {"foo"=>:b, "bar"=>:my_default}
Reason why I was surprised by this is that the parameters contract says that the default value of :my_default
is only relevant when foo
is a
. Instead, I should be getting the following:
> params
=> {"foo"=>:b}
Is this a known case, or a bug?