Skip to content
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 @@ -56,6 +56,7 @@
* [#2989](https://github.com/ruby-grape/grape/pull/2989): Leave the API format untouched when `format` rejects one with no content type - [@ericproulx](https://github.com/ericproulx).
* [#2990](https://github.com/ruby-grape/grape/pull/2990): Name a nested array element by its own indices when a Hash scope sits between two Array scopes - [@ericproulx](https://github.com/ericproulx).
* [#2991](https://github.com/ruby-grape/grape/pull/2991): Require exactly one name for a `requires` or `optional` block - [@ericproulx](https://github.com/ericproulx).
* [#2992](https://github.com/ruby-grape/grape/pull/2992): Accept a beginless range of `values` for a bare `Array` type - [@ericproulx](https://github.com/ericproulx).
* Your contribution here.

### 4.0.1 (2026-09-15)
Expand Down
4 changes: 3 additions & 1 deletion lib/grape/validations/validations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ def guess_coerce_type(coerce_type, *values_list)

values_list.each do |values|
next if !values || values.is_a?(Proc)
return values.first.class if values.is_a?(Range) || !values.empty?
# A beginless Range has no first element to ask.
return (values.begin || values.end).class if values.is_a?(Range)
return values.first.class unless values.empty?
end
coerce_type
end
Expand Down
15 changes: 15 additions & 0 deletions spec/grape/validations/params_scope_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,21 @@ def initialize(value)
end.not_to raise_error
end

it 'accepts beginless and endless range values' do
expect do
subject.params do
requires :low, type: Array, values: ..5
requires :high, type: Array, values: 1..
end
end.not_to raise_error
end

it 'still raises for a beginless range whose end is not of the member type' do
expect do
subject.params { requires :numbers, type: Array, values: ..5, except_values: ['a'] }
end.to raise_error Grape::Exceptions::IncompatibleOptionValues
end

it 'accepts an array containing only allowed values, given as a literal array' do
subject.params do
optional :periods, type: Array, values: %w[day month]
Expand Down
Loading