cp-sparrow 0.0.14 → 0.0.15
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/.travis.yml +2 -5
- data/README.md +6 -3
- data/Rakefile +8 -7
- data/lib/cp-sparrow.rb +1 -0
- data/lib/sparrow/configuration.rb +5 -1
- data/lib/sparrow/core_ext/hash.rb +22 -17
- data/lib/sparrow/dependencies.rb +11 -2
- data/lib/sparrow/logger.rb +1 -1
- data/lib/sparrow/railtie.rb +3 -3
- data/lib/sparrow/request_http_message.rb +1 -1
- data/lib/sparrow/response_middleware.rb +5 -5
- data/lib/sparrow/route_parser.rb +1 -1
- data/lib/sparrow/strategies/ignore.rb +2 -2
- data/lib/sparrow/strategies/json_format_strategies/default_json_format_strategy.rb +1 -1
- data/lib/sparrow/strategies/json_format_strategies/json_format_strategy.rb +5 -4
- data/lib/sparrow/strategies/key_transformation/underscore_key.rb +1 -1
- data/lib/sparrow/strategies/transform_params.rb +5 -1
- data/lib/sparrow/transformable.rb +8 -8
- data/lib/sparrow/version.rb +1 -1
- data/sparrow.gemspec +5 -3
- data/spec/integration/apps/rack_app/app.rb +22 -5
- data/spec/integration/apps/rack_app/config.ru +2 -2
- data/spec/integration/apps/rails_app/README.rdoc +15 -248
- data/spec/integration/apps/rails_app/Rakefile +1 -2
- data/spec/integration/apps/rails_app/app/assets/images/.keep +0 -0
- data/spec/integration/apps/rails_app/app/assets/javascripts/application.js +4 -6
- data/spec/integration/apps/rails_app/app/assets/stylesheets/application.css +6 -4
- data/spec/integration/apps/rails_app/app/controllers/application_controller.rb +3 -1
- data/spec/integration/apps/rails_app/app/controllers/concerns/.keep +0 -0
- data/spec/integration/apps/rails_app/app/controllers/errors_controller.rb +10 -0
- data/spec/integration/apps/rails_app/app/controllers/welcome_controller.rb +0 -5
- data/spec/integration/apps/rails_app/app/mailers/.keep +0 -0
- data/spec/integration/apps/rails_app/app/models/.keep +0 -0
- data/spec/integration/apps/rails_app/app/models/concerns/.keep +0 -0
- data/spec/integration/apps/rails_app/app/views/layouts/application.html.erb +3 -3
- data/spec/integration/apps/rails_app/bin/bundle +3 -0
- data/spec/integration/apps/rails_app/bin/rails +4 -0
- data/spec/integration/apps/rails_app/bin/rake +4 -0
- data/spec/integration/apps/rails_app/bin/setup +29 -0
- data/spec/integration/apps/rails_app/config.ru +2 -2
- data/spec/integration/apps/rails_app/config/application.rb +6 -43
- data/spec/integration/apps/rails_app/config/boot.rb +4 -9
- data/spec/integration/apps/rails_app/config/database.yml +25 -0
- data/spec/integration/apps/rails_app/config/environment.rb +3 -3
- data/spec/integration/apps/rails_app/config/environments/development.rb +23 -13
- data/spec/integration/apps/rails_app/config/environments/production.rb +46 -31
- data/spec/integration/apps/rails_app/config/environments/test.rb +20 -10
- data/spec/integration/apps/rails_app/config/initializers/assets.rb +11 -0
- data/spec/integration/apps/rails_app/config/initializers/cookies_serializer.rb +3 -0
- data/spec/integration/apps/rails_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/integration/apps/rails_app/config/initializers/inflections.rb +6 -5
- data/spec/integration/apps/rails_app/config/initializers/mime_types.rb +0 -1
- data/spec/integration/apps/rails_app/config/initializers/secret_token.rb +1 -1
- data/spec/integration/apps/rails_app/config/initializers/session_store.rb +1 -6
- data/spec/integration/apps/rails_app/config/initializers/wrap_parameters.rb +6 -2
- data/spec/integration/apps/rails_app/config/locales/en.yml +20 -2
- data/spec/integration/apps/rails_app/config/routes.rb +21 -29
- data/spec/integration/apps/rails_app/config/secrets.yml +22 -0
- data/spec/integration/apps/rails_app/lib/assets/.keep +0 -0
- data/spec/integration/apps/rails_app/public/404.html +54 -13
- data/spec/integration/apps/rails_app/public/422.html +54 -13
- data/spec/integration/apps/rails_app/public/500.html +53 -12
- data/spec/integration/rack/camel_caser_spec.rb +18 -18
- data/spec/integration/rack/error_spec.rb +17 -0
- data/spec/integration/rails/camel_caser_accept_header_spec.rb +3 -3
- data/spec/integration/rails/camel_caser_spec.rb +30 -19
- data/spec/spec_helper.rb +1 -2
- data/spec/support/rails_app_helper.rb +1 -1
- data/spec/unit/configuration_spec.rb +2 -2
- metadata +46 -24
@@ -0,0 +1,22 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Your secret key is used for verifying the integrity of signed cookies.
|
4
|
+
# If you change this key, all old signed cookies will become invalid!
|
5
|
+
|
6
|
+
# Make sure the secret is at least 30 characters and all random,
|
7
|
+
# no regular words or you'll be exposed to dictionary attacks.
|
8
|
+
# You can use `rake secret` to generate a secure secret key.
|
9
|
+
|
10
|
+
# Make sure the secrets in this file are kept private
|
11
|
+
# if you're sharing your code publicly.
|
12
|
+
|
13
|
+
development:
|
14
|
+
secret_key_base: 75dda1c248b28032a71bdc4492618eb696b43f9e8e0115f4f3d8bb603e3c26051e15aeaa3f0d11c71b35db060f4627766342b3a93a4cdcb10c38a5294e2d1885
|
15
|
+
|
16
|
+
test:
|
17
|
+
secret_key_base: d29a85353762cd6ea8936982d8a62def1850ac37bdbb42305cac6cf987e40c4ea8a6353aa54906260334f055b88d863104f8d250b457e9846c7d4a81fc6f288b
|
18
|
+
|
19
|
+
# Do not keep production secrets in the repository,
|
20
|
+
# instead read values from the environment.
|
21
|
+
production:
|
22
|
+
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
|
File without changes
|
@@ -2,25 +2,66 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<title>The page you were looking for doesn't exist (404)</title>
|
5
|
-
<
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
16
54
|
</style>
|
17
55
|
</head>
|
18
56
|
|
19
57
|
<body>
|
20
58
|
<!-- This file lives in public/404.html -->
|
21
59
|
<div class="dialog">
|
22
|
-
<
|
23
|
-
|
60
|
+
<div>
|
61
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
62
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
24
65
|
</div>
|
25
66
|
</body>
|
26
67
|
</html>
|
@@ -2,25 +2,66 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<title>The change you wanted was rejected (422)</title>
|
5
|
-
<
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
16
54
|
</style>
|
17
55
|
</head>
|
18
56
|
|
19
57
|
<body>
|
20
58
|
<!-- This file lives in public/422.html -->
|
21
59
|
<div class="dialog">
|
22
|
-
<
|
23
|
-
|
60
|
+
<div>
|
61
|
+
<h1>The change you wanted was rejected.</h1>
|
62
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
63
|
+
</div>
|
64
|
+
<p>If you are the application owner check the logs for more information.</p>
|
24
65
|
</div>
|
25
66
|
</body>
|
26
67
|
</html>
|
@@ -2,24 +2,65 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<title>We're sorry, but something went wrong (500)</title>
|
5
|
-
<
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
6
|
+
<style>
|
7
|
+
body {
|
8
|
+
background-color: #EFEFEF;
|
9
|
+
color: #2E2F30;
|
10
|
+
text-align: center;
|
11
|
+
font-family: arial, sans-serif;
|
12
|
+
margin: 0;
|
13
|
+
}
|
14
|
+
|
15
|
+
div.dialog {
|
16
|
+
width: 95%;
|
17
|
+
max-width: 33em;
|
18
|
+
margin: 4em auto 0;
|
19
|
+
}
|
20
|
+
|
21
|
+
div.dialog > div {
|
22
|
+
border: 1px solid #CCC;
|
23
|
+
border-right-color: #999;
|
24
|
+
border-left-color: #999;
|
25
|
+
border-bottom-color: #BBB;
|
26
|
+
border-top: #B00100 solid 4px;
|
27
|
+
border-top-left-radius: 9px;
|
28
|
+
border-top-right-radius: 9px;
|
29
|
+
background-color: white;
|
30
|
+
padding: 7px 12% 0;
|
31
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
32
|
+
}
|
33
|
+
|
34
|
+
h1 {
|
35
|
+
font-size: 100%;
|
36
|
+
color: #730E15;
|
37
|
+
line-height: 1.5em;
|
38
|
+
}
|
39
|
+
|
40
|
+
div.dialog > p {
|
41
|
+
margin: 0 0 1em;
|
42
|
+
padding: 1em;
|
43
|
+
background-color: #F7F7F7;
|
44
|
+
border: 1px solid #CCC;
|
45
|
+
border-right-color: #999;
|
46
|
+
border-left-color: #999;
|
47
|
+
border-bottom-color: #999;
|
48
|
+
border-bottom-left-radius: 4px;
|
49
|
+
border-bottom-right-radius: 4px;
|
50
|
+
border-top-color: #DADADA;
|
51
|
+
color: #666;
|
52
|
+
box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
|
53
|
+
}
|
16
54
|
</style>
|
17
55
|
</head>
|
18
56
|
|
19
57
|
<body>
|
20
58
|
<!-- This file lives in public/500.html -->
|
21
59
|
<div class="dialog">
|
22
|
-
<
|
60
|
+
<div>
|
61
|
+
<h1>We're sorry, but something went wrong.</h1>
|
62
|
+
</div>
|
63
|
+
<p>If you are the application owner check the logs for more information.</p>
|
23
64
|
</div>
|
24
65
|
</body>
|
25
66
|
</html>
|
@@ -1,23 +1,23 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "camel caser middleware", type: :rack do
|
4
|
-
|
5
|
-
let(:json) do
|
6
|
-
|
4
|
+
|
5
|
+
let(:json) do
|
6
|
+
JSON.generate({userName: "dsci", bar:{ lordFoo: 12 }})
|
7
7
|
end
|
8
|
-
|
9
|
-
context "accept header is given" do
|
10
|
-
|
11
|
-
before do
|
8
|
+
|
9
|
+
context "accept header is given" do
|
10
|
+
|
11
|
+
before do
|
12
12
|
post '/', json, {'request-json-format' => 'underscore',
|
13
13
|
'response-json-format' => 'underscore'}
|
14
14
|
end
|
15
|
-
|
16
|
-
subject do
|
17
|
-
|
15
|
+
|
16
|
+
subject do
|
17
|
+
JSON.parse(last_response.body)
|
18
18
|
end
|
19
19
|
|
20
|
-
it "converts lower camelcase to underscore params" do
|
20
|
+
it "converts lower camelcase to underscore params" do
|
21
21
|
expect(subject).to have_key("keys")
|
22
22
|
expect(subject["keys"]).to include("user_name")
|
23
23
|
expect(subject["keys"]).to include("bar")
|
@@ -26,22 +26,22 @@ describe "camel caser middleware", type: :rack do
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
context "
|
30
|
-
before do
|
29
|
+
context "default behavior without manual configuration" do
|
30
|
+
before do
|
31
31
|
post '/', json
|
32
32
|
end
|
33
33
|
|
34
34
|
subject do
|
35
|
-
|
35
|
+
JSON.parse(last_response.body)
|
36
36
|
end
|
37
37
|
|
38
|
-
|
39
|
-
it "
|
38
|
+
|
39
|
+
it "converts incoming camelCase arguments to snake_case" do
|
40
40
|
expect(subject).to have_key("keys")
|
41
|
-
expect(subject["keys"]).to include("
|
41
|
+
expect(subject["keys"]).to include("user_name")
|
42
42
|
end
|
43
43
|
|
44
|
-
it 'converted the snake case fake key to camelCase' do
|
44
|
+
it 'converted the snake case fake key to camelCase for the response' do
|
45
45
|
expect(subject['fake_key']).to_not be_present
|
46
46
|
expect(subject['fakeKey']).to eq false
|
47
47
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'the reactions when encountering error status', type: :rack do
|
4
|
+
context 'when encountering a server error' do
|
5
|
+
let(:json) { { error_code: 507 } }
|
6
|
+
|
7
|
+
before do
|
8
|
+
json_string = JSON.generate(json)
|
9
|
+
post '/error', json_string, {}
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'delegates the error response without failing' do
|
13
|
+
expect(last_response.status).to eq json[:error_code]
|
14
|
+
expect(last_response.body).to be_present
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -9,7 +9,7 @@ describe "camel caser middleware for Rails", type: :rails do
|
|
9
9
|
"DE" => 'german'
|
10
10
|
}
|
11
11
|
end
|
12
|
-
let(:json) {
|
12
|
+
let(:json) { JSON.generate(json_object) }
|
13
13
|
|
14
14
|
context "camel caser middleware for Rails with accept header " do
|
15
15
|
|
@@ -33,7 +33,7 @@ describe "camel caser middleware for Rails", type: :rails do
|
|
33
33
|
'CONTENT-TYPE' => 'application/json',
|
34
34
|
'ACCEPT' => 'text/html' }
|
35
35
|
|
36
|
-
last_json =
|
36
|
+
last_json = JSON.parse(last_response.body)
|
37
37
|
expect(last_json['keys']).to include('userName')
|
38
38
|
expect(last_json['keys']).to include('bar')
|
39
39
|
expect(last_json['keys']).to include('DE')
|
@@ -46,7 +46,7 @@ describe "camel caser middleware for Rails", type: :rails do
|
|
46
46
|
'CONTENT-TYPE' => 'application/json',
|
47
47
|
'ACCEPT' => 'foo/bar, gate/protect' }
|
48
48
|
|
49
|
-
last_json =
|
49
|
+
last_json = JSON.parse(last_response.body)
|
50
50
|
expect(last_json['keys']).to include('user_name')
|
51
51
|
expect(last_json['keys']).to include('de')
|
52
52
|
end
|
@@ -10,7 +10,7 @@ describe "camel caser middleware for Rails", type: :rails do
|
|
10
10
|
"DE" => 'german',
|
11
11
|
}
|
12
12
|
end
|
13
|
-
let(:json) {
|
13
|
+
let(:json) { JSON.generate(json_object) }
|
14
14
|
|
15
15
|
context "accept header is given" do
|
16
16
|
|
@@ -21,7 +21,7 @@ describe "camel caser middleware for Rails", type: :rails do
|
|
21
21
|
'CONTENT-TYPE' => 'application/json' }
|
22
22
|
end
|
23
23
|
|
24
|
-
subject {
|
24
|
+
subject { JSON.parse(last_response.body) }
|
25
25
|
|
26
26
|
it "converts lower camelcase to underscore params" do
|
27
27
|
expect(last_response).to be_successful
|
@@ -40,7 +40,7 @@ describe "camel caser middleware for Rails", type: :rails do
|
|
40
40
|
'response-json-format' => 'underscore' }
|
41
41
|
end
|
42
42
|
|
43
|
-
subject {
|
43
|
+
subject { JSON.parse(last_response.body) }
|
44
44
|
|
45
45
|
it 'should not touch the input keys and the response' do
|
46
46
|
expect(subject).to have_key('camelCase')
|
@@ -161,7 +161,7 @@ describe "camel caser middleware for Rails", type: :rails do
|
|
161
161
|
'CONTENT-TYPE' => 'application/json'
|
162
162
|
}
|
163
163
|
end
|
164
|
-
subject {
|
164
|
+
subject { JSON.parse(last_response.body) }
|
165
165
|
|
166
166
|
it 'should return an array as root element' do
|
167
167
|
expect(subject).to_not have_key("user_options")
|
@@ -180,18 +180,19 @@ describe "camel caser middleware for Rails", type: :rails do
|
|
180
180
|
end
|
181
181
|
|
182
182
|
subject do
|
183
|
-
|
183
|
+
JSON.parse(last_response.body)
|
184
184
|
end
|
185
185
|
|
186
186
|
|
187
|
-
it "
|
187
|
+
it "converts incoming request parameters to snake_case" do
|
188
188
|
expect(subject).to have_key("keys")
|
189
|
-
expect(subject["keys"]).to include("
|
189
|
+
expect(subject["keys"]).to include("user_name")
|
190
190
|
end
|
191
191
|
|
192
|
-
|
192
|
+
# not touching UPPERCASE params only works for camelizing strategies
|
193
|
+
it "converts UPPERCASE params when using underscore strategy" do
|
193
194
|
expect(subject).to have_key("keys")
|
194
|
-
expect(subject["keys"]).to include("
|
195
|
+
expect(subject["keys"]).to include("de")
|
195
196
|
end
|
196
197
|
|
197
198
|
end
|
@@ -204,7 +205,7 @@ describe "camel caser middleware for Rails", type: :rails do
|
|
204
205
|
end
|
205
206
|
|
206
207
|
subject do
|
207
|
-
|
208
|
+
JSON.parse(last_response.body)
|
208
209
|
end
|
209
210
|
|
210
211
|
it 'underscores the response' do
|
@@ -220,7 +221,7 @@ describe "camel caser middleware for Rails", type: :rails do
|
|
220
221
|
'CONTENT-TYPE' => 'application/json; charset=utf-8'
|
221
222
|
}
|
222
223
|
end
|
223
|
-
subject {
|
224
|
+
subject { JSON.parse(last_response.body) }
|
224
225
|
|
225
226
|
it 'should return an array as root element' do
|
226
227
|
expect(subject.class).to eq Array
|
@@ -230,7 +231,7 @@ describe "camel caser middleware for Rails", type: :rails do
|
|
230
231
|
|
231
232
|
end
|
232
233
|
|
233
|
-
|
234
|
+
describe 'the reaction on error responses' do
|
234
235
|
require 'action_controller/metal/exceptions'
|
235
236
|
it 'lets Rails do its RoutingError when the url is not found' do
|
236
237
|
expect do
|
@@ -239,9 +240,18 @@ describe "camel caser middleware for Rails", type: :rails do
|
|
239
240
|
end
|
240
241
|
|
241
242
|
it 'does not touch the response if a server error gets triggered' do
|
242
|
-
expect
|
243
|
+
expect do
|
243
244
|
get '/error', {}, { 'CONTENT-TYPE' => 'application/json' }
|
244
|
-
|
245
|
+
end.to raise_error ZeroDivisionError
|
246
|
+
end
|
247
|
+
|
248
|
+
it 'does not fail on 507 error' do
|
249
|
+
expect do
|
250
|
+
get '/error-507', {}, 'CONTENT-TYPE' => 'appliation/json',
|
251
|
+
'Accept' => 'application/json'
|
252
|
+
end.to_not raise_error
|
253
|
+
expect(last_response.status).to eq 507
|
254
|
+
expect(JSON.parse(last_response.body)).to eq({'error_code' => 507})
|
245
255
|
end
|
246
256
|
end
|
247
257
|
|
@@ -250,7 +260,7 @@ describe "camel caser middleware for Rails", type: :rails do
|
|
250
260
|
get '/welcome', json_object, { 'CONTENT_TYPE' => 'text/html',
|
251
261
|
'request-json-format' => 'underscore' }
|
252
262
|
|
253
|
-
last_json =
|
263
|
+
last_json = JSON.parse(last_response.body)
|
254
264
|
expect(last_json).to have_key 'fakeKey'
|
255
265
|
expect(last_json).to have_key 'keys'
|
256
266
|
end
|
@@ -264,7 +274,7 @@ describe "camel caser middleware for Rails", type: :rails do
|
|
264
274
|
'response-json-format' => 'underscore',
|
265
275
|
'CONTENT-TYPE' => '' }
|
266
276
|
|
267
|
-
last_json =
|
277
|
+
last_json = JSON.parse(last_response.body)
|
268
278
|
expect(last_json['keys']).to include('userName')
|
269
279
|
expect(last_json['keys']).to include('DE')
|
270
280
|
end
|
@@ -278,15 +288,16 @@ describe "camel caser middleware for Rails", type: :rails do
|
|
278
288
|
'response-json-format' => 'underscore',
|
279
289
|
'CONTENT_TYPE' => ''}
|
280
290
|
|
281
|
-
last_json =
|
291
|
+
last_json = JSON.parse(last_response.body)
|
282
292
|
expect(last_json['keys']).to include('user_name')
|
283
293
|
expect(last_json['keys']).to include('bar')
|
284
294
|
# at the moment the "let uppercase as it is"-option only works for
|
285
295
|
# camelCase. This test implies that.
|
286
296
|
expect(last_json['keys']).to include('de')
|
287
297
|
end
|
288
|
-
|
298
|
+
|
289
299
|
it 'processes everything if content-types configured contains nil and no content-type is sent' do
|
300
|
+
skip("Test is the same as above? Removal of content_type will fail the test.")
|
290
301
|
Sparrow.configure do |config|
|
291
302
|
config.allowed_content_types = [nil]
|
292
303
|
end
|
@@ -295,7 +306,7 @@ describe "camel caser middleware for Rails", type: :rails do
|
|
295
306
|
'response-json-format' => 'underscore',
|
296
307
|
'CONTENT_TYPE' => ''}
|
297
308
|
|
298
|
-
last_json =
|
309
|
+
last_json = JSON.parse(last_response.body)
|
299
310
|
expect(last_json['keys']).to include('user_name')
|
300
311
|
expect(last_json['keys']).to include('bar')
|
301
312
|
# at the moment the "let uppercase as it is"-option only works for
|