Skip to content

Fix Proc with arity one in param values #613

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

Merged
merged 2 commits into from
Jun 12, 2017
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#### Features

* Your contribution here.
* [#613](https://github.com/ruby-grape/grape-swagger/pull/613): Fix Proc with arity one in param values - [@timothysu](https://github.com/timothysu).

#### Fixes

Expand Down
2 changes: 1 addition & 1 deletion lib/grape-swagger/doc_methods/parse_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def param_type(value_type)
def parse_enum_or_range_values(values)
case values
when Proc
parse_enum_or_range_values(values.call)
parse_enum_or_range_values(values.call) if values.parameters.empty?
when Range
parse_range_values(values) if values.first.is_a?(Integer)
else
Expand Down
8 changes: 8 additions & 0 deletions spec/lib/parse_params_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
expect(parsed_range).to eql(enum: %w[a b c])
end
end

describe 'with arity one' do
let(:values) { proc { |v| v < 25 } }
specify do
parsed_range = subject.send(:parse_enum_or_range_values, values)
expect(parsed_range).to be_nil
end
end
end

describe 'values as Array -> enums' do
Expand Down