Skip to content

Commit 31b9b01

Browse files
natecjdblock
authored andcommitted
Added missing method all_or_none_of for the parameters DSL.
1 parent 2302e26 commit 31b9b01

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
0.9.1 (Next)
22
============
3-
* [#803](https://github.com/intridea/grape/pull/803): Added `all_or_none_of` parameter validator - [@loveltyoic](https://github.com/loveltyoic).
3+
4+
* [#803](https://github.com/intridea/grape/pull/803), [#820](https://github.com/intridea/grape/pull/820): Added `all_or_none_of` parameter validator - [@loveltyoic](https://github.com/loveltyoic), [@natecj](https://github.com/natecj).
45
* [#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).
56
* [#743](https://github.com/intridea/grape/pull/743): Added `allow_blank` parameter validator to validate non-empty strings - [@elado](https://github.com/elado).
67
* [#745](https://github.com/intridea/grape/pull/745): Removed `atom+xml`, `rss+xml`, and `jsonapi` content-types - [@akabraham](https://github.com/akabraham).

lib/grape/dsl/parameters.rb

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ def at_least_one_of(*attrs)
5757
validates(attrs, at_least_one_of: true)
5858
end
5959

60+
def all_or_none_of(*attrs)
61+
validates(attrs, all_or_none_of: true)
62+
end
63+
6064
def group(*attrs, &block)
6165
requires(*attrs, &block)
6266
end

spec/grape/dsl/parameters_spec.rb

+8
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ def valids
9595
end
9696
end
9797

98+
describe '#all_or_none_of' do
99+
it 'adds an all or none of parameter validation' do
100+
subject.all_or_none_of :media, :audio
101+
102+
expect(subject.valids).to eq([[:media, :audio], { all_or_none_of: true }])
103+
end
104+
end
105+
98106
xdescribe '#group' do
99107
it 'does some thing'
100108
end

0 commit comments

Comments
 (0)