|
9 | 9 | let(:parser) { described_class.new(params, settings) } |
10 | 10 |
|
11 | 11 | describe '#parse_request_params' do |
| 12 | + subject(:parse_request_params) { parser.parse_request_params } |
| 13 | + |
12 | 14 | context 'when param is of array type' do |
13 | 15 | let(:params) { [['param_1', { type: 'Array[String]' }]] } |
14 | 16 |
|
15 | 17 | it 'adds is_array option' do |
16 | | - expect(parser.parse_request_params).to eq('param_1' => { type: 'Array[String]', is_array: true }) |
| 18 | + expect(parse_request_params['param_1']).to eq(type: 'Array[String]', is_array: true) |
17 | 19 | end |
18 | 20 |
|
19 | 21 | context 'and array_use_braces setting set to true' do |
20 | 22 | let(:settings) { { array_use_braces: true } } |
21 | 23 |
|
22 | 24 | it 'adds braces to the param key' do |
23 | | - expect(parser.parse_request_params.keys.first).to eq 'param_1[]' |
| 25 | + expect(parse_request_params.keys.first).to eq 'param_1[]' |
24 | 26 | end |
25 | 27 | end |
26 | 28 | end |
|
29 | 31 | let(:params) { [['param_1', { type: 'String' }]] } |
30 | 32 |
|
31 | 33 | it 'does not change options' do |
32 | | - expect(parser.parse_request_params).to eq('param_1' => { type: 'String' }) |
| 34 | + expect(parse_request_params['param_1']).to eq(type: 'String') |
33 | 35 | end |
34 | 36 |
|
35 | 37 | context 'and array_use_braces setting set to true' do |
|
45 | 47 | let(:params) { [['param_1', { type: 'Array' }], ['param_1[param_2]', { type: 'String' }]] } |
46 | 48 |
|
47 | 49 | it 'skips root parameter' do |
48 | | - expect(parser.parse_request_params).not_to have_key 'param_1' |
| 50 | + is_expected.not_to have_key 'param_1' |
49 | 51 | end |
50 | 52 |
|
51 | 53 | it 'adds is_array option to the nested param' do |
52 | | - expect(parser.parse_request_params).to eq('param_1[param_2]' => { type: 'String', is_array: true }) |
| 54 | + expect(parse_request_params['param_1[param_2]']).to eq(type: 'String', is_array: true) |
53 | 55 | end |
54 | 56 |
|
55 | 57 | context 'and array_use_braces setting set to true' do |
56 | 58 | let(:settings) { { array_use_braces: true } } |
57 | 59 |
|
58 | 60 | it 'adds braces to the param key' do |
59 | | - expect(parser.parse_request_params.keys.first).to eq 'param_1[][param_2]' |
| 61 | + expect(parse_request_params.keys.first).to eq 'param_1[][param_2]' |
60 | 62 | end |
61 | 63 | end |
62 | 64 | end |
|
65 | 67 | let(:params) { [['param_1', { type: 'Hash' }], ['param_1[param_2]', { type: 'String' }]] } |
66 | 68 |
|
67 | 69 | it 'skips root parameter' do |
68 | | - expect(parser.parse_request_params).not_to have_key 'param_1' |
| 70 | + is_expected.not_to have_key 'param_1' |
69 | 71 | end |
70 | 72 |
|
71 | 73 | it 'does not change options to the nested param' do |
72 | | - expect(parser.parse_request_params).to eq('param_1[param_2]' => { type: 'String' }) |
| 74 | + expect(parse_request_params['param_1[param_2]']).to eq(type: 'String') |
73 | 75 | end |
74 | 76 |
|
75 | 77 | context 'and array_use_braces setting set to true' do |
76 | 78 | let(:settings) { { array_use_braces: true } } |
77 | 79 |
|
78 | 80 | it 'does not add braces to the param key' do |
79 | | - expect(parser.parse_request_params.keys.first).to eq 'param_1[param_2]' |
| 81 | + expect(parse_request_params.keys.first).to eq 'param_1[param_2]' |
80 | 82 | end |
81 | 83 | end |
82 | 84 | end |
|
0 commit comments