goliath 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of goliath might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/goliath.gemspec +1 -0
- data/lib/goliath/connection.rb +15 -11
- data/lib/goliath/constants.rb +1 -0
- data/lib/goliath/rack/default_response_format.rb +3 -9
- data/lib/goliath/rack/formatters/json.rb +1 -1
- data/lib/goliath/rack/params.rb +1 -1
- data/lib/goliath/request.rb +35 -18
- data/lib/goliath/response.rb +2 -0
- data/lib/goliath/version.rb +1 -1
- data/spec/integration/async_request_processing.rb +2 -2
- data/spec/integration/chunked_streaming_spec.rb +1 -1
- data/spec/integration/early_abort_spec.rb +5 -5
- data/spec/integration/echo_spec.rb +7 -7
- data/spec/integration/empty_body_spec.rb +2 -2
- data/spec/integration/event_stream_spec.rb +3 -3
- data/spec/integration/exception_handling_spec.rb +16 -16
- data/spec/integration/http_log_spec.rb +16 -16
- data/spec/integration/jsonp_spec.rb +6 -6
- data/spec/integration/keepalive_spec.rb +2 -2
- data/spec/integration/pipelining_spec.rb +3 -3
- data/spec/integration/reloader_spec.rb +3 -3
- data/spec/integration/template_spec.rb +7 -7
- data/spec/integration/test_helper_spec.rb +3 -3
- data/spec/integration/trace_spec.rb +2 -2
- data/spec/integration/valid_spec.rb +8 -8
- data/spec/integration/websocket_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -3
- data/spec/unit/api_spec.rb +1 -1
- data/spec/unit/connection_spec.rb +8 -8
- data/spec/unit/console_spec.rb +3 -3
- data/spec/unit/env_spec.rb +9 -9
- data/spec/unit/headers_spec.rb +8 -8
- data/spec/unit/rack/default_mime_type_spec.rb +3 -3
- data/spec/unit/rack/formatters/json_spec.rb +35 -13
- data/spec/unit/rack/formatters/plist_spec.rb +8 -8
- data/spec/unit/rack/formatters/xml_spec.rb +18 -18
- data/spec/unit/rack/formatters/yaml_spec.rb +13 -13
- data/spec/unit/rack/heartbeat_spec.rb +15 -15
- data/spec/unit/rack/params_spec.rb +62 -60
- data/spec/unit/rack/render_spec.rb +14 -14
- data/spec/unit/rack/validation/boolean_value_spec.rb +6 -6
- data/spec/unit/rack/validation/default_params_spec.rb +13 -13
- data/spec/unit/rack/validation/numeric_range_spec.rb +17 -17
- data/spec/unit/rack/validation/param_spec.rb +75 -75
- data/spec/unit/rack/validation/request_method_spec.rb +9 -9
- data/spec/unit/rack/validation/required_param_spec.rb +28 -28
- data/spec/unit/rack/validation/required_value_spec.rb +19 -19
- data/spec/unit/request_spec.rb +18 -18
- data/spec/unit/response_spec.rb +6 -6
- data/spec/unit/runner_spec.rb +31 -31
- data/spec/unit/server_spec.rb +21 -21
- data/spec/unit/validation/standard_http_errors_spec.rb +6 -6
- metadata +16 -2
@@ -13,31 +13,31 @@ describe Goliath::Rack::Render do
|
|
13
13
|
let(:render) { Goliath::Rack::Render.new(app) }
|
14
14
|
|
15
15
|
it 'accepts an app' do
|
16
|
-
|
16
|
+
expect { Goliath::Rack::Render.new('my app') }.not_to raise_error
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'returns the status, body and app headers' do
|
20
20
|
app_body = {'c' => 'd'}
|
21
21
|
|
22
|
-
app.
|
22
|
+
expect(app).to receive(:call).and_return([200, {'a' => 'b'}, app_body])
|
23
23
|
status, headers, body = render.call(env)
|
24
24
|
|
25
|
-
status.
|
26
|
-
headers['a'].
|
27
|
-
body.
|
25
|
+
expect(status).to eq(200)
|
26
|
+
expect(headers['a']).to eq('b')
|
27
|
+
expect(body).to eq(app_body)
|
28
28
|
end
|
29
29
|
|
30
30
|
describe 'Vary' do
|
31
31
|
it 'adds Accept to provided Vary header' do
|
32
|
-
app.
|
32
|
+
expect(app).to receive(:call).and_return([200, {'Vary' => 'Cookie'}, {}])
|
33
33
|
status, headers, body = render.call(env)
|
34
|
-
headers['Vary'].
|
34
|
+
expect(headers['Vary']).to eq('Cookie,Accept')
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'sets Accept if there is no Vary header' do
|
38
|
-
app.
|
38
|
+
expect(app).to receive(:call).and_return([200, {}, {}])
|
39
39
|
status, headers, body = render.call(env)
|
40
|
-
headers['Vary'].
|
40
|
+
expect(headers['Vary']).to eq('Accept')
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -51,7 +51,7 @@ describe Goliath::Rack::Render do
|
|
51
51
|
|
52
52
|
describe 'Content-Type' do
|
53
53
|
before(:each) do
|
54
|
-
app.
|
54
|
+
expect(app).to receive(:call).and_return([200, {}, {}])
|
55
55
|
end
|
56
56
|
|
57
57
|
describe 'from header' do
|
@@ -59,7 +59,7 @@ describe Goliath::Rack::Render do
|
|
59
59
|
it "handles content type for #{type}" do
|
60
60
|
env['HTTP_ACCEPT'] = type
|
61
61
|
status, headers, body = render.call(env)
|
62
|
-
headers['Content-Type'].
|
62
|
+
expect(headers['Content-Type']).to match(/^#{Regexp.escape(type)}/)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -69,7 +69,7 @@ describe Goliath::Rack::Render do
|
|
69
69
|
it "converts #{format} to #{content_type}" do
|
70
70
|
env['params']['format'] = format
|
71
71
|
status, headers, body = render.call(env)
|
72
|
-
headers['Content-Type'].
|
72
|
+
expect(headers['Content-Type']).to match(/^#{Regexp.escape(content_type)}/)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
end
|
@@ -78,14 +78,14 @@ describe Goliath::Rack::Render do
|
|
78
78
|
env['HTTP_ACCEPT'] = 'application/xml'
|
79
79
|
env['params']['format'] = 'json'
|
80
80
|
status, headers, body = render.call(env)
|
81
|
-
headers['Content-Type'].
|
81
|
+
expect(headers['Content-Type']).to match(%r{^application/json})
|
82
82
|
end
|
83
83
|
|
84
84
|
describe 'charset' do
|
85
85
|
it 'is set if not present' do
|
86
86
|
env['params']['format'] = 'json'
|
87
87
|
status, headers, body = render.call(env)
|
88
|
-
headers['Content-Type'].
|
88
|
+
expect(headers['Content-Type']).to match(/; charset=utf-8$/)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
@@ -14,32 +14,32 @@ describe Goliath::Rack::Validation::BooleanValue do
|
|
14
14
|
|
15
15
|
it 'uses the default if the key is not present' do
|
16
16
|
@bv.call(@env)
|
17
|
-
@env['params']['id'].
|
17
|
+
expect(@env['params']['id']).to eq(true)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'uses the default if the key is nil' do
|
21
21
|
@env['params']['id'] = nil
|
22
22
|
@bv.call(@env)
|
23
|
-
@env['params']['id'].
|
23
|
+
expect(@env['params']['id']).to eq(true)
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'uses the default if the key is blank' do
|
27
27
|
@env['params']['id'] = ""
|
28
28
|
@bv.call(@env)
|
29
|
-
@env['params']['id'].
|
29
|
+
expect(@env['params']['id']).to eq(true)
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'a random value is false' do
|
33
33
|
@env['params']['id'] = 'blarg'
|
34
34
|
@bv.call(@env)
|
35
|
-
@env['params']['id'].
|
35
|
+
expect(@env['params']['id']).to eq(false)
|
36
36
|
end
|
37
37
|
|
38
38
|
%w(t true TRUE T 1).each do |type|
|
39
39
|
it "considers #{type} true" do
|
40
40
|
@env['params']['id'] = type
|
41
41
|
@bv.call(@env)
|
42
|
-
@env['params']['id'].
|
42
|
+
expect(@env['params']['id']).to eq(true)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -47,7 +47,7 @@ describe Goliath::Rack::Validation::BooleanValue do
|
|
47
47
|
it "considers #{type} false" do
|
48
48
|
@env['params']['id'] = type
|
49
49
|
@bv.call(@env)
|
50
|
-
@env['params']['id'].
|
50
|
+
expect(@env['params']['id']).to eq(false)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -4,15 +4,15 @@ require 'goliath/rack/validation/default_params'
|
|
4
4
|
describe Goliath::Rack::Validation::DefaultParams do
|
5
5
|
it 'accepts an app' do
|
6
6
|
opts = {:defaults => ['title'], :key => 'fields'}
|
7
|
-
|
7
|
+
expect { Goliath::Rack::Validation::DefaultParams.new('my app', opts) }.not_to raise_error
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'requires defaults to be set' do
|
11
|
-
|
11
|
+
expect { Goliath::Rack::Validation::DefaultParams.new('my app', {:key => 'test'}) }.to raise_error('Must provide defaults to DefaultParams')
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'requires key to be set' do
|
15
|
-
|
15
|
+
expect { Goliath::Rack::Validation::DefaultParams.new('my app', {:defaults => 'test'}) }.to raise_error('must provide key to DefaultParams')
|
16
16
|
end
|
17
17
|
|
18
18
|
describe 'with middleware' do
|
@@ -25,47 +25,47 @@ describe Goliath::Rack::Validation::DefaultParams do
|
|
25
25
|
it 'passes through provided key if set' do
|
26
26
|
@env['params']['fl'] = ['pubdate', 'content']
|
27
27
|
@rf.call(@env)
|
28
|
-
@env['params']['fl'].
|
28
|
+
expect(@env['params']['fl']).to eq(['pubdate', 'content'])
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'sets defaults if no key set' do
|
32
32
|
@rf.call(@env)
|
33
|
-
@env['params']['fl'].
|
33
|
+
expect(@env['params']['fl']).to eq(['title', 'link'])
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'sets defaults if no key set' do
|
37
37
|
@env['params']['fl'] = nil
|
38
38
|
@rf.call(@env)
|
39
|
-
@env['params']['fl'].
|
39
|
+
expect(@env['params']['fl']).to eq(['title', 'link'])
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'sets defaults if no key is empty' do
|
43
43
|
@env['params']['fl'] = []
|
44
44
|
@rf.call(@env)
|
45
|
-
@env['params']['fl'].
|
45
|
+
expect(@env['params']['fl']).to eq(['title', 'link'])
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'handles a single item' do
|
49
49
|
@env['params']['fl'] = 'title'
|
50
50
|
@rf.call(@env)
|
51
|
-
@env['params']['fl'].
|
51
|
+
expect(@env['params']['fl']).to eq('title')
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'handles a blank string' do
|
55
55
|
@env['params']['fl'] = ''
|
56
56
|
@rf.call(@env)
|
57
|
-
@env['params']['fl'].
|
57
|
+
expect(@env['params']['fl']).to eq(['title', 'link'])
|
58
58
|
end
|
59
59
|
|
60
60
|
it 'returns the app status, headers and body' do
|
61
61
|
app_headers = {'Content-Type' => 'asdf'}
|
62
62
|
app_body = {'a' => 'b'}
|
63
|
-
@app.
|
63
|
+
expect(@app).to receive(:call).and_return([200, app_headers, app_body])
|
64
64
|
|
65
65
|
status, headers, body = @rf.call(@env)
|
66
|
-
status.
|
67
|
-
headers.
|
68
|
-
body.
|
66
|
+
expect(status).to eq(200)
|
67
|
+
expect(headers).to eq(app_headers)
|
68
|
+
expect(body).to eq(app_body)
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -9,7 +9,7 @@ describe Goliath::Rack::Validation::NumericRange do
|
|
9
9
|
|
10
10
|
it 'accepts options on create' do
|
11
11
|
opts = { :min => 1, :key => 2 }
|
12
|
-
|
12
|
+
expect { Goliath::Rack::Validation::NumericRange.new('my app', opts) }.not_to raise_error
|
13
13
|
end
|
14
14
|
|
15
15
|
describe 'with middleware' do
|
@@ -20,41 +20,41 @@ describe Goliath::Rack::Validation::NumericRange do
|
|
20
20
|
it 'uses the default if value is less then min' do
|
21
21
|
@env['params']['id'] = -10
|
22
22
|
@nr.call(@env)
|
23
|
-
@env['params']['id'].
|
23
|
+
expect(@env['params']['id']).to eq(15)
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'uses the default if value is greater then max' do
|
27
27
|
@env['params']['id'] = 25
|
28
28
|
@nr.call(@env)
|
29
|
-
@env['params']['id'].
|
29
|
+
expect(@env['params']['id']).to eq(15)
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'uses the first value, if the value is an array' do
|
33
33
|
@env['params']['id'] = [10, 11, 12]
|
34
34
|
@nr.call(@env)
|
35
|
-
@env['params']['id'].
|
35
|
+
expect(@env['params']['id']).to eq(10)
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'uses the default if value is not present' do
|
39
39
|
@nr.call(@env)
|
40
|
-
@env['params']['id'].
|
40
|
+
expect(@env['params']['id']).to eq(15)
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'uses the default if value is nil' do
|
44
44
|
@env['params']['id'] = nil
|
45
45
|
@nr.call(@env)
|
46
|
-
@env['params']['id'].
|
46
|
+
expect(@env['params']['id']).to eq(15)
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'returns the app status, headers and body' do
|
50
50
|
app_headers = {'Content-Type' => 'app'}
|
51
51
|
app_body = {'b' => 'c'}
|
52
|
-
@app.
|
52
|
+
expect(@app).to receive(:call).and_return([200, app_headers, app_body])
|
53
53
|
|
54
54
|
status, headers, body = @nr.call(@env)
|
55
|
-
status.
|
56
|
-
headers.
|
57
|
-
body.
|
55
|
+
expect(status).to eq(200)
|
56
|
+
expect(headers).to eq(app_headers)
|
57
|
+
expect(body).to eq(app_body)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -62,42 +62,42 @@ describe Goliath::Rack::Validation::NumericRange do
|
|
62
62
|
nr = Goliath::Rack::Validation::NumericRange.new(@app, {:key => 'id', :min => 1.1, :as => Float})
|
63
63
|
@env['params']['id'] = 1.5
|
64
64
|
nr.call(@env)
|
65
|
-
@env['params']['id'].
|
65
|
+
expect(@env['params']['id']).to eq(1.5)
|
66
66
|
end
|
67
67
|
|
68
68
|
it 'raises error if key is not set' do
|
69
|
-
|
69
|
+
expect { Goliath::Rack::Validation::NumericRange.new('app', {:min => 5}) }.to raise_error('NumericRange key required')
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'raises error if neither min nor max set' do
|
73
|
-
|
73
|
+
expect { Goliath::Rack::Validation::NumericRange.new('app', {:key => 5}) }.to raise_error('NumericRange requires :min or :max')
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'uses min if default not set' do
|
77
77
|
nr = Goliath::Rack::Validation::NumericRange.new(@app, {:key => 'id', :min => 5, :max => 10})
|
78
78
|
@env['params']['id'] = 15
|
79
79
|
nr.call(@env)
|
80
|
-
@env['params']['id'].
|
80
|
+
expect(@env['params']['id']).to eq(5)
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'uses max if default and min not set' do
|
84
84
|
nr = Goliath::Rack::Validation::NumericRange.new(@app, {:key => 'id', :max => 10})
|
85
85
|
@env['params']['id'] = 15
|
86
86
|
nr.call(@env)
|
87
|
-
@env['params']['id'].
|
87
|
+
expect(@env['params']['id']).to eq(10)
|
88
88
|
end
|
89
89
|
|
90
90
|
it "doesn't require min" do
|
91
91
|
nr = Goliath::Rack::Validation::NumericRange.new(@app, {:key => 'id', :max => 10})
|
92
92
|
@env['params']['id'] = 8
|
93
93
|
nr.call(@env)
|
94
|
-
@env['params']['id'].
|
94
|
+
expect(@env['params']['id']).to eq(8)
|
95
95
|
end
|
96
96
|
|
97
97
|
it "doesn't require max" do
|
98
98
|
nr = Goliath::Rack::Validation::NumericRange.new(@app, {:key => 'id', :min => 1})
|
99
99
|
@env['params']['id'] = 15
|
100
100
|
nr.call(@env)
|
101
|
-
@env['params']['id'].
|
101
|
+
expect(@env['params']['id']).to eq(15)
|
102
102
|
end
|
103
103
|
end
|
@@ -8,39 +8,39 @@ describe Goliath::Rack::Validation::Param do
|
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should not allow invalid options" do
|
11
|
-
|
11
|
+
expect {
|
12
12
|
Goliath::Rack::Validation::Param.new(@app, {:key => 'user', :as => Class.new})
|
13
|
-
}.
|
13
|
+
}.to raise_error(Exception)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "raises if key is not supplied" do
|
17
|
-
|
17
|
+
expect {
|
18
18
|
Goliath::Rack::Validation::Param.new(@app)
|
19
|
-
}.
|
19
|
+
}.to raise_error(Exception)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "uses a default value if optional is not supplied" do
|
23
23
|
cv = Goliath::Rack::Validation::Param.new(@app, :key => 'key')
|
24
|
-
cv.optional.
|
24
|
+
expect(cv.optional).to be false
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should have default and message be optional" do
|
28
28
|
cv = nil
|
29
|
-
|
29
|
+
expect {
|
30
30
|
cv = Goliath::Rack::Validation::Param.new(@app, {:key => 'flag',
|
31
31
|
:as => Goliath::Rack::Types::Boolean})
|
32
|
-
}.
|
32
|
+
}.not_to raise_error
|
33
33
|
|
34
|
-
cv.default.
|
35
|
-
cv.message.
|
34
|
+
expect(cv.default).to be_nil
|
35
|
+
expect(cv.message).not_to be_nil
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should fail if given an invalid option" do
|
39
39
|
cv = nil
|
40
|
-
|
40
|
+
expect {
|
41
41
|
cv = Goliath::Rack::Validation::Param.new(@app, {:key => 'flag',
|
42
42
|
:as => Goliath::Rack::Types::Boolean, :animal => :monkey})
|
43
|
-
}.
|
43
|
+
}.to raise_error('Unknown options: {:animal=>:monkey}')
|
44
44
|
end
|
45
45
|
|
46
46
|
context "fetch_key" do
|
@@ -57,7 +57,7 @@ describe Goliath::Rack::Validation::Param do
|
|
57
57
|
}
|
58
58
|
}
|
59
59
|
}
|
60
|
-
@cv.fetch_key(params).
|
60
|
+
expect(@cv.fetch_key(params)).to eq("mike")
|
61
61
|
end
|
62
62
|
|
63
63
|
it "should return nil given an incorrect params" do
|
@@ -68,7 +68,7 @@ describe Goliath::Rack::Validation::Param do
|
|
68
68
|
}
|
69
69
|
}
|
70
70
|
}
|
71
|
-
@cv.fetch_key(params).
|
71
|
+
expect(@cv.fetch_key(params)).to be_nil
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should set value if given" do
|
@@ -79,8 +79,8 @@ describe Goliath::Rack::Validation::Param do
|
|
79
79
|
}
|
80
80
|
}
|
81
81
|
}
|
82
|
-
@cv.fetch_key(params, "tim").
|
83
|
-
params['data']['credentials']['login'].
|
82
|
+
expect(@cv.fetch_key(params, "tim")).to eq("tim")
|
83
|
+
expect(params['data']['credentials']['login']).to eq("tim")
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
@@ -88,9 +88,9 @@ describe Goliath::Rack::Validation::Param do
|
|
88
88
|
|
89
89
|
it 'defaults type and message' do
|
90
90
|
@rp = Goliath::Rack::Validation::Param.new('app', :key => 'key')
|
91
|
-
@rp.type.
|
92
|
-
@rp.type.
|
93
|
-
@rp.message.
|
91
|
+
expect(@rp.type).not_to be_nil
|
92
|
+
expect(@rp.type).not_to match(/^\s*$/)
|
93
|
+
expect(@rp.message).to eq('identifier missing')
|
94
94
|
end
|
95
95
|
|
96
96
|
|
@@ -103,76 +103,76 @@ describe Goliath::Rack::Validation::Param do
|
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'stores type and key options' do
|
106
|
-
@rp.type.
|
107
|
-
@rp.key.
|
106
|
+
expect(@rp.type).to eq('Monkey')
|
107
|
+
expect(@rp.key).to eq('mk')
|
108
108
|
end
|
109
109
|
|
110
110
|
it 'calls validation_error with a custom message' do
|
111
|
-
@rp.
|
111
|
+
expect(@rp).to receive(:validation_error).with(anything, 'Monkey is required')
|
112
112
|
@rp.call(@env)
|
113
113
|
end
|
114
114
|
|
115
115
|
it 'returns the app status, headers and body' do
|
116
116
|
app_headers = {'Content-Type' => 'app'}
|
117
117
|
app_body = {'b' => 'c'}
|
118
|
-
@app.
|
118
|
+
expect(@app).to receive(:call).and_return([201, app_headers, app_body])
|
119
119
|
|
120
120
|
@env['params']['mk'] = 'monkey'
|
121
121
|
|
122
122
|
status, headers, body = @rp.call(@env)
|
123
|
-
status.
|
124
|
-
headers.
|
125
|
-
body.
|
123
|
+
expect(status).to eq(201)
|
124
|
+
expect(headers).to eq(app_headers)
|
125
|
+
expect(body).to eq(app_body)
|
126
126
|
end
|
127
127
|
|
128
128
|
context 'key_valid?' do
|
129
129
|
it 'raises exception if the key is not provided' do
|
130
|
-
@rp.key_valid?(@env['params']).
|
130
|
+
expect(@rp.key_valid?(@env['params'])).to be false
|
131
131
|
end
|
132
132
|
|
133
133
|
it 'raises exception if the key is blank' do
|
134
134
|
@env['params']['mk'] = ''
|
135
|
-
@rp.key_valid?(@env['params']).
|
135
|
+
expect(@rp.key_valid?(@env['params'])).to be false
|
136
136
|
end
|
137
137
|
|
138
138
|
it 'raises exception if the key is nil' do
|
139
139
|
@env['params']['mk'] = nil
|
140
|
-
@rp.key_valid?(@env['params']).
|
140
|
+
expect(@rp.key_valid?(@env['params'])).to be false
|
141
141
|
end
|
142
142
|
|
143
143
|
it 'handles an empty array' do
|
144
144
|
@env['params']['mk'] = []
|
145
|
-
@rp.key_valid?(@env['params']).
|
145
|
+
expect(@rp.key_valid?(@env['params'])).to be false
|
146
146
|
end
|
147
147
|
|
148
148
|
it 'handles an array of nils' do
|
149
149
|
@env['params']['mk'] = [nil, nil, nil]
|
150
|
-
@rp.key_valid?(@env['params']).
|
150
|
+
expect(@rp.key_valid?(@env['params'])).to be false
|
151
151
|
end
|
152
152
|
|
153
153
|
it 'handles an array of blanks' do
|
154
154
|
@env['params']['mk'] = ['', '', '']
|
155
|
-
@rp.key_valid?(@env['params']).
|
155
|
+
expect(@rp.key_valid?(@env['params'])).to be false
|
156
156
|
end
|
157
157
|
|
158
158
|
it "doesn't raise if the key provided" do
|
159
159
|
@env['params']['mk'] = 'my value'
|
160
|
-
@rp.key_valid?(@env['params']).
|
160
|
+
expect(@rp.key_valid?(@env['params'])).to be true
|
161
161
|
end
|
162
162
|
|
163
163
|
it "doesn't raise if the array contains valid data" do
|
164
164
|
@env['params']['mk'] = [1, 2, 3, 4]
|
165
|
-
@rp.key_valid?(@env['params']).
|
165
|
+
expect(@rp.key_valid?(@env['params'])).to be true
|
166
166
|
end
|
167
167
|
|
168
168
|
it "doesn't raise if the key provided is multiline and has blanks" do
|
169
169
|
@env['params']['mk'] = "my\n \nvalue"
|
170
|
-
@rp.key_valid?(@env['params']).
|
170
|
+
expect(@rp.key_valid?(@env['params'])).to be true
|
171
171
|
end
|
172
172
|
|
173
173
|
it "doesn't raise if the key provided is an array and contains multiline with blanks" do
|
174
174
|
@env['params']['mk'] = ["my\n \nvalue", "my\n \nother\n \nvalue"]
|
175
|
-
@rp.key_valid?(@env['params']).
|
175
|
+
expect(@rp.key_valid?(@env['params'])).to be true
|
176
176
|
end
|
177
177
|
end
|
178
178
|
end
|
@@ -194,7 +194,7 @@ describe Goliath::Rack::Validation::Param do
|
|
194
194
|
}
|
195
195
|
}
|
196
196
|
|
197
|
-
@rp.key_valid?(@env['params']).
|
197
|
+
expect(@rp.key_valid?(@env['params'])).to be false
|
198
198
|
end
|
199
199
|
|
200
200
|
it "return true if key is present" do
|
@@ -205,7 +205,7 @@ describe Goliath::Rack::Validation::Param do
|
|
205
205
|
}
|
206
206
|
}
|
207
207
|
|
208
|
-
@rp.key_valid?(@env['params']).
|
208
|
+
expect(@rp.key_valid?(@env['params'])).to be true
|
209
209
|
end
|
210
210
|
end
|
211
211
|
|
@@ -225,7 +225,7 @@ describe Goliath::Rack::Validation::Param do
|
|
225
225
|
}
|
226
226
|
}
|
227
227
|
|
228
|
-
@rp.key_valid?(@env['params']).
|
228
|
+
expect(@rp.key_valid?(@env['params'])).to be false
|
229
229
|
end
|
230
230
|
|
231
231
|
it "return true if key is present" do
|
@@ -236,7 +236,7 @@ describe Goliath::Rack::Validation::Param do
|
|
236
236
|
}
|
237
237
|
}
|
238
238
|
|
239
|
-
@rp.key_valid?(@env['params']).
|
239
|
+
expect(@rp.key_valid?(@env['params'])).to be true
|
240
240
|
end
|
241
241
|
end
|
242
242
|
|
@@ -245,9 +245,9 @@ describe Goliath::Rack::Validation::Param do
|
|
245
245
|
context "Coerce" do
|
246
246
|
|
247
247
|
it "should only accept a class in the :as" do
|
248
|
-
|
248
|
+
expect {
|
249
249
|
Goliath::Rack::Validation::Param.new(@app, {:key => 'user', :as => "not a class"})
|
250
|
-
}.
|
250
|
+
}.to raise_error('Params as must be a class')
|
251
251
|
end
|
252
252
|
|
253
253
|
context 'with middleware' do
|
@@ -266,7 +266,7 @@ describe Goliath::Rack::Validation::Param do
|
|
266
266
|
@env['params']['user'] = value.first
|
267
267
|
cv = Goliath::Rack::Validation::Param.new(@app, {:key => 'user', :as => type})
|
268
268
|
cv.call(@env)
|
269
|
-
@env['params']['user'].
|
269
|
+
expect(@env['params']['user']).to eq(value[1])
|
270
270
|
end
|
271
271
|
end
|
272
272
|
end
|
@@ -282,9 +282,9 @@ describe Goliath::Rack::Validation::Param do
|
|
282
282
|
@env['params']['user'] = value
|
283
283
|
cv = Goliath::Rack::Validation::Param.new(@app, {:key => 'user', :as => type})
|
284
284
|
result = cv.call(@env)
|
285
|
-
result.
|
286
|
-
result.first.
|
287
|
-
result.last.
|
285
|
+
expect(result).to be_an_instance_of(Array)
|
286
|
+
expect(result.first).to eq(400)
|
287
|
+
expect(result.last).to have_key(:error)
|
288
288
|
end
|
289
289
|
end
|
290
290
|
end
|
@@ -292,10 +292,10 @@ describe Goliath::Rack::Validation::Param do
|
|
292
292
|
it "should not fail with a invalid input, given a default value" do
|
293
293
|
cv = nil
|
294
294
|
@env['params']['user'] = "boo"
|
295
|
-
|
295
|
+
expect {
|
296
296
|
cv = Goliath::Rack::Validation::Param.new(@app, {:key => 'user',
|
297
297
|
:as => Goliath::Rack::Types::Boolean , :default => 'default'})
|
298
|
-
}.
|
298
|
+
}.not_to raise_error
|
299
299
|
@env['params']['user'] = 'default'
|
300
300
|
end
|
301
301
|
|
@@ -305,10 +305,10 @@ describe Goliath::Rack::Validation::Param do
|
|
305
305
|
:as => Goliath::Rack::Types::Integer, :message => "custom message"})
|
306
306
|
|
307
307
|
result = cv.call(@env)
|
308
|
-
result.
|
309
|
-
result.first.
|
310
|
-
result.last.
|
311
|
-
result.last[:error].
|
308
|
+
expect(result).to be_an_instance_of(Array)
|
309
|
+
expect(result.first).to eq(400)
|
310
|
+
expect(result.last).to have_key(:error)
|
311
|
+
expect(result.last[:error]).to eq("custom message")
|
312
312
|
end
|
313
313
|
end
|
314
314
|
|
@@ -320,15 +320,15 @@ describe Goliath::Rack::Validation::Param do
|
|
320
320
|
:as => Goliath::Rack::Types::Integer
|
321
321
|
@env['params']['login'] = "3"
|
322
322
|
cv.call(@env)
|
323
|
-
@env['params']['login'].
|
323
|
+
expect(@env['params']['login']).to eq(3)
|
324
324
|
|
325
325
|
@env['params']['login'] = nil
|
326
326
|
cv = Goliath::Rack::Validation::Param.new @app, :key => "login",
|
327
327
|
:as => Goliath::Rack::Types::Integer
|
328
328
|
result = cv.call(@env)
|
329
|
-
result.
|
330
|
-
result.first.
|
331
|
-
result.last.
|
329
|
+
expect(result).to be_an_instance_of(Array)
|
330
|
+
expect(result.first).to eq(400)
|
331
|
+
expect(result.last).to have_key(:error)
|
332
332
|
end
|
333
333
|
|
334
334
|
it "should do required param + coerce (nested)" do
|
@@ -337,30 +337,30 @@ describe Goliath::Rack::Validation::Param do
|
|
337
337
|
@env['params']['login'] = {}
|
338
338
|
@env['params']['login']['other'] = "3"
|
339
339
|
cv.call(@env)
|
340
|
-
@env['params']['login']['other'].
|
340
|
+
expect(@env['params']['login']['other']).to eq(3)
|
341
341
|
|
342
342
|
@env['params']['login'] = {}
|
343
343
|
@env['params']['login']['other'] = nil
|
344
344
|
cv = Goliath::Rack::Validation::Param.new @app, :key => "login.other",
|
345
345
|
:as => Goliath::Rack::Types::Integer
|
346
346
|
result = cv.call(@env)
|
347
|
-
result.
|
348
|
-
result.first.
|
349
|
-
result.last.
|
347
|
+
expect(result).to be_an_instance_of(Array)
|
348
|
+
expect(result.first).to eq(400)
|
349
|
+
expect(result.last).to have_key(:error)
|
350
350
|
end
|
351
351
|
|
352
352
|
it "should do required param + not coerce (not nested)" do
|
353
353
|
cv = Goliath::Rack::Validation::Param.new @app, :key => "login"
|
354
354
|
@env['params']['login'] = "3"
|
355
355
|
cv.call(@env)
|
356
|
-
@env['params']['login'].
|
356
|
+
expect(@env['params']['login']).to eq("3")
|
357
357
|
|
358
358
|
@env['params']['login'] = nil
|
359
359
|
cv = Goliath::Rack::Validation::Param.new @app, :key => "login"
|
360
360
|
result = cv.call(@env)
|
361
|
-
result.
|
362
|
-
result.first.
|
363
|
-
result.last.
|
361
|
+
expect(result).to be_an_instance_of(Array)
|
362
|
+
expect(result.first).to eq(400)
|
363
|
+
expect(result.last).to have_key(:error)
|
364
364
|
end
|
365
365
|
|
366
366
|
it "should do required param + not coerce (nested)" do
|
@@ -368,15 +368,15 @@ describe Goliath::Rack::Validation::Param do
|
|
368
368
|
@env['params']['login'] = {}
|
369
369
|
@env['params']['login']['other'] = "3"
|
370
370
|
cv.call(@env)
|
371
|
-
@env['params']['login']['other'].
|
371
|
+
expect(@env['params']['login']['other']).to eq("3")
|
372
372
|
|
373
373
|
@env['params']['login'] = {}
|
374
374
|
@env['params']['login']['other'] = nil
|
375
375
|
cv = Goliath::Rack::Validation::Param.new @app, :key => "login.other"
|
376
376
|
result = cv.call(@env)
|
377
|
-
result.
|
378
|
-
result.first.
|
379
|
-
result.last.
|
377
|
+
expect(result).to be_an_instance_of(Array)
|
378
|
+
expect(result.first).to eq(400)
|
379
|
+
expect(result.last).to have_key(:error)
|
380
380
|
end
|
381
381
|
|
382
382
|
it "should do optional param + coerce (not nested)" do
|
@@ -384,13 +384,13 @@ describe Goliath::Rack::Validation::Param do
|
|
384
384
|
:as => Goliath::Rack::Types::Integer, :optional => true
|
385
385
|
@env['params']['login'] = "3"
|
386
386
|
cv.call(@env)
|
387
|
-
@env['params']['login'].
|
387
|
+
expect(@env['params']['login']).to eq(3)
|
388
388
|
|
389
389
|
@env['params']['login'] = nil
|
390
390
|
cv = Goliath::Rack::Validation::Param.new @app, :key => "login",
|
391
391
|
:as => Goliath::Rack::Types::Integer, :optional => true
|
392
392
|
result = cv.call(@env)
|
393
|
-
result.
|
393
|
+
expect(result).not_to be_an_instance_of(Array) #implying its OK
|
394
394
|
end
|
395
395
|
|
396
396
|
it "should do optional param + coerce (nested)" do
|
@@ -399,14 +399,14 @@ describe Goliath::Rack::Validation::Param do
|
|
399
399
|
@env['params']['login'] = {}
|
400
400
|
@env['params']['login']['other'] = "3"
|
401
401
|
cv.call(@env)
|
402
|
-
@env['params']['login']['other'].
|
402
|
+
expect(@env['params']['login']['other']).to eq(3)
|
403
403
|
|
404
404
|
@env['params']['login'] = {}
|
405
405
|
@env['params']['login']['other'] = nil
|
406
406
|
cv = Goliath::Rack::Validation::Param.new @app, :key => ['login', 'other'],
|
407
407
|
:as => Goliath::Rack::Types::Integer, :optional => true
|
408
408
|
result = cv.call(@env)
|
409
|
-
result.
|
409
|
+
expect(result).not_to be_an_instance_of(Array) #implying its OK
|
410
410
|
end
|
411
411
|
|
412
412
|
it "should do optional param and not coerce (not nested)" do
|
@@ -414,13 +414,13 @@ describe Goliath::Rack::Validation::Param do
|
|
414
414
|
:optional => true
|
415
415
|
@env['params']['login'] = "3"
|
416
416
|
cv.call(@env)
|
417
|
-
@env['params']['login'].
|
417
|
+
expect(@env['params']['login']).to eq("3")
|
418
418
|
|
419
419
|
@env['params']['login'] = nil
|
420
420
|
cv = Goliath::Rack::Validation::Param.new @app, :key => "login",
|
421
421
|
:optional => true
|
422
422
|
result = cv.call(@env)
|
423
|
-
result.
|
423
|
+
expect(result).not_to be_an_instance_of(Array) #implying its OK
|
424
424
|
end
|
425
425
|
|
426
426
|
it "should do optional param and not coerce (nested)" do
|
@@ -429,14 +429,14 @@ describe Goliath::Rack::Validation::Param do
|
|
429
429
|
@env['params']['login'] = {}
|
430
430
|
@env['params']['login']['other'] = "3"
|
431
431
|
cv.call(@env)
|
432
|
-
@env['params']['login']['other'].
|
432
|
+
expect(@env['params']['login']['other']).to eq("3")
|
433
433
|
|
434
434
|
@env['params']['login'] = {}
|
435
435
|
@env['params']['login']['other'] = nil
|
436
436
|
cv = Goliath::Rack::Validation::Param.new @app, :key => "login.other",
|
437
437
|
:optional => true
|
438
438
|
result = cv.call(@env)
|
439
|
-
result.
|
439
|
+
expect(result).not_to be_an_instance_of(Array) #implying its OK
|
440
440
|
end
|
441
441
|
end
|
442
442
|
end
|