grape 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of grape might be problematic. Click here for more details.
- checksums.yaml +5 -13
- data/.rubocop.yml +6 -6
- data/.travis.yml +11 -2
- data/CHANGELOG.md +23 -1
- data/Gemfile +11 -10
- data/Guardfile +5 -6
- data/README.md +194 -13
- data/UPGRADING.md +3 -3
- data/grape.gemspec +1 -1
- data/grape.png +0 -0
- data/lib/grape/api.rb +21 -13
- data/lib/grape/endpoint.rb +31 -13
- data/lib/grape/exceptions/validation.rb +2 -2
- data/lib/grape/locale/en.yml +2 -0
- data/lib/grape/middleware/auth/oauth2.rb +69 -65
- data/lib/grape/middleware/error.rb +4 -2
- data/lib/grape/middleware/formatter.rb +2 -2
- data/lib/grape/middleware/versioner/accept_version_header.rb +1 -1
- data/lib/grape/middleware/versioner/header.rb +3 -3
- data/lib/grape/util/hash_stack.rb +1 -1
- data/lib/grape/validations.rb +22 -8
- data/lib/grape/validations/default.rb +1 -1
- data/lib/grape/validations/exactly_one_of.rb +26 -0
- data/lib/grape/validations/mutual_exclusion.rb +25 -0
- data/lib/grape/validations/presence.rb +1 -1
- data/lib/grape/validations/regexp.rb +2 -1
- data/lib/grape/validations/values.rb +7 -1
- data/lib/grape/version.rb +1 -1
- data/spec/grape/api_spec.rb +390 -333
- data/spec/grape/endpoint_spec.rb +129 -99
- data/spec/grape/entity_spec.rb +47 -27
- data/spec/grape/exceptions/invalid_formatter_spec.rb +1 -1
- data/spec/grape/exceptions/invalid_versioner_option_spec.rb +1 -1
- data/spec/grape/exceptions/missing_mime_type_spec.rb +2 -2
- data/spec/grape/exceptions/missing_option_spec.rb +1 -1
- data/spec/grape/exceptions/unknown_options_spec.rb +1 -1
- data/spec/grape/exceptions/unknown_validator_spec.rb +1 -1
- data/spec/grape/middleware/auth/basic_spec.rb +3 -3
- data/spec/grape/middleware/auth/digest_spec.rb +4 -4
- data/spec/grape/middleware/auth/oauth2_spec.rb +11 -11
- data/spec/grape/middleware/base_spec.rb +9 -9
- data/spec/grape/middleware/error_spec.rb +4 -4
- data/spec/grape/middleware/exception_spec.rb +17 -17
- data/spec/grape/middleware/formatter_spec.rb +38 -38
- data/spec/grape/middleware/versioner/accept_version_header_spec.rb +11 -11
- data/spec/grape/middleware/versioner/header_spec.rb +39 -39
- data/spec/grape/middleware/versioner/param_spec.rb +10 -10
- data/spec/grape/middleware/versioner/path_spec.rb +7 -7
- data/spec/grape/middleware/versioner_spec.rb +4 -4
- data/spec/grape/path_spec.rb +6 -6
- data/spec/grape/util/hash_stack_spec.rb +22 -22
- data/spec/grape/validations/coerce_spec.rb +34 -34
- data/spec/grape/validations/default_spec.rb +16 -16
- data/spec/grape/validations/exactly_one_of_spec.rb +71 -0
- data/spec/grape/validations/mutual_exclusion_spec.rb +61 -0
- data/spec/grape/validations/presence_spec.rb +34 -34
- data/spec/grape/validations/regexp_spec.rb +11 -4
- data/spec/grape/validations/values_spec.rb +34 -20
- data/spec/grape/validations_spec.rb +300 -147
- data/spec/shared/versioning_examples.rb +18 -18
- data/spec/spec_helper.rb +2 -1
- metadata +81 -38
@@ -7,30 +7,30 @@ describe Grape::Middleware::Versioner::Param do
|
|
7
7
|
|
8
8
|
it 'sets the API version based on the default param (apiver)' do
|
9
9
|
env = Rack::MockRequest.env_for("/awesome", params: { "apiver" => "v1" })
|
10
|
-
subject.call(env)[1]["api.version"].
|
10
|
+
expect(subject.call(env)[1]["api.version"]).to eq('v1')
|
11
11
|
end
|
12
12
|
|
13
|
-
it 'cuts (only) the version out of the params'
|
13
|
+
it 'cuts (only) the version out of the params' do
|
14
14
|
env = Rack::MockRequest.env_for("/awesome", params: { "apiver" => "v1", "other_param" => "5" })
|
15
15
|
env['rack.request.query_hash'] = Rack::Utils.parse_nested_query(env['QUERY_STRING'])
|
16
|
-
subject.call(env)[1]['rack.request.query_hash']["apiver"].
|
17
|
-
subject.call(env)[1]['rack.request.query_hash']["other_param"].
|
16
|
+
expect(subject.call(env)[1]['rack.request.query_hash']["apiver"]).to be_nil
|
17
|
+
expect(subject.call(env)[1]['rack.request.query_hash']["other_param"]).to eq("5")
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'provides a nil version if no version is given' do
|
21
21
|
env = Rack::MockRequest.env_for("/")
|
22
|
-
subject.call(env).last.
|
22
|
+
expect(subject.call(env).last).to be_nil
|
23
23
|
end
|
24
24
|
|
25
25
|
context 'with specified parameter name' do
|
26
26
|
before { @options = { parameter: 'v' } }
|
27
27
|
it 'sets the API version based on the custom parameter name' do
|
28
28
|
env = Rack::MockRequest.env_for("/awesome", params: { "v" => "v1" })
|
29
|
-
subject.call(env)[1]["api.version"].
|
29
|
+
expect(subject.call(env)[1]["api.version"]).to eq("v1")
|
30
30
|
end
|
31
31
|
it 'does not set the API version based on the default param' do
|
32
32
|
env = Rack::MockRequest.env_for("/awesome", params: { "apiver" => "v1" })
|
33
|
-
subject.call(env)[1]["api.version"].
|
33
|
+
expect(subject.call(env)[1]["api.version"]).to be_nil
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -38,11 +38,11 @@ describe Grape::Middleware::Versioner::Param do
|
|
38
38
|
before { @options = { versions: ['v1', 'v2'] } }
|
39
39
|
it 'throws an error if a non-allowed version is specified' do
|
40
40
|
env = Rack::MockRequest.env_for("/awesome", params: { "apiver" => "v3" })
|
41
|
-
catch(:error) { subject.call(env) }[:status].
|
41
|
+
expect(catch(:error) { subject.call(env) }[:status]).to eq(404)
|
42
42
|
end
|
43
43
|
it 'allows versions that have been specified' do
|
44
44
|
env = Rack::MockRequest.env_for("/awesome", params: { "apiver" => "v1" })
|
45
|
-
subject.call(env)[1]["api.version"].
|
45
|
+
expect(subject.call(env)[1]["api.version"]).to eq('v1')
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -52,7 +52,7 @@ describe Grape::Middleware::Versioner::Param do
|
|
52
52
|
version_options: { using: :header }
|
53
53
|
}
|
54
54
|
env = Rack::MockRequest.env_for("/awesome", params: {})
|
55
|
-
subject.call(env).first.
|
55
|
+
expect(subject.call(env).first).to eq(200)
|
56
56
|
end
|
57
57
|
|
58
58
|
end
|
@@ -5,25 +5,25 @@ describe Grape::Middleware::Versioner::Path do
|
|
5
5
|
subject { Grape::Middleware::Versioner::Path.new(app, @options || {}) }
|
6
6
|
|
7
7
|
it 'sets the API version based on the first path' do
|
8
|
-
subject.call('PATH_INFO' => '/v1/awesome').last.
|
8
|
+
expect(subject.call('PATH_INFO' => '/v1/awesome').last).to eq('v1')
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'does not cut the version out of the path' do
|
12
|
-
subject.call('PATH_INFO' => '/v1/awesome')[1]['PATH_INFO'].
|
12
|
+
expect(subject.call('PATH_INFO' => '/v1/awesome')[1]['PATH_INFO']).to eq('/v1/awesome')
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'provides a nil version if no path is given' do
|
16
|
-
subject.call('PATH_INFO' => '/').last.
|
16
|
+
expect(subject.call('PATH_INFO' => '/').last).to be_nil
|
17
17
|
end
|
18
18
|
|
19
19
|
context 'with a pattern' do
|
20
20
|
before { @options = { pattern: /v./i } }
|
21
21
|
it 'sets the version if it matches' do
|
22
|
-
subject.call('PATH_INFO' => '/v1/awesome').last.
|
22
|
+
expect(subject.call('PATH_INFO' => '/v1/awesome').last).to eq('v1')
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'ignores the version if it fails to match' do
|
26
|
-
subject.call('PATH_INFO' => '/awesome/radical').last.
|
26
|
+
expect(subject.call('PATH_INFO' => '/awesome/radical').last).to be_nil
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -32,11 +32,11 @@ describe Grape::Middleware::Versioner::Path do
|
|
32
32
|
before { @options = { versions: versions } }
|
33
33
|
|
34
34
|
it 'throws an error if a non-allowed version is specified' do
|
35
|
-
catch(:error) { subject.call('PATH_INFO' => '/v3/awesome') }[:status].
|
35
|
+
expect(catch(:error) { subject.call('PATH_INFO' => '/v3/awesome') }[:status]).to eq(404)
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'allows versions that have been specified' do
|
39
|
-
subject.call('PATH_INFO' => '/v1/asoasd').last.
|
39
|
+
expect(subject.call('PATH_INFO' => '/v1/asoasd').last).to eq('v1')
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
@@ -5,18 +5,18 @@ describe Grape::Middleware::Versioner do
|
|
5
5
|
let(:klass) { Grape::Middleware::Versioner }
|
6
6
|
|
7
7
|
it 'recognizes :path' do
|
8
|
-
klass.using(:path).
|
8
|
+
expect(klass.using(:path)).to eq(Grape::Middleware::Versioner::Path)
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'recognizes :header' do
|
12
|
-
klass.using(:header).
|
12
|
+
expect(klass.using(:header)).to eq(Grape::Middleware::Versioner::Header)
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'recognizes :param' do
|
16
|
-
klass.using(:param).
|
16
|
+
expect(klass.using(:param)).to eq(Grape::Middleware::Versioner::Param)
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'recognizes :accept_version_header' do
|
20
|
-
klass.using(:accept_version_header).
|
20
|
+
expect(klass.using(:accept_version_header)).to eq(Grape::Middleware::Versioner::AcceptVersionHeader)
|
21
21
|
end
|
22
22
|
end
|
data/spec/grape/path_spec.rb
CHANGED
@@ -185,7 +185,7 @@ module Grape
|
|
185
185
|
context "when path versioning is used" do
|
186
186
|
it "includes a '/'" do
|
187
187
|
path = Path.new(nil, nil, {})
|
188
|
-
path.
|
188
|
+
allow(path).to receive(:uses_path_versioning?) { true }
|
189
189
|
|
190
190
|
expect(path.suffix).to eql('(/.:format)')
|
191
191
|
end
|
@@ -194,21 +194,21 @@ module Grape
|
|
194
194
|
context "when path versioning is not used" do
|
195
195
|
it "does not include a '/' when the path has a namespace" do
|
196
196
|
path = Path.new(nil, 'namespace', {})
|
197
|
-
path.
|
197
|
+
allow(path).to receive(:uses_path_versioning?) { true }
|
198
198
|
|
199
199
|
expect(path.suffix).to eql('(.:format)')
|
200
200
|
end
|
201
201
|
|
202
202
|
it "does not include a '/' when the path has a path" do
|
203
203
|
path = Path.new('/path', nil, {})
|
204
|
-
path.
|
204
|
+
allow(path).to receive(:uses_path_versioning?) { true }
|
205
205
|
|
206
206
|
expect(path.suffix).to eql('(.:format)')
|
207
207
|
end
|
208
208
|
|
209
209
|
it "includes a '/' otherwise" do
|
210
210
|
path = Path.new(nil, nil, {})
|
211
|
-
path.
|
211
|
+
allow(path).to receive(:uses_path_versioning?) { true }
|
212
212
|
|
213
213
|
expect(path.suffix).to eql('(/.:format)')
|
214
214
|
end
|
@@ -218,8 +218,8 @@ module Grape
|
|
218
218
|
describe "#path_with_suffix" do
|
219
219
|
it "combines the path and suffix" do
|
220
220
|
path = Path.new(nil, nil, {})
|
221
|
-
path.
|
222
|
-
path.
|
221
|
+
allow(path).to receive(:path) { '/the/path' }
|
222
|
+
allow(path).to receive(:suffix) { 'suffix' }
|
223
223
|
|
224
224
|
expect(path.path_with_suffix).to eql('/the/pathsuffix')
|
225
225
|
end
|
@@ -6,11 +6,11 @@ describe Grape::Util::HashStack do
|
|
6
6
|
it 'finds the first available key' do
|
7
7
|
subject[:abc] = 123
|
8
8
|
subject.push(abc: 345)
|
9
|
-
subject.get(:abc).
|
9
|
+
expect(subject.get(:abc)).to eq(345)
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'is nil if the key has not been set' do
|
13
|
-
subject[:abc].
|
13
|
+
expect(subject[:abc]).to be_nil
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -18,7 +18,7 @@ describe Grape::Util::HashStack do
|
|
18
18
|
it 'sets a value on the highest frame' do
|
19
19
|
subject.push
|
20
20
|
subject.set(:abc, 123)
|
21
|
-
subject.stack.last[:abc].
|
21
|
+
expect(subject.stack.last[:abc]).to eq(123)
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -27,96 +27,96 @@ describe Grape::Util::HashStack do
|
|
27
27
|
subject[:abc] = []
|
28
28
|
subject.imbue :abc, [123]
|
29
29
|
subject.imbue :abc, [456]
|
30
|
-
subject[:abc].
|
30
|
+
expect(subject[:abc]).to eq([123, 456])
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'merges a hash that is passed' do
|
34
34
|
subject[:abc] = { foo: 'bar' }
|
35
35
|
subject.imbue :abc, baz: 'wich'
|
36
|
-
subject[:abc].
|
36
|
+
expect(subject[:abc]).to eq(foo: 'bar', baz: 'wich')
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'sets the value if not a hash or array' do
|
40
40
|
subject.imbue :abc, 123
|
41
|
-
subject[:abc].
|
41
|
+
expect(subject[:abc]).to eq(123)
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'is able to imbue an array without explicit setting' do
|
45
45
|
subject.imbue :arr, [1]
|
46
46
|
subject.imbue :arr, [2]
|
47
|
-
subject[:arr].
|
47
|
+
expect(subject[:arr]).to eq([1, 2])
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'is able to imbue a hash without explicit setting' do
|
51
51
|
subject.imbue :hash, foo: 'bar'
|
52
52
|
subject.imbue :hash, baz: 'wich'
|
53
|
-
subject[:hash].
|
53
|
+
expect(subject[:hash]).to eq(foo: 'bar', baz: 'wich')
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
describe '#push' do
|
58
58
|
it 'returns a HashStack' do
|
59
|
-
subject.push(Grape::Util::HashStack.new).
|
59
|
+
expect(subject.push(Grape::Util::HashStack.new)).to be_kind_of(Grape::Util::HashStack)
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'places the passed value on the top of the stack' do
|
63
63
|
subject.push(abc: 123)
|
64
|
-
subject.stack.
|
64
|
+
expect(subject.stack).to eq([{}, { abc: 123 }])
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'pushes an empty hash by default' do
|
68
68
|
subject[:abc] = 123
|
69
69
|
subject.push
|
70
|
-
subject.stack.
|
70
|
+
expect(subject.stack).to eq([{ abc: 123 }, {}])
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
74
|
describe '#pop' do
|
75
75
|
it 'removes and return the top frame' do
|
76
76
|
subject.push(abc: 123)
|
77
|
-
subject.pop.
|
78
|
-
subject.stack.size.
|
77
|
+
expect(subject.pop).to eq(abc: 123)
|
78
|
+
expect(subject.stack.size).to eq(1)
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
82
|
describe '#peek' do
|
83
83
|
it 'returns the top frame without removing it' do
|
84
84
|
subject.push(abc: 123)
|
85
|
-
subject.peek.
|
86
|
-
subject.stack.size.
|
85
|
+
expect(subject.peek).to eq(abc: 123)
|
86
|
+
expect(subject.stack.size).to eq(2)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
90
|
describe '#prepend' do
|
91
91
|
it 'returns a HashStack' do
|
92
|
-
subject.prepend(Grape::Util::HashStack.new).
|
92
|
+
expect(subject.prepend(Grape::Util::HashStack.new)).to be_kind_of(Grape::Util::HashStack)
|
93
93
|
end
|
94
94
|
|
95
95
|
it "prepends a HashStack's stack onto its own stack" do
|
96
96
|
other = Grape::Util::HashStack.new.push(abc: 123)
|
97
|
-
subject.prepend(other).stack.
|
97
|
+
expect(subject.prepend(other).stack).to eq([{}, { abc: 123 }, {}])
|
98
98
|
end
|
99
99
|
end
|
100
100
|
|
101
101
|
describe '#concat' do
|
102
102
|
it 'returns a HashStack' do
|
103
|
-
subject.concat(Grape::Util::HashStack.new).
|
103
|
+
expect(subject.concat(Grape::Util::HashStack.new)).to be_kind_of(Grape::Util::HashStack)
|
104
104
|
end
|
105
105
|
|
106
106
|
it "appends a HashStack's stack onto its own stack" do
|
107
107
|
other = Grape::Util::HashStack.new.push(abc: 123)
|
108
|
-
subject.concat(other).stack.
|
108
|
+
expect(subject.concat(other).stack).to eq([{}, {}, { abc: 123 }])
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
112
|
describe '#update' do
|
113
113
|
it 'merges! into the top frame' do
|
114
114
|
subject.update(abc: 123)
|
115
|
-
subject.stack.
|
115
|
+
expect(subject.stack).to eq([{ abc: 123 }])
|
116
116
|
end
|
117
117
|
|
118
118
|
it 'returns a HashStack' do
|
119
|
-
subject.update(abc: 123).
|
119
|
+
expect(subject.update(abc: 123)).to be_kind_of(Grape::Util::HashStack)
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
@@ -126,7 +126,7 @@ describe Grape::Util::HashStack do
|
|
126
126
|
subject.push def: 234
|
127
127
|
clone = subject.clone
|
128
128
|
clone[:def] = 345
|
129
|
-
subject[:def].
|
129
|
+
expect(subject[:def]).to eq(234)
|
130
130
|
end
|
131
131
|
end
|
132
132
|
end
|
@@ -30,8 +30,8 @@ describe Grape::Validations::CoerceValidator do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
get '/single', age: '43a'
|
33
|
-
last_response.status.
|
34
|
-
last_response.body.
|
33
|
+
expect(last_response.status).to eq(400)
|
34
|
+
expect(last_response.body).to eq('年龄格式不正确')
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'gives an english fallback error when default locale message is blank' do
|
@@ -44,8 +44,8 @@ describe Grape::Validations::CoerceValidator do
|
|
44
44
|
end
|
45
45
|
|
46
46
|
get '/single', age: '43a'
|
47
|
-
last_response.status.
|
48
|
-
last_response.body.
|
47
|
+
expect(last_response.status).to eq(400)
|
48
|
+
expect(last_response.body).to eq('age is invalid')
|
49
49
|
end
|
50
50
|
|
51
51
|
end
|
@@ -59,12 +59,12 @@ describe Grape::Validations::CoerceValidator do
|
|
59
59
|
end
|
60
60
|
|
61
61
|
get '/single', int: '43a'
|
62
|
-
last_response.status.
|
63
|
-
last_response.body.
|
62
|
+
expect(last_response.status).to eq(400)
|
63
|
+
expect(last_response.body).to eq('int is invalid')
|
64
64
|
|
65
65
|
get '/single', int: '43'
|
66
|
-
last_response.status.
|
67
|
-
last_response.body.
|
66
|
+
expect(last_response.status).to eq(200)
|
67
|
+
expect(last_response.body).to eq('int works')
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'error on malformed input (Array)' do
|
@@ -76,12 +76,12 @@ describe Grape::Validations::CoerceValidator do
|
|
76
76
|
end
|
77
77
|
|
78
78
|
get 'array', ids: ['1', '2', 'az']
|
79
|
-
last_response.status.
|
80
|
-
last_response.body.
|
79
|
+
expect(last_response.status).to eq(400)
|
80
|
+
expect(last_response.body).to eq('ids is invalid')
|
81
81
|
|
82
82
|
get 'array', ids: ['1', '2', '890']
|
83
|
-
last_response.status.
|
84
|
-
last_response.body.
|
83
|
+
expect(last_response.status).to eq(200)
|
84
|
+
expect(last_response.body).to eq('array int works')
|
85
85
|
end
|
86
86
|
|
87
87
|
context 'complex objects' do
|
@@ -102,12 +102,12 @@ describe Grape::Validations::CoerceValidator do
|
|
102
102
|
end
|
103
103
|
|
104
104
|
get '/user', user: "32"
|
105
|
-
last_response.status.
|
106
|
-
last_response.body.
|
105
|
+
expect(last_response.status).to eq(400)
|
106
|
+
expect(last_response.body).to eq('user is invalid')
|
107
107
|
|
108
108
|
get '/user', user: { id: 32, name: 'Bob' }
|
109
|
-
last_response.status.
|
110
|
-
last_response.body.
|
109
|
+
expect(last_response.status).to eq(200)
|
110
|
+
expect(last_response.body).to eq('complex works')
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
@@ -121,8 +121,8 @@ describe Grape::Validations::CoerceValidator do
|
|
121
121
|
end
|
122
122
|
|
123
123
|
get '/int', int: "45"
|
124
|
-
last_response.status.
|
125
|
-
last_response.body.
|
124
|
+
expect(last_response.status).to eq(200)
|
125
|
+
expect(last_response.body).to eq('Fixnum')
|
126
126
|
end
|
127
127
|
|
128
128
|
it 'Array of Integers' do
|
@@ -134,8 +134,8 @@ describe Grape::Validations::CoerceValidator do
|
|
134
134
|
end
|
135
135
|
|
136
136
|
get '/array', arry: ['1', '2', '3']
|
137
|
-
last_response.status.
|
138
|
-
last_response.body.
|
137
|
+
expect(last_response.status).to eq(200)
|
138
|
+
expect(last_response.body).to eq('Fixnum')
|
139
139
|
end
|
140
140
|
|
141
141
|
it 'Array of Bools' do
|
@@ -147,8 +147,8 @@ describe Grape::Validations::CoerceValidator do
|
|
147
147
|
end
|
148
148
|
|
149
149
|
get 'array', arry: [1, 0]
|
150
|
-
last_response.status.
|
151
|
-
last_response.body.
|
150
|
+
expect(last_response.status).to eq(200)
|
151
|
+
expect(last_response.body).to eq('TrueClass')
|
152
152
|
end
|
153
153
|
|
154
154
|
it 'Bool' do
|
@@ -160,20 +160,20 @@ describe Grape::Validations::CoerceValidator do
|
|
160
160
|
end
|
161
161
|
|
162
162
|
get '/bool', bool: 1
|
163
|
-
last_response.status.
|
164
|
-
last_response.body.
|
163
|
+
expect(last_response.status).to eq(200)
|
164
|
+
expect(last_response.body).to eq('TrueClass')
|
165
165
|
|
166
166
|
get '/bool', bool: 0
|
167
|
-
last_response.status.
|
168
|
-
last_response.body.
|
167
|
+
expect(last_response.status).to eq(200)
|
168
|
+
expect(last_response.body).to eq('FalseClass')
|
169
169
|
|
170
170
|
get '/bool', bool: 'false'
|
171
|
-
last_response.status.
|
172
|
-
last_response.body.
|
171
|
+
expect(last_response.status).to eq(200)
|
172
|
+
expect(last_response.body).to eq('FalseClass')
|
173
173
|
|
174
174
|
get '/bool', bool: 'true'
|
175
|
-
last_response.status.
|
176
|
-
last_response.body.
|
175
|
+
expect(last_response.status).to eq(200)
|
176
|
+
expect(last_response.body).to eq('TrueClass')
|
177
177
|
end
|
178
178
|
|
179
179
|
it 'file' do
|
@@ -185,8 +185,8 @@ describe Grape::Validations::CoerceValidator do
|
|
185
185
|
end
|
186
186
|
|
187
187
|
post '/upload', file: Rack::Test::UploadedFile.new(__FILE__)
|
188
|
-
last_response.status.
|
189
|
-
last_response.body.
|
188
|
+
expect(last_response.status).to eq(201)
|
189
|
+
expect(last_response.body).to eq(File.basename(__FILE__).to_s)
|
190
190
|
end
|
191
191
|
|
192
192
|
it 'Nests integers' do
|
@@ -200,8 +200,8 @@ describe Grape::Validations::CoerceValidator do
|
|
200
200
|
end
|
201
201
|
|
202
202
|
get '/int', integers: { int: "45" }
|
203
|
-
last_response.status.
|
204
|
-
last_response.body.
|
203
|
+
expect(last_response.status).to eq(200)
|
204
|
+
expect(last_response.body).to eq('Fixnum')
|
205
205
|
end
|
206
206
|
end
|
207
207
|
end
|