Skip to content

Add missing method for all_or_none_of() #820

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

Closed
wants to merge 2 commits into from
Closed
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
@@ -1,5 +1,6 @@
0.9.1 (Next)
============
* [#820](https://github.com/intridea/grape/pull/820): Added missing method `all_or_none_of` for the DSL parameters - [@natecj](https://github.com/natecj).
* [#803](https://github.com/intridea/grape/pull/803): Added `all_or_none_of` parameter validator - [@loveltyoic](https://github.com/loveltyoic).
* [#774](https://github.com/intridea/grape/pull/774): Extended `mutually_exclusive`, `exactly_one_of`, `at_least_one_of` to work inside any kind of group: `requires` or `optional`, `Hash` or `Array` - [@ShPakvel](https://github.com/ShPakvel).
* [#743](https://github.com/intridea/grape/pull/743): Added `allow_blank` parameter validator to validate non-empty strings - [@elado](https://github.com/elado).
Expand Down
4 changes: 4 additions & 0 deletions lib/grape/dsl/parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def at_least_one_of(*attrs)
validates(attrs, at_least_one_of: true)
end

def all_or_none_of(*attrs)
validates(attrs, all_or_none_of: true)
end

def group(*attrs, &block)
requires(*attrs, &block)
end
Expand Down
8 changes: 8 additions & 0 deletions spec/grape/dsl/parameters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ def valids
end
end

describe '#all_or_none_of' do
it 'adds an all or none of parameter validation' do
subject.all_or_none_of :media, :audio

expect(subject.valids).to eq([[:media, :audio], { all_or_none_of: true }])
end
end

xdescribe '#group' do
it 'does some thing'
end
Expand Down