goliath 1.0.5 → 1.0.7
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 +5 -5
- data/examples/rasterize/rasterize.rb +1 -1
- data/goliath.gemspec +1 -0
- data/lib/goliath/connection.rb +16 -12
- 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/rack/templates.rb +1 -1
- data/lib/goliath/request.rb +35 -18
- data/lib/goliath/response.rb +3 -1
- data/lib/goliath/server.rb +1 -1
- 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 +20 -7
@@ -4,7 +4,7 @@ require 'nokogiri'
|
|
4
4
|
|
5
5
|
describe Goliath::Rack::Formatters::XML do
|
6
6
|
it 'accepts an app' do
|
7
|
-
|
7
|
+
expect { Goliath::Rack::Formatters::XML.new('my app') }.not_to raise_error
|
8
8
|
end
|
9
9
|
|
10
10
|
describe 'with a formatter' do
|
@@ -14,52 +14,52 @@ describe Goliath::Rack::Formatters::XML do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'checks content type for application/xml' do
|
17
|
-
@xml.xml_response?({'Content-Type' => 'application/xml'}).
|
17
|
+
expect(@xml.xml_response?({'Content-Type' => 'application/xml'})).to be_truthy
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'returns false for non-applicaton/xml types' do
|
21
|
-
@xml.xml_response?({'Content-Type' => 'application/json'}).
|
21
|
+
expect(@xml.xml_response?({'Content-Type' => 'application/json'})).to be_falsey
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'calls the app with the provided environment' do
|
25
25
|
env_mock = double('env').as_null_object
|
26
|
-
@app.
|
26
|
+
expect(@app).to receive(:call).with(env_mock).and_return([200, {}, {"a" => 1}])
|
27
27
|
@xml.call(env_mock)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'formats the body into xml if content-type is xml' do
|
31
|
-
@app.
|
31
|
+
expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])
|
32
32
|
|
33
33
|
status, header, body = @xml.call({})
|
34
|
-
|
34
|
+
expect { expect(Nokogiri.parse(body.first).search('a').inner_text).to eq('1') }.not_to raise_error
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'generates arrays correctly' do
|
38
|
-
@app.
|
38
|
+
expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, [1, 2]])
|
39
39
|
|
40
40
|
status, header, body = @xml.call({})
|
41
|
-
|
41
|
+
expect {
|
42
42
|
doc = Nokogiri.parse(body.first)
|
43
|
-
doc.search('item').first.inner_text.
|
44
|
-
doc.search('item').last.inner_text.
|
45
|
-
}.
|
43
|
+
expect(doc.search('item').first.inner_text).to eq('1')
|
44
|
+
expect(doc.search('item').last.inner_text).to eq('2')
|
45
|
+
}.not_to raise_error
|
46
46
|
end
|
47
47
|
|
48
48
|
it "doesn't format to xml if the type is not application/xml" do
|
49
|
-
@app.
|
49
|
+
expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/json'}, {:a => 1, :b => 2}])
|
50
50
|
|
51
|
-
@xml.
|
51
|
+
expect(@xml).not_to receive(:to_xml)
|
52
52
|
status, header, body = @xml.call({})
|
53
|
-
body[:a].
|
53
|
+
expect(body[:a]).to eq(1)
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'returns the status and headers' do
|
57
|
-
@app.
|
57
|
+
expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/json'}, {:a => 1, :b => 2}])
|
58
58
|
|
59
|
-
@xml.
|
59
|
+
expect(@xml).not_to receive(:to_xml)
|
60
60
|
status, header, body = @xml.call({})
|
61
|
-
status.
|
62
|
-
header.
|
61
|
+
expect(status).to eq(200)
|
62
|
+
expect(header).to eq({'Content-Type' => 'application/json'})
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
@@ -3,7 +3,7 @@ require 'goliath/rack/formatters/yaml'
|
|
3
3
|
|
4
4
|
describe Goliath::Rack::Formatters::YAML do
|
5
5
|
it 'accepts an app' do
|
6
|
-
|
6
|
+
expect { Goliath::Rack::Formatters::YAML.new('my app') }.not_to raise_error
|
7
7
|
end
|
8
8
|
|
9
9
|
describe 'with a formatter' do
|
@@ -13,41 +13,41 @@ describe Goliath::Rack::Formatters::YAML do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'checks content type for text/yaml' do
|
16
|
-
@ym.yaml_response?({'Content-Type' => 'text/yaml'}).
|
16
|
+
expect(@ym.yaml_response?({'Content-Type' => 'text/yaml'})).to be_truthy
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'returns false for non-applicaton/yaml types' do
|
20
|
-
@ym.yaml_response?({'Content-Type' => 'application/xml'}).
|
20
|
+
expect(@ym.yaml_response?({'Content-Type' => 'application/xml'})).to be_falsey
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'calls the app with the provided environment' do
|
24
24
|
env_mock = double('env').as_null_object
|
25
|
-
@app.
|
25
|
+
expect(@app).to receive(:call).with(env_mock).and_return([200, {}, {"a" => 1}])
|
26
26
|
@ym.call(env_mock)
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'formats the body into yaml if content-type is yaml' do
|
30
|
-
@app.
|
30
|
+
expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'text/yaml'}, {:a => 1, :b => 2}])
|
31
31
|
|
32
32
|
status, header, body = @ym.call({})
|
33
|
-
|
33
|
+
expect { expect(YAML.load(body.first)[:a]).to eq(1) }.not_to raise_error
|
34
34
|
end
|
35
35
|
|
36
36
|
it "doesn't format to yaml if the type is not text/yaml" do
|
37
|
-
@app.
|
37
|
+
expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])
|
38
38
|
|
39
|
-
YAML.
|
39
|
+
expect(YAML).not_to receive(:encode)
|
40
40
|
status, header, body = @ym.call({})
|
41
|
-
body[:a].
|
41
|
+
expect(body[:a]).to eq(1)
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'returns the status and headers' do
|
45
|
-
@app.
|
45
|
+
expect(@app).to receive(:call).and_return([200, {'Content-Type' => 'application/xml'}, {:a => 1, :b => 2}])
|
46
46
|
|
47
|
-
YAML.
|
47
|
+
expect(YAML).not_to receive(:encode)
|
48
48
|
status, header, body = @ym.call({})
|
49
|
-
status.
|
50
|
-
header.
|
49
|
+
expect(status).to eq(200)
|
50
|
+
expect(header).to eq({'Content-Type' => 'application/xml'})
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -4,7 +4,7 @@ require 'goliath/env'
|
|
4
4
|
|
5
5
|
describe Goliath::Rack::Heartbeat do
|
6
6
|
it 'accepts an app' do
|
7
|
-
|
7
|
+
expect { Goliath::Rack::Heartbeat.new('my app') }.not_to raise_error
|
8
8
|
end
|
9
9
|
|
10
10
|
describe 'with the middleware' do
|
@@ -16,54 +16,54 @@ describe Goliath::Rack::Heartbeat do
|
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'allows /status as a path prefix' do
|
19
|
-
@app.
|
19
|
+
expect(@app).to receive(:call)
|
20
20
|
@env['PATH_INFO'] = '/status_endpoint'
|
21
21
|
@hb.call(@env)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "doesn't call the app when request /status" do
|
25
|
-
@app.
|
25
|
+
expect(@app).not_to receive(:call)
|
26
26
|
@env['PATH_INFO'] = '/status'
|
27
27
|
@hb.call(@env)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'returns the status, headers and body from the app on non-/status' do
|
31
31
|
@env['PATH_INFO'] = '/v1'
|
32
|
-
@app.
|
32
|
+
expect(@app).to receive(:call).and_return([200, {'a' => 'b'}, {'c' => 'd'}])
|
33
33
|
status, headers, body = @hb.call(@env)
|
34
|
-
status.
|
35
|
-
headers.
|
36
|
-
body.
|
34
|
+
expect(status).to eq(200)
|
35
|
+
expect(headers).to eq({'a' => 'b'})
|
36
|
+
expect(body).to eq({'c' => 'd'})
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'returns the correct status, headers and body on /status' do
|
40
40
|
@env['PATH_INFO'] = '/status'
|
41
41
|
status, headers, body = @hb.call(@env)
|
42
|
-
status.
|
43
|
-
headers.
|
44
|
-
body.
|
42
|
+
expect(status).to eq(200)
|
43
|
+
expect(headers).to eq({})
|
44
|
+
expect(body).to eq('OK')
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'allows path and response to be set using options' do
|
48
48
|
@hb = Goliath::Rack::Heartbeat.new(@app, :path => '/isup', :response => [204, {}, nil])
|
49
49
|
@env['PATH_INFO'] = '/isup'
|
50
50
|
status, headers, body = @hb.call(@env)
|
51
|
-
status.
|
52
|
-
headers.
|
53
|
-
body.
|
51
|
+
expect(status).to eq(204)
|
52
|
+
expect(headers).to eq({})
|
53
|
+
expect(body).to eq(nil)
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'does not log the request by default' do
|
57
57
|
@env['PATH_INFO'] = '/status'
|
58
58
|
@hb.call(@env)
|
59
|
-
@env[Goliath::Constants::RACK_LOGGER].
|
59
|
+
expect(@env[Goliath::Constants::RACK_LOGGER]).to eq(Log4r::Logger.root)
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'logs the request only if asked' do
|
63
63
|
@env['PATH_INFO'] = '/status'
|
64
64
|
@hb = Goliath::Rack::Heartbeat.new(@app, :log => true)
|
65
65
|
@hb.call(@env)
|
66
|
-
@env[Goliath::Constants::RACK_LOGGER].
|
66
|
+
expect(@env[Goliath::Constants::RACK_LOGGER]).not_to eq(Log4r::Logger.root)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
@@ -3,7 +3,7 @@ require 'goliath/rack/params'
|
|
3
3
|
|
4
4
|
describe Goliath::Rack::Params do
|
5
5
|
it 'accepts an app' do
|
6
|
-
|
6
|
+
expect { Goliath::Rack::Params.new('my app') }.not_to raise_error
|
7
7
|
end
|
8
8
|
|
9
9
|
describe 'with middleware' do
|
@@ -32,15 +32,15 @@ describe Goliath::Rack::Params do
|
|
32
32
|
@env['QUERY_STRING'] = 'foo=bar&baz=bonkey'
|
33
33
|
|
34
34
|
ret = @params.retrieve_params(@env)
|
35
|
-
ret['foo'].
|
36
|
-
ret['baz'].
|
35
|
+
expect(ret['foo']).to eq('bar')
|
36
|
+
expect(ret['baz']).to eq('bonkey')
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'parses the nested query string' do
|
40
40
|
@env['QUERY_STRING'] = 'foo[bar]=baz'
|
41
41
|
|
42
42
|
ret = @params.retrieve_params(@env)
|
43
|
-
ret['foo'].
|
43
|
+
expect(ret['foo']).to eq({'bar' => 'baz'})
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'parses the post body' do
|
@@ -49,18 +49,18 @@ describe Goliath::Rack::Params do
|
|
49
49
|
@env['rack.input'].rewind
|
50
50
|
|
51
51
|
ret = @params.retrieve_params(@env)
|
52
|
-
ret['foo'].
|
53
|
-
ret['baz'].
|
54
|
-
ret['zonk'].
|
52
|
+
expect(ret['foo']).to eq('bar')
|
53
|
+
expect(ret['baz']).to eq('bonkey')
|
54
|
+
expect(ret['zonk']).to eq({'donk' => 'monk'})
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'parses arrays of data' do
|
58
58
|
@env['QUERY_STRING'] = 'foo[]=bar&foo[]=baz&foo[]=foos'
|
59
59
|
|
60
60
|
ret = @params.retrieve_params(@env)
|
61
|
-
ret['foo'].is_a?(Array).
|
62
|
-
ret['foo'].length.
|
63
|
-
ret['foo'].
|
61
|
+
expect(ret['foo'].is_a?(Array)).to be true
|
62
|
+
expect(ret['foo'].length).to eq(3)
|
63
|
+
expect(ret['foo']).to eq(%w(bar baz foos))
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'parses multipart data' do
|
@@ -80,8 +80,8 @@ Berry\r
|
|
80
80
|
@env[Goliath::Constants::CONTENT_LENGTH] = @env['rack.input'].length
|
81
81
|
|
82
82
|
ret = @params.retrieve_params(@env)
|
83
|
-
ret['submit-name'].
|
84
|
-
ret['submit-name-with-content'].
|
83
|
+
expect(ret['submit-name']).to eq('Larry')
|
84
|
+
expect(ret['submit-name-with-content']).to eq('Berry')
|
85
85
|
end
|
86
86
|
|
87
87
|
it 'combines query string and post body params' do
|
@@ -92,14 +92,14 @@ Berry\r
|
|
92
92
|
@env['rack.input'].rewind
|
93
93
|
|
94
94
|
ret = @params.retrieve_params(@env)
|
95
|
-
ret['baz'].
|
96
|
-
ret['foos'].
|
95
|
+
expect(ret['baz']).to eq('bar')
|
96
|
+
expect(ret['foos']).to eq('bonkey')
|
97
97
|
end
|
98
98
|
|
99
99
|
it 'handles empty query and post body' do
|
100
100
|
ret = @params.retrieve_params(@env)
|
101
|
-
ret.is_a?(Hash).
|
102
|
-
ret.
|
101
|
+
expect(ret.is_a?(Hash)).to be true
|
102
|
+
expect(ret).to be_empty
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'prefers post body over query string' do
|
@@ -110,12 +110,12 @@ Berry\r
|
|
110
110
|
@env['rack.input'].rewind
|
111
111
|
|
112
112
|
ret = @params.retrieve_params(@env)
|
113
|
-
ret['foo'].
|
114
|
-
ret['baz'].
|
113
|
+
expect(ret['foo']).to eq('bar2')
|
114
|
+
expect(ret['baz']).to eq('bonkey')
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'sets the params into the environment' do
|
118
|
-
@app.
|
118
|
+
expect(@app).to receive(:call).with(hash_including("params"=>{"a"=>"b"}))
|
119
119
|
|
120
120
|
@env['QUERY_STRING'] = "a=b"
|
121
121
|
@params.call(@env)
|
@@ -124,12 +124,12 @@ Berry\r
|
|
124
124
|
it 'returns status, headers and body from the app' do
|
125
125
|
app_headers = {'Content-Type' => 'hash'}
|
126
126
|
app_body = {:a => 1, :b => 2}
|
127
|
-
@app.
|
127
|
+
expect(@app).to receive(:call).and_return([200, app_headers, app_body])
|
128
128
|
|
129
129
|
status, headers, body = @params.call(@env)
|
130
|
-
status.
|
131
|
-
headers.
|
132
|
-
body.
|
130
|
+
expect(status).to eq(200)
|
131
|
+
expect(headers).to eq(app_headers)
|
132
|
+
expect(body).to eq(app_body)
|
133
133
|
end
|
134
134
|
|
135
135
|
it 'returns a validation error if one is raised while parsing' do
|
@@ -171,44 +171,46 @@ Berry\r
|
|
171
171
|
@env['rack.input'].rewind
|
172
172
|
|
173
173
|
ret = @params.retrieve_params(@env)
|
174
|
-
ret['foos'].
|
174
|
+
expect(ret['foos']).to eq('bonkey')
|
175
175
|
end
|
176
176
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
177
|
+
['application/json', 'application/vnd.api+json', 'application/javascript'].each do |content_type|
|
178
|
+
it "parses #{content_type}" do
|
179
|
+
@env['CONTENT_TYPE'] = content_type
|
180
|
+
@env['rack.input'] = StringIO.new
|
181
|
+
@env['rack.input'] << %|{"foo":"bar"}|
|
182
|
+
@env['rack.input'].rewind
|
183
|
+
|
184
|
+
ret = @params.retrieve_params(@env)
|
185
|
+
expect(ret['foo']).to eq('bar')
|
186
|
+
end
|
187
|
+
|
188
|
+
it "parses #{content_type} that does not evaluate to a hash" do
|
189
|
+
@env['CONTENT_TYPE'] = content_type
|
190
|
+
@env['rack.input'] = StringIO.new
|
191
|
+
@env['rack.input'] << %|["foo","bar"]|
|
192
|
+
@env['rack.input'].rewind
|
193
|
+
|
194
|
+
ret = @params.retrieve_params(@env)
|
195
|
+
expect(ret['_json']).to eq(['foo', 'bar'])
|
196
|
+
end
|
197
|
+
|
198
|
+
it "handles empty input gracefully on #{content_type} JSON" do
|
199
|
+
@env['CONTENT_TYPE'] = content_type
|
200
|
+
@env['rack.input'] = StringIO.new
|
201
|
+
|
202
|
+
ret = @params.retrieve_params(@env)
|
203
|
+
expect(ret).to be_empty
|
204
|
+
end
|
205
|
+
|
206
|
+
it "raises a BadRequestError on invalid #{content_type} JSON" do
|
207
|
+
@env['CONTENT_TYPE'] = content_type
|
208
|
+
@env['rack.input'] = StringIO.new
|
209
|
+
@env['rack.input'] << %|{"foo":"bar" BORKEN}|
|
210
|
+
@env['rack.input'].rewind
|
211
|
+
|
212
|
+
expect{ @params.retrieve_params(@env) }.to raise_error(Goliath::Validation::BadRequestError)
|
213
|
+
end
|
212
214
|
end
|
213
215
|
|
214
216
|
it "doesn't parse unknown content types" do
|
@@ -218,7 +220,7 @@ Berry\r
|
|
218
220
|
@env['rack.input'].rewind
|
219
221
|
|
220
222
|
ret = @params.retrieve_params(@env)
|
221
|
-
ret.
|
223
|
+
expect(ret).to eq({})
|
222
224
|
end
|
223
225
|
end
|
224
226
|
end
|
@@ -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
|