|
6 | 6 | describe '#each' do
|
7 | 7 | subject(:iterator) { described_class.new(validator, scope, params) }
|
8 | 8 | let(:scope) { Grape::Validations::ParamsScope.new(api: Class.new(Grape::API)) }
|
9 |
| - let(:validator) { double(attrs: %i[first second third]) } |
| 9 | + let(:validator) { double(attrs: %i[first second]) } |
10 | 10 |
|
11 | 11 | context 'when params is a hash' do
|
12 | 12 | let(:params) do
|
|
15 | 15 |
|
16 | 16 | it 'yields params and every single attribute from the list' do
|
17 | 17 | expect { |b| iterator.each(&b) }
|
18 |
| - .to yield_successive_args([params, :first], [params, :second], [params, :third]) |
| 18 | + .to yield_successive_args([params, :first, false], [params, :second, false]) |
19 | 19 | end
|
20 | 20 | end
|
21 | 21 |
|
|
26 | 26 |
|
27 | 27 | it 'yields every single attribute from the list for each of the array elements' do
|
28 | 28 | expect { |b| iterator.each(&b) }.to yield_successive_args(
|
29 |
| - [params[0], :first], [params[0], :second], [params[0], :third], |
30 |
| - [params[1], :first], [params[1], :second], [params[1], :third] |
| 29 | + [params[0], :first, false], [params[0], :second, false], |
| 30 | + [params[1], :first, false], [params[1], :second, false] |
31 | 31 | )
|
32 | 32 | end
|
| 33 | + |
| 34 | + context 'empty values' do |
| 35 | + let(:params) { [{}, '', 10] } |
| 36 | + |
| 37 | + it 'marks params with empty values' do |
| 38 | + expect { |b| iterator.each(&b) }.to yield_successive_args( |
| 39 | + [params[0], :first, true], [params[0], :second, true], |
| 40 | + [params[1], :first, true], [params[1], :second, true], |
| 41 | + [params[2], :first, false], [params[2], :second, false] |
| 42 | + ) |
| 43 | + end |
| 44 | + end |
33 | 45 | end
|
34 | 46 | end
|
35 | 47 | end
|
0 commit comments