grape 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of grape might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -66
- data/.rubocop_todo.yml +78 -17
- data/.travis.yml +7 -3
- data/Appraisals +7 -0
- data/CHANGELOG.md +24 -0
- data/CONTRIBUTING.md +7 -0
- data/Gemfile +1 -7
- data/Guardfile +1 -1
- data/README.md +560 -94
- data/RELEASING.md +1 -1
- data/Rakefile +10 -11
- data/UPGRADING.md +211 -3
- data/gemfiles/rails_3.gemfile +14 -0
- data/gemfiles/rails_4.gemfile +14 -0
- data/grape.gemspec +10 -9
- data/lib/backports/active_support/deep_dup.rb +49 -0
- data/lib/backports/active_support/duplicable.rb +88 -0
- data/lib/grape.rb +29 -2
- data/lib/grape/api.rb +59 -65
- data/lib/grape/dsl/api.rb +19 -0
- data/lib/grape/dsl/callbacks.rb +6 -4
- data/lib/grape/dsl/configuration.rb +49 -5
- data/lib/grape/dsl/helpers.rb +7 -8
- data/lib/grape/dsl/inside_route.rb +22 -10
- data/lib/grape/dsl/middleware.rb +5 -5
- data/lib/grape/dsl/parameters.rb +6 -2
- data/lib/grape/dsl/request_response.rb +23 -20
- data/lib/grape/dsl/routing.rb +52 -49
- data/lib/grape/dsl/settings.rb +110 -0
- data/lib/grape/dsl/validations.rb +14 -6
- data/lib/grape/endpoint.rb +104 -88
- data/lib/grape/exceptions/base.rb +2 -2
- data/lib/grape/exceptions/incompatible_option_values.rb +1 -1
- data/lib/grape/exceptions/invalid_formatter.rb +1 -1
- data/lib/grape/exceptions/invalid_versioner_option.rb +1 -1
- data/lib/grape/exceptions/invalid_with_option_for_represent.rb +1 -1
- data/lib/grape/exceptions/missing_mime_type.rb +1 -1
- data/lib/grape/exceptions/missing_option.rb +1 -1
- data/lib/grape/exceptions/missing_vendor_option.rb +1 -1
- data/lib/grape/exceptions/unknown_options.rb +1 -1
- data/lib/grape/exceptions/unknown_validator.rb +1 -1
- data/lib/grape/exceptions/validation.rb +1 -1
- data/lib/grape/exceptions/validation_errors.rb +2 -2
- data/lib/grape/formatter/serializable_hash.rb +1 -1
- data/lib/grape/formatter/xml.rb +1 -1
- data/lib/grape/locale/en.yml +2 -0
- data/lib/grape/middleware/auth/dsl.rb +26 -21
- data/lib/grape/middleware/auth/strategies.rb +1 -1
- data/lib/grape/middleware/auth/strategy_info.rb +0 -2
- data/lib/grape/middleware/base.rb +2 -2
- data/lib/grape/middleware/error.rb +1 -1
- data/lib/grape/middleware/formatter.rb +5 -5
- data/lib/grape/middleware/versioner.rb +1 -1
- data/lib/grape/middleware/versioner/header.rb +3 -3
- data/lib/grape/middleware/versioner/param.rb +2 -2
- data/lib/grape/middleware/versioner/path.rb +1 -1
- data/lib/grape/namespace.rb +1 -1
- data/lib/grape/path.rb +9 -3
- data/lib/grape/util/content_types.rb +16 -8
- data/lib/grape/util/inheritable_setting.rb +74 -0
- data/lib/grape/util/inheritable_values.rb +51 -0
- data/lib/grape/util/stackable_values.rb +52 -0
- data/lib/grape/util/strict_hash_configuration.rb +106 -0
- data/lib/grape/validations.rb +0 -220
- data/lib/grape/validations/attributes_iterator.rb +21 -0
- data/lib/grape/validations/params_scope.rb +176 -0
- data/lib/grape/validations/validators/all_or_none.rb +20 -0
- data/lib/grape/validations/validators/allow_blank.rb +30 -0
- data/lib/grape/validations/validators/at_least_one_of.rb +20 -0
- data/lib/grape/validations/validators/base.rb +37 -0
- data/lib/grape/validations/{coerce.rb → validators/coerce.rb} +3 -3
- data/lib/grape/validations/{default.rb → validators/default.rb} +1 -1
- data/lib/grape/validations/validators/exactly_one_of.rb +20 -0
- data/lib/grape/validations/validators/multiple_params_base.rb +26 -0
- data/lib/grape/validations/validators/mutual_exclusion.rb +25 -0
- data/lib/grape/validations/{presence.rb → validators/presence.rb} +2 -2
- data/lib/grape/validations/validators/regexp.rb +12 -0
- data/lib/grape/validations/validators/values.rb +26 -0
- data/lib/grape/version.rb +1 -1
- data/spec/grape/api_spec.rb +522 -343
- data/spec/grape/dsl/callbacks_spec.rb +4 -4
- data/spec/grape/dsl/configuration_spec.rb +48 -9
- data/spec/grape/dsl/helpers_spec.rb +6 -13
- data/spec/grape/dsl/inside_route_spec.rb +43 -4
- data/spec/grape/dsl/middleware_spec.rb +1 -10
- data/spec/grape/dsl/parameters_spec.rb +8 -1
- data/spec/grape/dsl/request_response_spec.rb +16 -22
- data/spec/grape/dsl/routing_spec.rb +21 -5
- data/spec/grape/dsl/settings_spec.rb +219 -0
- data/spec/grape/dsl/validations_spec.rb +8 -11
- data/spec/grape/endpoint_spec.rb +115 -86
- data/spec/grape/entity_spec.rb +33 -33
- data/spec/grape/exceptions/invalid_formatter_spec.rb +3 -5
- data/spec/grape/exceptions/invalid_versioner_option_spec.rb +4 -6
- data/spec/grape/exceptions/missing_mime_type_spec.rb +5 -6
- data/spec/grape/exceptions/missing_option_spec.rb +3 -5
- data/spec/grape/exceptions/unknown_options_spec.rb +3 -5
- data/spec/grape/exceptions/unknown_validator_spec.rb +3 -5
- data/spec/grape/exceptions/validation_errors_spec.rb +5 -5
- data/spec/grape/loading_spec.rb +44 -0
- data/spec/grape/middleware/auth/base_spec.rb +0 -4
- data/spec/grape/middleware/auth/dsl_spec.rb +2 -4
- data/spec/grape/middleware/auth/strategies_spec.rb +5 -6
- data/spec/grape/middleware/exception_spec.rb +8 -10
- data/spec/grape/middleware/formatter_spec.rb +13 -15
- data/spec/grape/middleware/versioner/accept_version_header_spec.rb +10 -10
- data/spec/grape/middleware/versioner/header_spec.rb +25 -25
- data/spec/grape/middleware/versioner/param_spec.rb +15 -17
- data/spec/grape/middleware/versioner/path_spec.rb +1 -2
- data/spec/grape/middleware/versioner_spec.rb +0 -1
- data/spec/grape/path_spec.rb +66 -45
- data/spec/grape/util/inheritable_setting_spec.rb +217 -0
- data/spec/grape/util/inheritable_values_spec.rb +63 -0
- data/spec/grape/util/stackable_values_spec.rb +115 -0
- data/spec/grape/util/strict_hash_configuration_spec.rb +38 -0
- data/spec/grape/validations/attributes_iterator_spec.rb +4 -0
- data/spec/grape/validations/params_scope_spec.rb +57 -0
- data/spec/grape/validations/validators/all_or_none_spec.rb +60 -0
- data/spec/grape/validations/validators/allow_blank_spec.rb +170 -0
- data/spec/grape/validations/{at_least_one_of_spec.rb → validators/at_least_one_of_spec.rb} +7 -3
- data/spec/grape/validations/{coerce_spec.rb → validators/coerce_spec.rb} +8 -11
- data/spec/grape/validations/{default_spec.rb → validators/default_spec.rb} +7 -9
- data/spec/grape/validations/{exactly_one_of_spec.rb → validators/exactly_one_of_spec.rb} +15 -11
- data/spec/grape/validations/{mutual_exclusion_spec.rb → validators/mutual_exclusion_spec.rb} +11 -9
- data/spec/grape/validations/{presence_spec.rb → validators/presence_spec.rb} +30 -30
- data/spec/grape/validations/{regexp_spec.rb → validators/regexp_spec.rb} +2 -4
- data/spec/grape/validations/{values_spec.rb → validators/values_spec.rb} +95 -23
- data/spec/grape/validations/{zh-CN.yml → validators/zh-CN.yml} +0 -0
- data/spec/grape/validations_spec.rb +335 -70
- data/spec/shared/versioning_examples.rb +7 -8
- data/spec/spec_helper.rb +2 -0
- data/spec/support/basic_auth_encode_helpers.rb +1 -1
- data/spec/support/content_type_helpers.rb +1 -1
- data/spec/support/versioned_helpers.rb +3 -3
- metadata +80 -33
- data/lib/grape/util/deep_merge.rb +0 -23
- data/lib/grape/util/hash_stack.rb +0 -120
- data/lib/grape/validations/at_least_one_of.rb +0 -25
- data/lib/grape/validations/exactly_one_of.rb +0 -26
- data/lib/grape/validations/mutual_exclusion.rb +0 -25
- data/lib/grape/validations/regexp.rb +0 -12
- data/lib/grape/validations/values.rb +0 -23
- data/spec/grape/util/hash_stack_spec.rb +0 -132
@@ -14,28 +14,28 @@ module Grape
|
|
14
14
|
|
15
15
|
describe '.before' do
|
16
16
|
it 'adds a block to "before"' do
|
17
|
-
expect(subject).to receive(:
|
17
|
+
expect(subject).to receive(:namespace_stackable).with(:befores, proc)
|
18
18
|
subject.before(&proc)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
22
|
describe '.before_validation' do
|
23
23
|
it 'adds a block to "before_validation"' do
|
24
|
-
expect(subject).to receive(:
|
24
|
+
expect(subject).to receive(:namespace_stackable).with(:before_validations, proc)
|
25
25
|
subject.before_validation(&proc)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
describe '.after_validation' do
|
30
30
|
it 'adds a block to "after_validation"' do
|
31
|
-
expect(subject).to receive(:
|
31
|
+
expect(subject).to receive(:namespace_stackable).with(:after_validations, proc)
|
32
32
|
subject.after_validation(&proc)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
describe '.after' do
|
37
37
|
it 'adds a block to "after"' do
|
38
|
-
expect(subject).to receive(:
|
38
|
+
expect(subject).to receive(:namespace_stackable).with(:afters, proc)
|
39
39
|
subject.after(&proc)
|
40
40
|
end
|
41
41
|
end
|
@@ -5,12 +5,6 @@ module Grape
|
|
5
5
|
module ConfigurationSpec
|
6
6
|
class Dummy
|
7
7
|
include Grape::DSL::Configuration
|
8
|
-
|
9
|
-
# rubocop:disable TrivialAccessors
|
10
|
-
def self.last_desc
|
11
|
-
@last_description
|
12
|
-
end
|
13
|
-
# rubocop:enable TrivialAccessors
|
14
8
|
end
|
15
9
|
end
|
16
10
|
describe Configuration do
|
@@ -22,16 +16,61 @@ module Grape
|
|
22
16
|
subject.logger logger
|
23
17
|
expect(subject.logger).to eq logger
|
24
18
|
end
|
19
|
+
|
20
|
+
it 'returns a logger' do
|
21
|
+
expect(subject.logger logger).to eq logger
|
22
|
+
end
|
25
23
|
end
|
26
24
|
|
27
25
|
describe '.desc' do
|
28
26
|
it 'sets a description' do
|
27
|
+
desc_text = 'The description'
|
29
28
|
options = { message: 'none' }
|
30
|
-
subject.desc options
|
31
|
-
expect(subject.
|
29
|
+
subject.desc desc_text, options
|
30
|
+
expect(subject.namespace_setting(:description)).to eq(options.merge(description: desc_text))
|
31
|
+
expect(subject.route_setting(:description)).to eq(options.merge(description: desc_text))
|
32
32
|
end
|
33
|
-
end
|
34
33
|
|
34
|
+
it 'can be set with a block' do
|
35
|
+
expected_options = {
|
36
|
+
description: 'The description',
|
37
|
+
detail: 'more details',
|
38
|
+
params: { first: :param },
|
39
|
+
entity: Object,
|
40
|
+
http_codes: [[401, 'Unauthorized', 'Entities::Error']],
|
41
|
+
named: 'My named route',
|
42
|
+
headers: [XAuthToken: {
|
43
|
+
description: 'Valdates your identity',
|
44
|
+
required: true
|
45
|
+
},
|
46
|
+
XOptionalHeader: {
|
47
|
+
description: 'Not really needed',
|
48
|
+
required: false
|
49
|
+
}
|
50
|
+
]
|
51
|
+
}
|
52
|
+
|
53
|
+
subject.desc 'The description' do
|
54
|
+
detail 'more details'
|
55
|
+
params(first: :param)
|
56
|
+
success Object
|
57
|
+
failure [[401, 'Unauthorized', 'Entities::Error']]
|
58
|
+
named 'My named route'
|
59
|
+
headers [XAuthToken: {
|
60
|
+
description: 'Valdates your identity',
|
61
|
+
required: true
|
62
|
+
},
|
63
|
+
XOptionalHeader: {
|
64
|
+
description: 'Not really needed',
|
65
|
+
required: false
|
66
|
+
}
|
67
|
+
]
|
68
|
+
end
|
69
|
+
|
70
|
+
expect(subject.namespace_setting(:description)).to eq(expected_options)
|
71
|
+
expect(subject.route_setting(:description)).to eq(expected_options)
|
72
|
+
end
|
73
|
+
end
|
35
74
|
end
|
36
75
|
end
|
37
76
|
end
|
@@ -6,17 +6,9 @@ module Grape
|
|
6
6
|
class Dummy
|
7
7
|
include Grape::DSL::Helpers
|
8
8
|
|
9
|
-
def self.settings
|
10
|
-
@settings ||= Grape::Util::HashStack.new
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.set(_, mod)
|
14
|
-
@mod = mod
|
15
|
-
end
|
16
|
-
|
17
9
|
# rubocop:disable TrivialAccessors
|
18
10
|
def self.mod
|
19
|
-
|
11
|
+
namespace_stackable(:helpers).first
|
20
12
|
end
|
21
13
|
# rubocop:enable TrivialAccessors
|
22
14
|
end
|
@@ -33,7 +25,8 @@ module Grape
|
|
33
25
|
|
34
26
|
describe '.helpers' do
|
35
27
|
it 'adds a module with the given block' do
|
36
|
-
expect(subject).to receive(:
|
28
|
+
expect(subject).to receive(:namespace_stackable).with(:helpers, kind_of(Grape::DSL::Helpers::BaseHelper)).and_call_original
|
29
|
+
expect(subject).to receive(:namespace_stackable).with(:helpers).and_call_original
|
37
30
|
subject.helpers(&proc)
|
38
31
|
|
39
32
|
expect(subject.mod.instance_methods).to include(:test)
|
@@ -42,11 +35,11 @@ module Grape
|
|
42
35
|
it 'uses provided modules' do
|
43
36
|
mod = Module.new
|
44
37
|
|
45
|
-
expect(subject).to receive(:
|
38
|
+
expect(subject).to receive(:namespace_stackable).with(:helpers, kind_of(Grape::DSL::Helpers::BaseHelper)).and_call_original
|
39
|
+
expect(subject).to receive(:namespace_stackable).with(:helpers).and_call_original
|
46
40
|
subject.helpers(mod, &proc)
|
47
41
|
|
48
|
-
expect(subject.mod).
|
49
|
-
expect(subject.mod).to include mod
|
42
|
+
expect(subject.mod).to eq mod
|
50
43
|
end
|
51
44
|
end
|
52
45
|
end
|
@@ -6,12 +6,12 @@ module Grape
|
|
6
6
|
class Dummy
|
7
7
|
include Grape::DSL::InsideRoute
|
8
8
|
|
9
|
-
attr_reader :env, :request, :
|
9
|
+
attr_reader :env, :request, :new_settings
|
10
10
|
|
11
11
|
def initialize
|
12
12
|
@env = {}
|
13
13
|
@header = {}
|
14
|
-
@
|
14
|
+
@new_settings = { namespace_inheritable: {}, namespace_stackable: {} }
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -46,7 +46,7 @@ module Grape
|
|
46
46
|
|
47
47
|
describe 'default_error_status' do
|
48
48
|
before do
|
49
|
-
subject.
|
49
|
+
subject.namespace_inheritable(:default_error_status, 500)
|
50
50
|
catch(:error) { subject.error! 'Unknown' }
|
51
51
|
end
|
52
52
|
it 'sets status to default_error_status' do
|
@@ -89,7 +89,7 @@ module Grape
|
|
89
89
|
end
|
90
90
|
|
91
91
|
describe '#status' do
|
92
|
-
|
92
|
+
%w(GET PUT DELETE OPTIONS).each do |method|
|
93
93
|
it 'defaults to 200 on GET' do
|
94
94
|
request = Grape::Request.new(Rack::MockRequest.env_for('/', method: method))
|
95
95
|
expect(subject).to receive(:request).and_return(request)
|
@@ -160,6 +160,17 @@ module Grape
|
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
163
|
+
describe 'false' do
|
164
|
+
before do
|
165
|
+
subject.body false
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'sets status to 204' do
|
169
|
+
expect(subject.body).to eq ''
|
170
|
+
expect(subject.status).to eq 204
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
163
174
|
it 'returns default' do
|
164
175
|
expect(subject.body).to be nil
|
165
176
|
end
|
@@ -208,6 +219,34 @@ module Grape
|
|
208
219
|
end
|
209
220
|
end
|
210
221
|
end
|
222
|
+
|
223
|
+
describe 'with' do
|
224
|
+
describe 'multiple entities' do
|
225
|
+
let(:entity_mock1) do
|
226
|
+
entity_mock1 = Object.new
|
227
|
+
allow(entity_mock1).to receive(:represent).and_return(dummy1: 'dummy1')
|
228
|
+
entity_mock1
|
229
|
+
end
|
230
|
+
|
231
|
+
let(:entity_mock2) do
|
232
|
+
entity_mock2 = Object.new
|
233
|
+
allow(entity_mock2).to receive(:represent).and_return(dummy2: 'dummy2')
|
234
|
+
entity_mock2
|
235
|
+
end
|
236
|
+
|
237
|
+
describe 'instance' do
|
238
|
+
before do
|
239
|
+
subject.present 'dummy1', with: entity_mock1
|
240
|
+
subject.present 'dummy2', with: entity_mock2
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'presents both dummy objects' do
|
244
|
+
expect(subject.body[:dummy1]).to eq 'dummy1'
|
245
|
+
expect(subject.body[:dummy2]).to eq 'dummy2'
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
211
250
|
end
|
212
251
|
|
213
252
|
describe '#declared' do
|
@@ -5,14 +5,6 @@ module Grape
|
|
5
5
|
module MiddlewareSpec
|
6
6
|
class Dummy
|
7
7
|
include Grape::DSL::Middleware
|
8
|
-
|
9
|
-
def self.settings
|
10
|
-
@settings ||= Grape::Util::HashStack.new
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.imbue(key, value)
|
14
|
-
settings.imbue(key, value)
|
15
|
-
end
|
16
8
|
end
|
17
9
|
end
|
18
10
|
describe Middleware do
|
@@ -21,11 +13,10 @@ module Grape
|
|
21
13
|
|
22
14
|
describe '.use' do
|
23
15
|
it 'adds a middleware' do
|
24
|
-
expect(subject).to receive(:
|
16
|
+
expect(subject).to receive(:namespace_stackable).with(:middleware, [:my_middleware, :arg1, proc])
|
25
17
|
|
26
18
|
subject.use :my_middleware, :arg1, &proc
|
27
19
|
end
|
28
|
-
|
29
20
|
end
|
30
21
|
|
31
22
|
describe '.middleware' do
|
@@ -95,6 +95,14 @@ module Grape
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
+
describe '#all_or_none_of' do
|
99
|
+
it 'adds an all or none of parameter validation' do
|
100
|
+
subject.all_or_none_of :media, :audio
|
101
|
+
|
102
|
+
expect(subject.valids).to eq([[:media, :audio], { all_or_none_of: true }])
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
98
106
|
xdescribe '#group' do
|
99
107
|
it 'does some thing'
|
100
108
|
end
|
@@ -102,7 +110,6 @@ module Grape
|
|
102
110
|
xdescribe '#params' do
|
103
111
|
it 'does some thing'
|
104
112
|
end
|
105
|
-
|
106
113
|
end
|
107
114
|
end
|
108
115
|
end
|
@@ -6,10 +6,6 @@ module Grape
|
|
6
6
|
class Dummy
|
7
7
|
include Grape::DSL::RequestResponse
|
8
8
|
|
9
|
-
def self.settings
|
10
|
-
@settings ||= Grape::Util::HashStack.new
|
11
|
-
end
|
12
|
-
|
13
9
|
def self.set(key, value)
|
14
10
|
settings[key.to_sym] = value
|
15
11
|
end
|
@@ -27,7 +23,7 @@ module Grape
|
|
27
23
|
|
28
24
|
describe '.default_format' do
|
29
25
|
it 'sets the default format' do
|
30
|
-
expect(subject).to receive(:
|
26
|
+
expect(subject).to receive(:namespace_inheritable).with(:default_format, :format)
|
31
27
|
subject.default_format :format
|
32
28
|
end
|
33
29
|
|
@@ -40,8 +36,8 @@ module Grape
|
|
40
36
|
|
41
37
|
describe '.format' do
|
42
38
|
it 'sets a new format' do
|
43
|
-
expect(subject).to receive(:
|
44
|
-
expect(subject).to receive(:
|
39
|
+
expect(subject).to receive(:namespace_inheritable).with(:format, format.to_sym)
|
40
|
+
expect(subject).to receive(:namespace_inheritable).with(:default_error_formatter, Grape::ErrorFormatter::Txt)
|
45
41
|
|
46
42
|
subject.format format
|
47
43
|
end
|
@@ -49,21 +45,21 @@ module Grape
|
|
49
45
|
|
50
46
|
describe '.formatter' do
|
51
47
|
it 'sets the formatter for a content type' do
|
52
|
-
expect(subject
|
48
|
+
expect(subject).to receive(:namespace_stackable).with(:formatters, c_type.to_sym => :formatter)
|
53
49
|
subject.formatter c_type, :formatter
|
54
50
|
end
|
55
51
|
end
|
56
52
|
|
57
53
|
describe '.parser' do
|
58
54
|
it 'sets a parser for a content type' do
|
59
|
-
expect(subject
|
55
|
+
expect(subject).to receive(:namespace_stackable).with(:parsers, c_type.to_sym => :parser)
|
60
56
|
subject.parser c_type, :parser
|
61
57
|
end
|
62
58
|
end
|
63
59
|
|
64
60
|
describe '.default_error_formatter' do
|
65
61
|
it 'sets a new error formatter' do
|
66
|
-
expect(subject).to receive(:
|
62
|
+
expect(subject).to receive(:namespace_inheritable).with(:default_error_formatter, Grape::ErrorFormatter::Json)
|
67
63
|
subject.default_error_formatter :json
|
68
64
|
end
|
69
65
|
end
|
@@ -71,38 +67,36 @@ module Grape
|
|
71
67
|
describe '.error_formatter' do
|
72
68
|
it 'sets a error_formatter' do
|
73
69
|
format = 'txt'
|
74
|
-
expect(subject
|
70
|
+
expect(subject).to receive(:namespace_stackable).with(:error_formatters, format.to_sym => :error_formatter)
|
75
71
|
subject.error_formatter format, :error_formatter
|
76
72
|
end
|
77
73
|
|
78
74
|
it 'understands syntactic sugar' do
|
79
|
-
expect(subject
|
75
|
+
expect(subject).to receive(:namespace_stackable).with(:error_formatters, format.to_sym => :error_formatter)
|
80
76
|
subject.error_formatter format, with: :error_formatter
|
81
77
|
end
|
82
78
|
end
|
83
79
|
|
84
80
|
describe '.content_type' do
|
85
81
|
it 'sets a content type for a format' do
|
86
|
-
expect(subject
|
82
|
+
expect(subject).to receive(:namespace_stackable).with(:content_types, format.to_sym => c_type)
|
87
83
|
subject.content_type format, c_type
|
88
84
|
end
|
89
85
|
end
|
90
86
|
|
91
87
|
describe '.content_types' do
|
92
88
|
it 'returns all content types' do
|
93
|
-
expect(subject.content_types).to eq(xml:
|
94
|
-
serializable_hash:
|
95
|
-
json:
|
96
|
-
|
97
|
-
|
98
|
-
rss: "application/rss+xml",
|
99
|
-
txt: "text/plain")
|
89
|
+
expect(subject.content_types).to eq(xml: 'application/xml',
|
90
|
+
serializable_hash: 'application/json',
|
91
|
+
json: 'application/json',
|
92
|
+
txt: 'text/plain',
|
93
|
+
binary: 'application/octet-stream')
|
100
94
|
end
|
101
95
|
end
|
102
96
|
|
103
97
|
describe '.default_error_status' do
|
104
98
|
it 'sets a default error status' do
|
105
|
-
expect(subject).to receive(:
|
99
|
+
expect(subject).to receive(:namespace_inheritable).with(:default_error_status, 500)
|
106
100
|
subject.default_error_status 500
|
107
101
|
end
|
108
102
|
end
|
@@ -114,7 +108,7 @@ module Grape
|
|
114
108
|
describe '.represent' do
|
115
109
|
it 'sets a presenter for a class' do
|
116
110
|
presenter = Class.new
|
117
|
-
expect(subject).to receive(:
|
111
|
+
expect(subject).to receive(:namespace_stackable).with(:representations, ThisClass: presenter)
|
118
112
|
subject.represent :ThisClass, with: presenter
|
119
113
|
end
|
120
114
|
end
|
@@ -21,27 +21,43 @@ module Grape
|
|
21
21
|
describe '.prefix' do
|
22
22
|
it 'sets a prefix for route' do
|
23
23
|
prefix = '/api'
|
24
|
-
expect(subject).to receive(:
|
24
|
+
expect(subject).to receive(:namespace_inheritable).with(:root_prefix, prefix)
|
25
25
|
subject.prefix prefix
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
describe '.do_not_route_head!' do
|
30
30
|
it 'sets do not route head option' do
|
31
|
-
expect(subject).to receive(:
|
31
|
+
expect(subject).to receive(:namespace_inheritable).with(:do_not_route_head, true)
|
32
32
|
subject.do_not_route_head!
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
describe '.do_not_route_options!' do
|
37
37
|
it 'sets do not route options option' do
|
38
|
-
expect(subject).to receive(:
|
38
|
+
expect(subject).to receive(:namespace_inheritable).with(:do_not_route_options, true)
|
39
39
|
subject.do_not_route_options!
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
|
-
it '
|
43
|
+
describe '.mount' do
|
44
|
+
it 'mounts on a nested path' do
|
45
|
+
subject = Class.new(Grape::API)
|
46
|
+
app1 = Class.new(Grape::API)
|
47
|
+
app2 = Class.new(Grape::API)
|
48
|
+
app2.get '/nice' do
|
49
|
+
'play'
|
50
|
+
end
|
51
|
+
|
52
|
+
subject.mount app1 => '/app1'
|
53
|
+
app1.mount app2 => '/app2'
|
54
|
+
|
55
|
+
expect(subject.inheritable_setting.to_hash[:namespace]).to eq({})
|
56
|
+
expect(subject.inheritable_setting.to_hash[:namespace_inheritable]).to eq({})
|
57
|
+
expect(app1.inheritable_setting.to_hash[:namespace_stackable]).to eq(:mount_path => ['/app1'])
|
58
|
+
|
59
|
+
expect(app2.inheritable_setting.to_hash[:namespace_stackable]).to eq(:mount_path => ['/app1', '/app2'])
|
60
|
+
end
|
45
61
|
end
|
46
62
|
xdescribe '.route' do
|
47
63
|
it 'does some thing'
|