Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wierd behavior with optional array #615

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions spec/grape/endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,26 @@ def app
end
end

describe "hash array with default value" do
it "is nil when value is not provided" do
subject.params do
optional :my_simple_value, type: String
optional :my_array, type: Array do
requires :foo, default: "bar"
end
end
subject.post("/array") do
{
my_array: params[:my_array].nil?,
my_simple_value: params[:my_simple_value].nil?
}.to_json
end

post "/array"

expect(JSON.parse(last_response.body)).to eq(my_array: true, my_simple_value: true)
end
end
end

describe '#error!' do
Expand Down