grape 1.6.2 → 1.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +54 -1
- data/CONTRIBUTING.md +30 -0
- data/README.md +146 -23
- data/UPGRADING.md +15 -0
- data/grape.gemspec +2 -2
- data/lib/grape/api/instance.rb +1 -1
- data/lib/grape/dry_types.rb +12 -0
- data/lib/grape/dsl/api.rb +0 -2
- data/lib/grape/dsl/callbacks.rb +0 -2
- data/lib/grape/dsl/configuration.rb +0 -2
- data/lib/grape/dsl/desc.rb +2 -16
- data/lib/grape/dsl/helpers.rb +0 -2
- data/lib/grape/dsl/inside_route.rb +34 -30
- data/lib/grape/dsl/middleware.rb +0 -2
- data/lib/grape/dsl/parameters.rb +10 -7
- data/lib/grape/dsl/request_response.rb +1 -3
- data/lib/grape/dsl/routing.rb +4 -2
- data/lib/grape/dsl/settings.rb +0 -2
- data/lib/grape/dsl/validations.rb +0 -15
- data/lib/grape/endpoint.rb +2 -2
- data/lib/grape/error_formatter/json.rb +7 -1
- data/lib/grape/exceptions/base.rb +3 -2
- data/lib/grape/exceptions/missing_group_type.rb +8 -1
- data/lib/grape/exceptions/too_many_multipart_files.rb +11 -0
- data/lib/grape/exceptions/unsupported_group_type.rb +8 -1
- data/lib/grape/exceptions/validation.rb +0 -4
- data/lib/grape/locale/en.yml +9 -8
- data/lib/grape/middleware/auth/dsl.rb +0 -1
- data/lib/grape/middleware/error.rb +2 -2
- data/lib/grape/middleware/stack.rb +1 -1
- data/lib/grape/request.rb +3 -1
- data/lib/grape/router/attribute_translator.rb +1 -1
- data/lib/grape/types/invalid_value.rb +8 -0
- data/lib/grape/util/cache.rb +1 -1
- data/lib/grape/util/json.rb +2 -0
- data/lib/grape/validations/attributes_doc.rb +58 -0
- data/lib/grape/validations/params_scope.rb +67 -41
- data/lib/grape/validations/types/array_coercer.rb +0 -2
- data/lib/grape/validations/types/dry_type_coercer.rb +3 -7
- data/lib/grape/validations/types/invalid_value.rb +0 -7
- data/lib/grape/validations/types/primitive_coercer.rb +14 -6
- data/lib/grape/validations/types/set_coercer.rb +0 -2
- data/lib/grape/validations/types.rb +98 -30
- data/lib/grape/validations/validators/{all_or_none.rb → all_or_none_of_validator.rb} +0 -2
- data/lib/grape/validations/validators/{at_least_one_of.rb → at_least_one_of_validator.rb} +0 -2
- data/lib/grape/validations/validators/base.rb +7 -0
- data/lib/grape/validations/validators/{exactly_one_of.rb → exactly_one_of_validator.rb} +0 -2
- data/lib/grape/validations/validators/{mutual_exclusion.rb → mutual_exclusion_validator.rb} +0 -2
- data/lib/grape/validations.rb +16 -12
- data/lib/grape/version.rb +1 -1
- data/lib/grape.rb +74 -28
- data/spec/grape/api/custom_validations_spec.rb +41 -2
- data/spec/grape/api/deeply_included_options_spec.rb +0 -2
- data/spec/grape/api/defines_boolean_in_params_spec.rb +0 -2
- data/spec/grape/api/documentation_spec.rb +59 -0
- data/spec/grape/api/inherited_helpers_spec.rb +0 -2
- data/spec/grape/api/instance_spec.rb +0 -1
- data/spec/grape/api/invalid_format_spec.rb +0 -2
- data/spec/grape/api/namespace_parameters_in_route_spec.rb +0 -2
- data/spec/grape/api/nested_helpers_spec.rb +0 -2
- data/spec/grape/api/optional_parameters_in_route_spec.rb +0 -2
- data/spec/grape/api/parameters_modification_spec.rb +0 -2
- data/spec/grape/api/patch_method_helpers_spec.rb +0 -2
- data/spec/grape/api/recognize_path_spec.rb +0 -2
- data/spec/grape/api/required_parameters_in_route_spec.rb +0 -2
- data/spec/grape/api/required_parameters_with_invalid_method_spec.rb +0 -2
- data/spec/grape/api/routes_with_requirements_spec.rb +0 -2
- data/spec/grape/api/shared_helpers_exactly_one_of_spec.rb +0 -2
- data/spec/grape/api/shared_helpers_spec.rb +0 -2
- data/spec/grape/api_remount_spec.rb +0 -1
- data/spec/grape/api_spec.rb +23 -25
- data/spec/grape/config_spec.rb +0 -2
- data/spec/grape/dsl/callbacks_spec.rb +0 -2
- data/spec/grape/dsl/desc_spec.rb +2 -2
- data/spec/grape/dsl/headers_spec.rb +2 -4
- data/spec/grape/dsl/helpers_spec.rb +0 -2
- data/spec/grape/dsl/inside_route_spec.rb +10 -12
- data/spec/grape/dsl/logger_spec.rb +0 -2
- data/spec/grape/dsl/middleware_spec.rb +0 -2
- data/spec/grape/dsl/parameters_spec.rb +0 -2
- data/spec/grape/dsl/request_response_spec.rb +6 -8
- data/spec/grape/dsl/routing_spec.rb +1 -3
- data/spec/grape/dsl/settings_spec.rb +0 -2
- data/spec/grape/dsl/validations_spec.rb +0 -17
- data/spec/grape/endpoint/declared_spec.rb +2 -4
- data/spec/grape/endpoint_spec.rb +29 -9
- data/spec/grape/entity_spec.rb +0 -1
- data/spec/grape/exceptions/base_spec.rb +16 -2
- data/spec/grape/exceptions/body_parse_errors_spec.rb +0 -2
- data/spec/grape/exceptions/invalid_accept_header_spec.rb +3 -2
- data/spec/grape/exceptions/invalid_formatter_spec.rb +0 -2
- data/spec/grape/exceptions/invalid_response_spec.rb +0 -2
- data/spec/grape/exceptions/invalid_versioner_option_spec.rb +1 -3
- data/spec/grape/exceptions/missing_group_type_spec.rb +21 -0
- data/spec/grape/exceptions/missing_mime_type_spec.rb +0 -2
- data/spec/grape/exceptions/missing_option_spec.rb +1 -3
- data/spec/grape/exceptions/unknown_options_spec.rb +0 -2
- data/spec/grape/exceptions/unknown_validator_spec.rb +0 -2
- data/spec/grape/exceptions/unsupported_group_type_spec.rb +23 -0
- data/spec/grape/exceptions/validation_errors_spec.rb +0 -1
- data/spec/grape/exceptions/validation_spec.rb +1 -3
- data/spec/grape/extensions/param_builders/hash_spec.rb +0 -2
- data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +0 -2
- data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +0 -2
- data/spec/grape/integration/global_namespace_function_spec.rb +0 -2
- data/spec/grape/integration/rack_sendfile_spec.rb +0 -2
- data/spec/grape/integration/rack_spec.rb +6 -7
- data/spec/grape/loading_spec.rb +0 -2
- data/spec/grape/middleware/auth/base_spec.rb +0 -1
- data/spec/grape/middleware/auth/dsl_spec.rb +0 -2
- data/spec/grape/middleware/auth/strategies_spec.rb +0 -2
- data/spec/grape/middleware/base_spec.rb +7 -7
- data/spec/grape/middleware/error_spec.rb +6 -1
- data/spec/grape/middleware/exception_spec.rb +0 -2
- data/spec/grape/middleware/formatter_spec.rb +6 -8
- data/spec/grape/middleware/globals_spec.rb +0 -2
- data/spec/grape/middleware/stack_spec.rb +0 -2
- data/spec/grape/middleware/versioner/accept_version_header_spec.rb +0 -2
- data/spec/grape/middleware/versioner/header_spec.rb +18 -4
- data/spec/grape/middleware/versioner/param_spec.rb +0 -2
- data/spec/grape/middleware/versioner/path_spec.rb +0 -2
- data/spec/grape/middleware/versioner_spec.rb +0 -2
- data/spec/grape/named_api_spec.rb +0 -2
- data/spec/grape/parser_spec.rb +0 -2
- data/spec/grape/path_spec.rb +0 -2
- data/spec/grape/presenters/presenter_spec.rb +0 -2
- data/spec/grape/request_spec.rb +0 -2
- data/spec/grape/util/inheritable_setting_spec.rb +0 -1
- data/spec/grape/util/inheritable_values_spec.rb +0 -1
- data/spec/grape/util/reverse_stackable_values_spec.rb +0 -1
- data/spec/grape/util/stackable_values_spec.rb +0 -1
- data/spec/grape/util/strict_hash_configuration_spec.rb +0 -1
- data/spec/grape/validations/attributes_doc_spec.rb +153 -0
- data/spec/grape/validations/instance_behaivour_spec.rb +0 -2
- data/spec/grape/validations/multiple_attributes_iterator_spec.rb +0 -2
- data/spec/grape/validations/params_scope_spec.rb +315 -86
- data/spec/grape/validations/single_attribute_iterator_spec.rb +0 -2
- data/spec/grape/validations/types/array_coercer_spec.rb +0 -2
- data/spec/grape/validations/types/primitive_coercer_spec.rb +20 -5
- data/spec/grape/validations/types/set_coercer_spec.rb +0 -2
- data/spec/grape/validations/types_spec.rb +28 -2
- data/spec/grape/validations/validators/all_or_none_spec.rb +0 -2
- data/spec/grape/validations/validators/allow_blank_spec.rb +0 -2
- data/spec/grape/validations/validators/at_least_one_of_spec.rb +0 -2
- data/spec/grape/validations/validators/coerce_spec.rb +0 -2
- data/spec/grape/validations/validators/default_spec.rb +0 -2
- data/spec/grape/validations/validators/exactly_one_of_spec.rb +0 -2
- data/spec/grape/validations/validators/except_values_spec.rb +0 -2
- data/spec/grape/validations/validators/mutual_exclusion_spec.rb +0 -2
- data/spec/grape/validations/validators/presence_spec.rb +0 -2
- data/spec/grape/validations/validators/regexp_spec.rb +0 -2
- data/spec/grape/validations/validators/same_as_spec.rb +0 -2
- data/spec/grape/validations/validators/values_spec.rb +19 -2
- data/spec/grape/validations_spec.rb +78 -27
- data/spec/integration/multi_json/json_spec.rb +0 -2
- data/spec/integration/multi_xml/xml_spec.rb +0 -2
- data/spec/spec_helper.rb +9 -4
- metadata +134 -122
- data/spec/grape/dsl/configuration_spec.rb +0 -16
- data/spec/grape/validations/attributes_iterator_spec.rb +0 -6
- data/spec/support/eager_load.rb +0 -19
- /data/lib/grape/validations/validators/{allow_blank.rb → allow_blank_validator.rb} +0 -0
- /data/lib/grape/validations/validators/{as.rb → as_validator.rb} +0 -0
- /data/lib/grape/validations/validators/{coerce.rb → coerce_validator.rb} +0 -0
- /data/lib/grape/validations/validators/{default.rb → default_validator.rb} +0 -0
- /data/lib/grape/validations/validators/{except_values.rb → except_values_validator.rb} +0 -0
- /data/lib/grape/validations/validators/{presence.rb → presence_validator.rb} +0 -0
- /data/lib/grape/validations/validators/{regexp.rb → regexp_validator.rb} +0 -0
- /data/lib/grape/validations/validators/{same_as.rb → same_as_validator.rb} +0 -0
- /data/lib/grape/validations/validators/{values.rb → values_validator.rb} +0 -0
@@ -1,8 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
describe Grape::Exceptions::Base do
|
4
|
+
describe '#to_s' do
|
5
|
+
subject { described_class.new(message: message).to_s }
|
6
|
+
|
7
|
+
let(:message) { 'a_message' }
|
8
|
+
|
9
|
+
it { is_expected.to eq(message) }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#message' do
|
13
|
+
subject { described_class.new(message: message).message }
|
14
|
+
|
15
|
+
let(:message) { 'a_message' }
|
16
|
+
|
17
|
+
it { is_expected.to eq(message) }
|
18
|
+
end
|
19
|
+
|
6
20
|
describe '#compose_message' do
|
7
21
|
subject { described_class.new.send(:compose_message, key, **attributes) }
|
8
22
|
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
describe Grape::Exceptions::InvalidAcceptHeader do
|
6
4
|
shared_examples_for 'a valid request' do
|
7
5
|
it 'does return with status 200' do
|
@@ -12,11 +10,13 @@ describe Grape::Exceptions::InvalidAcceptHeader do
|
|
12
10
|
expect(last_response.body).to eq('beer received')
|
13
11
|
end
|
14
12
|
end
|
13
|
+
|
15
14
|
shared_examples_for 'a cascaded request' do
|
16
15
|
it 'does not find a matching route' do
|
17
16
|
expect(last_response.status).to eq 404
|
18
17
|
end
|
19
18
|
end
|
19
|
+
|
20
20
|
shared_examples_for 'a not-cascaded request' do
|
21
21
|
it 'does not include the X-Cascade=pass header' do
|
22
22
|
expect(last_response.headers['X-Cascade']).to be_nil
|
@@ -26,6 +26,7 @@ describe Grape::Exceptions::InvalidAcceptHeader do
|
|
26
26
|
expect(last_response.status).to eq 406
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
29
30
|
shared_examples_for 'a rescued request' do
|
30
31
|
it 'does not include the X-Cascade=pass header' do
|
31
32
|
expect(last_response.headers['X-Cascade']).to be_nil
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
describe Grape::Exceptions::InvalidVersionerOption do
|
6
4
|
describe '#message' do
|
7
5
|
let(:error) do
|
@@ -10,7 +8,7 @@ describe Grape::Exceptions::InvalidVersionerOption do
|
|
10
8
|
|
11
9
|
it 'contains the problem in the message' do
|
12
10
|
expect(error.message).to include(
|
13
|
-
'
|
11
|
+
'unknown :using for versioner: headers'
|
14
12
|
)
|
15
13
|
end
|
16
14
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Grape::Exceptions::MissingGroupType do
|
4
|
+
describe '#message' do
|
5
|
+
subject { described_class.new.message }
|
6
|
+
|
7
|
+
it { is_expected.to include 'group type is required' }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'deprecated Grape::Exceptions::MissingGroupTypeError' do
|
11
|
+
subject { Grape::Exceptions::MissingGroupTypeError.new }
|
12
|
+
|
13
|
+
it 'puts a deprecation warning' do
|
14
|
+
expect(Warning).to receive(:warn) do |message|
|
15
|
+
expect(message).to include('`Grape::Exceptions::MissingGroupTypeError` is deprecated')
|
16
|
+
end
|
17
|
+
|
18
|
+
subject
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
describe Grape::Exceptions::MissingOption do
|
6
4
|
describe '#message' do
|
7
5
|
let(:error) do
|
@@ -10,7 +8,7 @@ describe Grape::Exceptions::MissingOption do
|
|
10
8
|
|
11
9
|
it 'contains the problem in the message' do
|
12
10
|
expect(error.message).to include(
|
13
|
-
'
|
11
|
+
'you must specify :path options'
|
14
12
|
)
|
15
13
|
end
|
16
14
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe Grape::Exceptions::UnsupportedGroupType do
|
4
|
+
subject { described_class.new }
|
5
|
+
|
6
|
+
describe '#message' do
|
7
|
+
subject { described_class.new.message }
|
8
|
+
|
9
|
+
it { is_expected.to include 'group type must be Array, Hash, JSON or Array[JSON]' }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe 'deprecated Grape::Exceptions::UnsupportedGroupTypeError' do
|
13
|
+
subject { Grape::Exceptions::UnsupportedGroupTypeError.new }
|
14
|
+
|
15
|
+
it 'puts a deprecation warning' do
|
16
|
+
expect(Warning).to receive(:warn) do |message|
|
17
|
+
expect(message).to include('`Grape::Exceptions::UnsupportedGroupTypeError` is deprecated')
|
18
|
+
end
|
19
|
+
|
20
|
+
subject
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
describe Grape::Exceptions::Validation do
|
6
4
|
it 'fails when params are missing' do
|
7
5
|
expect { described_class.new(message: 'presence') }.to raise_error(ArgumentError, /missing keyword:.+?params/)
|
@@ -15,7 +13,7 @@ describe Grape::Exceptions::Validation do
|
|
15
13
|
|
16
14
|
context 'when message is a String' do
|
17
15
|
it 'does not store the message_key' do
|
18
|
-
expect(described_class.new(params: ['id'], message: 'presence').message_key).to
|
16
|
+
expect(described_class.new(params: ['id'], message: 'presence').message_key).to be_nil
|
19
17
|
end
|
20
18
|
end
|
21
19
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
describe Rack do
|
6
4
|
it 'correctly populates params from a Tempfile' do
|
7
5
|
input = Tempfile.new 'rubbish'
|
@@ -29,19 +27,20 @@ describe Rack do
|
|
29
27
|
end
|
30
28
|
|
31
29
|
context 'when the app is mounted' do
|
32
|
-
|
33
|
-
|
30
|
+
let(:ping_mount) do
|
31
|
+
Class.new(Grape::API) do
|
34
32
|
get 'ping'
|
35
33
|
end
|
36
34
|
end
|
37
35
|
|
38
|
-
let
|
39
|
-
app_to_mount =
|
40
|
-
Class.new(Grape::API) do
|
36
|
+
let(:app) do
|
37
|
+
app_to_mount = ping_mount
|
38
|
+
app = Class.new(Grape::API) do
|
41
39
|
namespace 'namespace' do
|
42
40
|
mount app_to_mount
|
43
41
|
end
|
44
42
|
end
|
43
|
+
Rack::Builder.new(app)
|
45
44
|
end
|
46
45
|
|
47
46
|
it 'finds the app on the namespace' do
|
data/spec/grape/loading_spec.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
describe Grape::Middleware::Base do
|
6
4
|
subject { described_class.new(blank_app) }
|
7
5
|
|
@@ -72,18 +70,18 @@ describe Grape::Middleware::Base do
|
|
72
70
|
|
73
71
|
it 'is able to access the response' do
|
74
72
|
subject.call({})
|
75
|
-
expect(subject.response).to
|
73
|
+
expect(subject.response).to be_a(Rack::Response)
|
76
74
|
end
|
77
75
|
|
78
76
|
describe '#response' do
|
79
77
|
subject do
|
80
|
-
puts described_class
|
81
78
|
described_class.new(response)
|
82
79
|
end
|
83
80
|
|
84
81
|
before { subject.call({}) }
|
85
82
|
|
86
83
|
context 'when Array' do
|
84
|
+
let(:rack_response) { Rack::Response.new('test', 204, abc: 1) }
|
87
85
|
let(:response) { ->(_) { [204, { abc: 1 }, 'test'] } }
|
88
86
|
|
89
87
|
it 'status' do
|
@@ -99,12 +97,14 @@ describe Grape::Middleware::Base do
|
|
99
97
|
end
|
100
98
|
|
101
99
|
it 'returns the memoized Rack::Response instance' do
|
102
|
-
|
100
|
+
allow(Rack::Response).to receive(:new).and_return(rack_response)
|
101
|
+
expect(subject.response).to eq(rack_response)
|
103
102
|
end
|
104
103
|
end
|
105
104
|
|
106
105
|
context 'when Rack::Response' do
|
107
|
-
let(:
|
106
|
+
let(:rack_response) { Rack::Response.new('test', 204, abc: 1) }
|
107
|
+
let(:response) { ->(_) { rack_response } }
|
108
108
|
|
109
109
|
it 'status' do
|
110
110
|
expect(subject.response.status).to eq(204)
|
@@ -119,7 +119,7 @@ describe Grape::Middleware::Base do
|
|
119
119
|
end
|
120
120
|
|
121
121
|
it 'returns the memoized Rack::Response instance' do
|
122
|
-
expect(subject.response).to
|
122
|
+
expect(subject.response).to eq(rack_response)
|
123
123
|
end
|
124
124
|
end
|
125
125
|
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
3
|
require 'grape-entity'
|
5
4
|
|
6
5
|
describe Grape::Middleware::Error do
|
@@ -42,6 +41,12 @@ describe Grape::Middleware::Error do
|
|
42
41
|
expect(last_response.status).to eq(410)
|
43
42
|
end
|
44
43
|
|
44
|
+
it 'sets the status code based on the rack util status code symbol' do
|
45
|
+
ErrorSpec::ErrApp.error = { status: :gone }
|
46
|
+
get '/'
|
47
|
+
expect(last_response.status).to eq(410)
|
48
|
+
end
|
49
|
+
|
45
50
|
it 'sets the error message appropriately' do
|
46
51
|
ErrorSpec::ErrApp.error = { message: 'Awesome stuff.' }
|
47
52
|
get '/'
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
describe Grape::Middleware::Formatter do
|
6
4
|
subject { described_class.new(app) }
|
7
5
|
|
@@ -15,7 +13,7 @@ describe Grape::Middleware::Formatter do
|
|
15
13
|
|
16
14
|
it 'looks at the bodies for possibly serializable data' do
|
17
15
|
_, _, bodies = *subject.call('PATH_INFO' => '/somewhere', 'HTTP_ACCEPT' => 'application/json')
|
18
|
-
bodies.each { |b| expect(b).to eq(::Grape::Json.dump(body)) }
|
16
|
+
bodies.each { |b| expect(b).to eq(::Grape::Json.dump(body)) } # rubocop:disable RSpec/IteratedExpectation
|
19
17
|
end
|
20
18
|
|
21
19
|
context 'default format' do
|
@@ -28,7 +26,7 @@ describe Grape::Middleware::Formatter do
|
|
28
26
|
end
|
29
27
|
end
|
30
28
|
|
31
|
-
subject.call('PATH_INFO' => '/somewhere', 'HTTP_ACCEPT' => 'application/json').to_a.last.each { |b| expect(b).to eq('"bar"') }
|
29
|
+
subject.call('PATH_INFO' => '/somewhere', 'HTTP_ACCEPT' => 'application/json').to_a.last.each { |b| expect(b).to eq('"bar"') } # rubocop:disable RSpec/IteratedExpectation
|
32
30
|
end
|
33
31
|
end
|
34
32
|
|
@@ -42,7 +40,7 @@ describe Grape::Middleware::Formatter do
|
|
42
40
|
end
|
43
41
|
end
|
44
42
|
|
45
|
-
subject.call('PATH_INFO' => '/somewhere', 'HTTP_ACCEPT' => 'application/vnd.api+json').to_a.last.each { |b| expect(b).to eq('{"foos":[{"bar":"baz"}] }') }
|
43
|
+
subject.call('PATH_INFO' => '/somewhere', 'HTTP_ACCEPT' => 'application/vnd.api+json').to_a.last.each { |b| expect(b).to eq('{"foos":[{"bar":"baz"}] }') } # rubocop:disable RSpec/IteratedExpectation
|
46
44
|
end
|
47
45
|
end
|
48
46
|
|
@@ -55,8 +53,7 @@ describe Grape::Middleware::Formatter do
|
|
55
53
|
'<bar/>'
|
56
54
|
end
|
57
55
|
end
|
58
|
-
|
59
|
-
subject.call('PATH_INFO' => '/somewhere.xml', 'HTTP_ACCEPT' => 'application/json').to_a.last.each { |b| expect(b).to eq('<bar/>') }
|
56
|
+
subject.call('PATH_INFO' => '/somewhere.xml', 'HTTP_ACCEPT' => 'application/json').to_a.last.each { |b| expect(b).to eq('<bar/>') } # rubocop:disable RSpec/IteratedExpectation
|
60
57
|
end
|
61
58
|
end
|
62
59
|
end
|
@@ -245,6 +242,7 @@ describe Grape::Middleware::Formatter do
|
|
245
242
|
end
|
246
243
|
|
247
244
|
context 'input' do
|
245
|
+
content_types = ['application/json', 'application/json; charset=utf-8'].freeze
|
248
246
|
%w[POST PATCH PUT DELETE].each do |method|
|
249
247
|
context 'when body is not nil or empty' do
|
250
248
|
context 'when Content-Type is supported' do
|
@@ -322,7 +320,7 @@ describe Grape::Middleware::Formatter do
|
|
322
320
|
end
|
323
321
|
end
|
324
322
|
|
325
|
-
|
323
|
+
content_types.each do |content_type|
|
326
324
|
context content_type do
|
327
325
|
it "parses the body from #{method} and copies values into rack.request.form_hash" do
|
328
326
|
io = StringIO.new('{"is_boolean":true,"string":"thing"}')
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
3
|
describe Grape::Middleware::Versioner::Header do
|
6
4
|
subject { described_class.new(app, **(@options || {})) }
|
7
5
|
|
@@ -48,7 +46,7 @@ describe Grape::Middleware::Versioner::Header do
|
|
48
46
|
|
49
47
|
it 'is nil if not provided' do
|
50
48
|
status, _, env = subject.call('HTTP_ACCEPT' => 'application/vnd.vendor')
|
51
|
-
expect(env['api.format']).to
|
49
|
+
expect(env['api.format']).to be_nil
|
52
50
|
expect(status).to eq(200)
|
53
51
|
end
|
54
52
|
|
@@ -66,7 +64,7 @@ describe Grape::Middleware::Versioner::Header do
|
|
66
64
|
|
67
65
|
it 'is nil if not provided' do
|
68
66
|
status, _, env = subject.call('HTTP_ACCEPT' => 'application/vnd.vendor-v1')
|
69
|
-
expect(env['api.format']).to
|
67
|
+
expect(env['api.format']).to be_nil
|
70
68
|
expect(status).to eq(200)
|
71
69
|
end
|
72
70
|
end
|
@@ -328,4 +326,20 @@ describe Grape::Middleware::Versioner::Header do
|
|
328
326
|
end
|
329
327
|
end
|
330
328
|
end
|
329
|
+
|
330
|
+
context 'with missing vendor option' do
|
331
|
+
subject do
|
332
|
+
Class.new(Grape::API) do
|
333
|
+
version 'v1', using: :header
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
def app
|
338
|
+
subject
|
339
|
+
end
|
340
|
+
|
341
|
+
it 'fails' do
|
342
|
+
expect { versioned_get '/', 'v1', using: :header }.to raise_error Grape::Exceptions::MissingVendorOption
|
343
|
+
end
|
344
|
+
end
|
331
345
|
end
|
data/spec/grape/parser_spec.rb
CHANGED
data/spec/grape/path_spec.rb
CHANGED
data/spec/grape/request_spec.rb
CHANGED