grape 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grape might be problematic. Click here for more details.

Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -66
  3. data/.rubocop_todo.yml +78 -17
  4. data/.travis.yml +7 -3
  5. data/Appraisals +7 -0
  6. data/CHANGELOG.md +24 -0
  7. data/CONTRIBUTING.md +7 -0
  8. data/Gemfile +1 -7
  9. data/Guardfile +1 -1
  10. data/README.md +560 -94
  11. data/RELEASING.md +1 -1
  12. data/Rakefile +10 -11
  13. data/UPGRADING.md +211 -3
  14. data/gemfiles/rails_3.gemfile +14 -0
  15. data/gemfiles/rails_4.gemfile +14 -0
  16. data/grape.gemspec +10 -9
  17. data/lib/backports/active_support/deep_dup.rb +49 -0
  18. data/lib/backports/active_support/duplicable.rb +88 -0
  19. data/lib/grape.rb +29 -2
  20. data/lib/grape/api.rb +59 -65
  21. data/lib/grape/dsl/api.rb +19 -0
  22. data/lib/grape/dsl/callbacks.rb +6 -4
  23. data/lib/grape/dsl/configuration.rb +49 -5
  24. data/lib/grape/dsl/helpers.rb +7 -8
  25. data/lib/grape/dsl/inside_route.rb +22 -10
  26. data/lib/grape/dsl/middleware.rb +5 -5
  27. data/lib/grape/dsl/parameters.rb +6 -2
  28. data/lib/grape/dsl/request_response.rb +23 -20
  29. data/lib/grape/dsl/routing.rb +52 -49
  30. data/lib/grape/dsl/settings.rb +110 -0
  31. data/lib/grape/dsl/validations.rb +14 -6
  32. data/lib/grape/endpoint.rb +104 -88
  33. data/lib/grape/exceptions/base.rb +2 -2
  34. data/lib/grape/exceptions/incompatible_option_values.rb +1 -1
  35. data/lib/grape/exceptions/invalid_formatter.rb +1 -1
  36. data/lib/grape/exceptions/invalid_versioner_option.rb +1 -1
  37. data/lib/grape/exceptions/invalid_with_option_for_represent.rb +1 -1
  38. data/lib/grape/exceptions/missing_mime_type.rb +1 -1
  39. data/lib/grape/exceptions/missing_option.rb +1 -1
  40. data/lib/grape/exceptions/missing_vendor_option.rb +1 -1
  41. data/lib/grape/exceptions/unknown_options.rb +1 -1
  42. data/lib/grape/exceptions/unknown_validator.rb +1 -1
  43. data/lib/grape/exceptions/validation.rb +1 -1
  44. data/lib/grape/exceptions/validation_errors.rb +2 -2
  45. data/lib/grape/formatter/serializable_hash.rb +1 -1
  46. data/lib/grape/formatter/xml.rb +1 -1
  47. data/lib/grape/locale/en.yml +2 -0
  48. data/lib/grape/middleware/auth/dsl.rb +26 -21
  49. data/lib/grape/middleware/auth/strategies.rb +1 -1
  50. data/lib/grape/middleware/auth/strategy_info.rb +0 -2
  51. data/lib/grape/middleware/base.rb +2 -2
  52. data/lib/grape/middleware/error.rb +1 -1
  53. data/lib/grape/middleware/formatter.rb +5 -5
  54. data/lib/grape/middleware/versioner.rb +1 -1
  55. data/lib/grape/middleware/versioner/header.rb +3 -3
  56. data/lib/grape/middleware/versioner/param.rb +2 -2
  57. data/lib/grape/middleware/versioner/path.rb +1 -1
  58. data/lib/grape/namespace.rb +1 -1
  59. data/lib/grape/path.rb +9 -3
  60. data/lib/grape/util/content_types.rb +16 -8
  61. data/lib/grape/util/inheritable_setting.rb +74 -0
  62. data/lib/grape/util/inheritable_values.rb +51 -0
  63. data/lib/grape/util/stackable_values.rb +52 -0
  64. data/lib/grape/util/strict_hash_configuration.rb +106 -0
  65. data/lib/grape/validations.rb +0 -220
  66. data/lib/grape/validations/attributes_iterator.rb +21 -0
  67. data/lib/grape/validations/params_scope.rb +176 -0
  68. data/lib/grape/validations/validators/all_or_none.rb +20 -0
  69. data/lib/grape/validations/validators/allow_blank.rb +30 -0
  70. data/lib/grape/validations/validators/at_least_one_of.rb +20 -0
  71. data/lib/grape/validations/validators/base.rb +37 -0
  72. data/lib/grape/validations/{coerce.rb → validators/coerce.rb} +3 -3
  73. data/lib/grape/validations/{default.rb → validators/default.rb} +1 -1
  74. data/lib/grape/validations/validators/exactly_one_of.rb +20 -0
  75. data/lib/grape/validations/validators/multiple_params_base.rb +26 -0
  76. data/lib/grape/validations/validators/mutual_exclusion.rb +25 -0
  77. data/lib/grape/validations/{presence.rb → validators/presence.rb} +2 -2
  78. data/lib/grape/validations/validators/regexp.rb +12 -0
  79. data/lib/grape/validations/validators/values.rb +26 -0
  80. data/lib/grape/version.rb +1 -1
  81. data/spec/grape/api_spec.rb +522 -343
  82. data/spec/grape/dsl/callbacks_spec.rb +4 -4
  83. data/spec/grape/dsl/configuration_spec.rb +48 -9
  84. data/spec/grape/dsl/helpers_spec.rb +6 -13
  85. data/spec/grape/dsl/inside_route_spec.rb +43 -4
  86. data/spec/grape/dsl/middleware_spec.rb +1 -10
  87. data/spec/grape/dsl/parameters_spec.rb +8 -1
  88. data/spec/grape/dsl/request_response_spec.rb +16 -22
  89. data/spec/grape/dsl/routing_spec.rb +21 -5
  90. data/spec/grape/dsl/settings_spec.rb +219 -0
  91. data/spec/grape/dsl/validations_spec.rb +8 -11
  92. data/spec/grape/endpoint_spec.rb +115 -86
  93. data/spec/grape/entity_spec.rb +33 -33
  94. data/spec/grape/exceptions/invalid_formatter_spec.rb +3 -5
  95. data/spec/grape/exceptions/invalid_versioner_option_spec.rb +4 -6
  96. data/spec/grape/exceptions/missing_mime_type_spec.rb +5 -6
  97. data/spec/grape/exceptions/missing_option_spec.rb +3 -5
  98. data/spec/grape/exceptions/unknown_options_spec.rb +3 -5
  99. data/spec/grape/exceptions/unknown_validator_spec.rb +3 -5
  100. data/spec/grape/exceptions/validation_errors_spec.rb +5 -5
  101. data/spec/grape/loading_spec.rb +44 -0
  102. data/spec/grape/middleware/auth/base_spec.rb +0 -4
  103. data/spec/grape/middleware/auth/dsl_spec.rb +2 -4
  104. data/spec/grape/middleware/auth/strategies_spec.rb +5 -6
  105. data/spec/grape/middleware/exception_spec.rb +8 -10
  106. data/spec/grape/middleware/formatter_spec.rb +13 -15
  107. data/spec/grape/middleware/versioner/accept_version_header_spec.rb +10 -10
  108. data/spec/grape/middleware/versioner/header_spec.rb +25 -25
  109. data/spec/grape/middleware/versioner/param_spec.rb +15 -17
  110. data/spec/grape/middleware/versioner/path_spec.rb +1 -2
  111. data/spec/grape/middleware/versioner_spec.rb +0 -1
  112. data/spec/grape/path_spec.rb +66 -45
  113. data/spec/grape/util/inheritable_setting_spec.rb +217 -0
  114. data/spec/grape/util/inheritable_values_spec.rb +63 -0
  115. data/spec/grape/util/stackable_values_spec.rb +115 -0
  116. data/spec/grape/util/strict_hash_configuration_spec.rb +38 -0
  117. data/spec/grape/validations/attributes_iterator_spec.rb +4 -0
  118. data/spec/grape/validations/params_scope_spec.rb +57 -0
  119. data/spec/grape/validations/validators/all_or_none_spec.rb +60 -0
  120. data/spec/grape/validations/validators/allow_blank_spec.rb +170 -0
  121. data/spec/grape/validations/{at_least_one_of_spec.rb → validators/at_least_one_of_spec.rb} +7 -3
  122. data/spec/grape/validations/{coerce_spec.rb → validators/coerce_spec.rb} +8 -11
  123. data/spec/grape/validations/{default_spec.rb → validators/default_spec.rb} +7 -9
  124. data/spec/grape/validations/{exactly_one_of_spec.rb → validators/exactly_one_of_spec.rb} +15 -11
  125. data/spec/grape/validations/{mutual_exclusion_spec.rb → validators/mutual_exclusion_spec.rb} +11 -9
  126. data/spec/grape/validations/{presence_spec.rb → validators/presence_spec.rb} +30 -30
  127. data/spec/grape/validations/{regexp_spec.rb → validators/regexp_spec.rb} +2 -4
  128. data/spec/grape/validations/{values_spec.rb → validators/values_spec.rb} +95 -23
  129. data/spec/grape/validations/{zh-CN.yml → validators/zh-CN.yml} +0 -0
  130. data/spec/grape/validations_spec.rb +335 -70
  131. data/spec/shared/versioning_examples.rb +7 -8
  132. data/spec/spec_helper.rb +2 -0
  133. data/spec/support/basic_auth_encode_helpers.rb +1 -1
  134. data/spec/support/content_type_helpers.rb +1 -1
  135. data/spec/support/versioned_helpers.rb +3 -3
  136. metadata +80 -33
  137. data/lib/grape/util/deep_merge.rb +0 -23
  138. data/lib/grape/util/hash_stack.rb +0 -120
  139. data/lib/grape/validations/at_least_one_of.rb +0 -25
  140. data/lib/grape/validations/exactly_one_of.rb +0 -26
  141. data/lib/grape/validations/mutual_exclusion.rb +0 -25
  142. data/lib/grape/validations/regexp.rb +0 -12
  143. data/lib/grape/validations/values.rb +0 -23
  144. data/spec/grape/util/hash_stack_spec.rb +0 -132
@@ -31,7 +31,7 @@ describe Grape::Entity do
31
31
 
32
32
  it 'pulls a representation from the class options if it exists' do
33
33
  entity = Class.new(Grape::Entity)
34
- allow(entity).to receive(:represent).and_return("Hiya")
34
+ allow(entity).to receive(:represent).and_return('Hiya')
35
35
 
36
36
  subject.represent Object, with: entity
37
37
  subject.get '/example' do
@@ -43,7 +43,7 @@ describe Grape::Entity do
43
43
 
44
44
  it 'pulls a representation from the class options if the presented object is a collection of objects' do
45
45
  entity = Class.new(Grape::Entity)
46
- allow(entity).to receive(:represent).and_return("Hiya")
46
+ allow(entity).to receive(:represent).and_return('Hiya')
47
47
 
48
48
  class TestObject
49
49
  end
@@ -64,15 +64,15 @@ describe Grape::Entity do
64
64
  end
65
65
 
66
66
  get '/example'
67
- expect(last_response.body).to eq("Hiya")
67
+ expect(last_response.body).to eq('Hiya')
68
68
 
69
69
  get '/example2'
70
- expect(last_response.body).to eq("Hiya")
70
+ expect(last_response.body).to eq('Hiya')
71
71
  end
72
72
 
73
73
  it 'pulls a representation from the class ancestor if it exists' do
74
74
  entity = Class.new(Grape::Entity)
75
- allow(entity).to receive(:represent).and_return("Hiya")
75
+ allow(entity).to receive(:represent).and_return('Hiya')
76
76
 
77
77
  subclass = Class.new(Object)
78
78
 
@@ -87,7 +87,7 @@ describe Grape::Entity do
87
87
  it 'automatically uses Klass::Entity if that exists' do
88
88
  some_model = Class.new
89
89
  entity = Class.new(Grape::Entity)
90
- allow(entity).to receive(:represent).and_return("Auto-detect!")
90
+ allow(entity).to receive(:represent).and_return('Auto-detect!')
91
91
 
92
92
  some_model.const_set :Entity, entity
93
93
 
@@ -101,7 +101,7 @@ describe Grape::Entity do
101
101
  it 'automatically uses Klass::Entity based on the first object in the collection being presented' do
102
102
  some_model = Class.new
103
103
  entity = Class.new(Grape::Entity)
104
- allow(entity).to receive(:represent).and_return("Auto-detect!")
104
+ allow(entity).to receive(:represent).and_return('Auto-detect!')
105
105
 
106
106
  some_model.const_set :Entity, entity
107
107
 
@@ -129,7 +129,7 @@ describe Grape::Entity do
129
129
  some_relation = Class.new
130
130
  some_model = Class.new
131
131
 
132
- allow(entity).to receive(:represent).and_return("Auto-detect!")
132
+ allow(entity).to receive(:represent).and_return('Auto-detect!')
133
133
  allow(some_relation).to receive(:first)
134
134
  allow(some_relation).to receive(:klass).and_return(some_model)
135
135
 
@@ -168,10 +168,9 @@ describe Grape::Entity do
168
168
  end
169
169
 
170
170
  [:json, :serializable_hash].each do |format|
171
-
172
171
  it 'presents with #{format}' do
173
172
  entity = Class.new(Grape::Entity)
174
- entity.root "examples", "example"
173
+ entity.root 'examples', 'example'
175
174
  entity.expose :id
176
175
 
177
176
  subject.format format
@@ -192,7 +191,7 @@ describe Grape::Entity do
192
191
 
193
192
  it 'presents with #{format} collection' do
194
193
  entity = Class.new(Grape::Entity)
195
- entity.root "examples", "example"
194
+ entity.root 'examples', 'example'
196
195
  entity.expose :id
197
196
 
198
197
  subject.format format
@@ -211,12 +210,11 @@ describe Grape::Entity do
211
210
  expect(last_response.status).to eq(200)
212
211
  expect(last_response.body).to eq('{"examples":[{"id":1},{"id":2}]}')
213
212
  end
214
-
215
213
  end
216
214
 
217
215
  it 'presents with xml' do
218
216
  entity = Class.new(Grape::Entity)
219
- entity.root "examples", "example"
217
+ entity.root 'examples', 'example'
220
218
  entity.expose :name
221
219
 
222
220
  subject.format :xml
@@ -225,14 +223,14 @@ describe Grape::Entity do
225
223
  c = Class.new do
226
224
  attr_reader :name
227
225
  def initialize(args)
228
- @name = args[:name] || "no name set"
226
+ @name = args[:name] || 'no name set'
229
227
  end
230
228
  end
231
- present c.new(name: "johnnyiller"), with: entity
229
+ present c.new(name: 'johnnyiller'), with: entity
232
230
  end
233
231
  get '/example'
234
232
  expect(last_response.status).to eq(200)
235
- expect(last_response.headers['Content-type']).to eq("application/xml")
233
+ expect(last_response.headers['Content-type']).to eq('application/xml')
236
234
  expect(last_response.body).to eq <<-XML
237
235
  <?xml version="1.0" encoding="UTF-8"?>
238
236
  <hash>
@@ -245,7 +243,7 @@ XML
245
243
 
246
244
  it 'presents with json' do
247
245
  entity = Class.new(Grape::Entity)
248
- entity.root "examples", "example"
246
+ entity.root 'examples', 'example'
249
247
  entity.expose :name
250
248
 
251
249
  subject.format :json
@@ -254,14 +252,14 @@ XML
254
252
  c = Class.new do
255
253
  attr_reader :name
256
254
  def initialize(args)
257
- @name = args[:name] || "no name set"
255
+ @name = args[:name] || 'no name set'
258
256
  end
259
257
  end
260
- present c.new(name: "johnnyiller"), with: entity
258
+ present c.new(name: 'johnnyiller'), with: entity
261
259
  end
262
260
  get '/example'
263
261
  expect(last_response.status).to eq(200)
264
- expect(last_response.headers['Content-type']).to eq("application/json")
262
+ expect(last_response.headers['Content-type']).to eq('application/json')
265
263
  expect(last_response.body).to eq('{"example":{"name":"johnnyiller"}}')
266
264
  end
267
265
 
@@ -272,35 +270,38 @@ XML
272
270
  subject.use Rack::JSONP
273
271
 
274
272
  entity = Class.new(Grape::Entity)
275
- entity.root "examples", "example"
273
+ entity.root 'examples', 'example'
276
274
  entity.expose :name
277
275
 
278
- # Rack::JSONP expects a standard JSON response
276
+ # Rack::JSONP expects a standard JSON response in UTF-8 format
279
277
  subject.format :json
278
+ subject.formatter :json, lambda { |object, _|
279
+ object.to_json.encode('utf-8')
280
+ }
280
281
 
281
282
  subject.get '/example' do
282
283
  c = Class.new do
283
284
  attr_reader :name
284
285
  def initialize(args)
285
- @name = args[:name] || "no name set"
286
+ @name = args[:name] || 'no name set'
286
287
  end
287
288
  end
288
289
 
289
- present c.new(name: "johnnyiller"), with: entity
290
+ present c.new(name: 'johnnyiller'), with: entity
290
291
  end
291
292
 
292
293
  get '/example?callback=abcDef'
293
294
  expect(last_response.status).to eq(200)
294
- expect(last_response.headers['Content-type']).to eq("application/javascript")
295
- expect(last_response.body).to eq('abcDef({"example":{"name":"johnnyiller"}})')
295
+ expect(last_response.headers['Content-type']).to eq('application/javascript')
296
+ expect(last_response.body).to include 'abcDef({"example":{"name":"johnnyiller"}})'
296
297
  end
297
298
 
298
- context "present with multiple entities" do
299
- it "present with multiple entities using optional symbol" do
299
+ context 'present with multiple entities' do
300
+ it 'present with multiple entities using optional symbol' do
300
301
  user = Class.new do
301
302
  attr_reader :name
302
303
  def initialize(args)
303
- @name = args[:name] || "no name set"
304
+ @name = args[:name] || 'no name set'
304
305
  end
305
306
  end
306
307
  user1 = user.new(name: 'user1')
@@ -317,13 +318,12 @@ XML
317
318
  end
318
319
  get '/example'
319
320
  expect_response_json = {
320
- "page" => 1,
321
- "user1" => { "name" => "user1" },
322
- "user2" => { "name" => "user2" }
321
+ 'page' => 1,
322
+ 'user1' => { 'name' => 'user1' },
323
+ 'user2' => { 'name' => 'user2' }
323
324
  }
324
325
  expect(JSON(last_response.body)).to eq(expect_response_json)
325
326
  end
326
-
327
327
  end
328
328
  end
329
329
  end
@@ -2,17 +2,15 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Grape::Exceptions::InvalidFormatter do
5
- describe "#message" do
5
+ describe '#message' do
6
6
  let(:error) do
7
7
  described_class.new(String, 'xml')
8
8
  end
9
9
 
10
- it "contains the problem in the message" do
10
+ it 'contains the problem in the message' do
11
11
  expect(error.message).to include(
12
- "cannot convert String to xml"
12
+ 'cannot convert String to xml'
13
13
  )
14
14
  end
15
-
16
15
  end
17
-
18
16
  end
@@ -2,17 +2,15 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Grape::Exceptions::InvalidVersionerOption do
5
- describe "#message" do
5
+ describe '#message' do
6
6
  let(:error) do
7
- described_class.new("headers")
7
+ described_class.new('headers')
8
8
  end
9
9
 
10
- it "contains the problem in the message" do
10
+ it 'contains the problem in the message' do
11
11
  expect(error.message).to include(
12
- "Unknown :using for versioner: headers"
12
+ 'Unknown :using for versioner: headers'
13
13
  )
14
14
  end
15
-
16
15
  end
17
-
18
16
  end
@@ -1,17 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Grape::Exceptions::MissingMimeType do
4
- describe "#message" do
5
-
4
+ describe '#message' do
6
5
  let(:error) do
7
- described_class.new("new_json")
6
+ described_class.new('new_json')
8
7
  end
9
8
 
10
- it "contains the problem in the message" do
11
- expect(error.message).to include "missing mime type for new_json"
9
+ it 'contains the problem in the message' do
10
+ expect(error.message).to include 'missing mime type for new_json'
12
11
  end
13
12
 
14
- it "contains the resolution in the message" do
13
+ it 'contains the resolution in the message' do
15
14
  expect(error.message).to include "or add your own with content_type :new_json, 'application/new_json' "
16
15
  end
17
16
  end
@@ -2,17 +2,15 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Grape::Exceptions::MissingOption do
5
- describe "#message" do
5
+ describe '#message' do
6
6
  let(:error) do
7
7
  described_class.new(:path)
8
8
  end
9
9
 
10
- it "contains the problem in the message" do
10
+ it 'contains the problem in the message' do
11
11
  expect(error.message).to include(
12
- "You must specify :path options."
12
+ 'You must specify :path options.'
13
13
  )
14
14
  end
15
-
16
15
  end
17
-
18
16
  end
@@ -2,17 +2,15 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Grape::Exceptions::UnknownOptions do
5
- describe "#message" do
5
+ describe '#message' do
6
6
  let(:error) do
7
7
  described_class.new([:a, :b])
8
8
  end
9
9
 
10
- it "contains the problem in the message" do
10
+ it 'contains the problem in the message' do
11
11
  expect(error.message).to include(
12
- "unknown options: "
12
+ 'unknown options: '
13
13
  )
14
14
  end
15
-
16
15
  end
17
-
18
16
  end
@@ -2,17 +2,15 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Grape::Exceptions::UnknownValidator do
5
- describe "#message" do
5
+ describe '#message' do
6
6
  let(:error) do
7
7
  described_class.new('gt_10')
8
8
  end
9
9
 
10
- it "contains the problem in the message" do
10
+ it 'contains the problem in the message' do
11
11
  expect(error.message).to include(
12
- "unknown validator: gt_10"
12
+ 'unknown validator: gt_10'
13
13
  )
14
14
  end
15
-
16
15
  end
17
-
18
16
  end
@@ -2,11 +2,11 @@ require 'spec_helper'
2
2
  require 'ostruct'
3
3
 
4
4
  describe Grape::Exceptions::ValidationErrors do
5
- let(:validation_message) { "FooBar is invalid" }
5
+ let(:validation_message) { 'FooBar is invalid' }
6
6
  let(:validation_error) { OpenStruct.new(params: [validation_message]) }
7
7
 
8
- context "message" do
9
- context "is not repeated" do
8
+ context 'message' do
9
+ context 'is not repeated' do
10
10
  let(:error) do
11
11
  described_class.new(errors: [validation_error, validation_error])
12
12
  end
@@ -41,8 +41,8 @@ describe Grape::Exceptions::ValidationErrors do
41
41
  get '/exactly_one_of', beer: 'string', wine: 'anotherstring'
42
42
  expect(last_response.status).to eq(400)
43
43
  expect(JSON.parse(last_response.body)).to eq([
44
- "params" => ["beer", "wine"],
45
- "messages" => ["are mutually exclusive"]
44
+ 'params' => %w(beer wine),
45
+ 'messages' => ['are mutually exclusive']
46
46
  ])
47
47
  end
48
48
  end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Grape::API do
4
+ let(:jobs_api) do
5
+ Class.new(Grape::API) do
6
+ namespace :one do
7
+ namespace :two do
8
+ namespace :three do
9
+ get :one do
10
+ end
11
+ get :two do
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ let(:combined_api) do
20
+ JobsApi = jobs_api
21
+ Class.new(Grape::API) do
22
+ version :v1, using: :accept_version_header, cascade: true
23
+ mount JobsApi
24
+ end
25
+ end
26
+
27
+ subject do
28
+ CombinedApi = combined_api
29
+ Class.new(Grape::API) do
30
+ format :json
31
+ mount CombinedApi => '/'
32
+ end
33
+ end
34
+
35
+ def app
36
+ subject
37
+ end
38
+
39
+ it 'execute first request in reasonable time' do
40
+ started = Time.now
41
+ get '/mount1/nested/test_method'
42
+ expect(Time.now - started).to be < 5
43
+ end
44
+ end
@@ -4,16 +4,13 @@ require 'base64'
4
4
  describe Grape::Middleware::Auth::Base do
5
5
  subject do
6
6
  Class.new(Grape::API) do
7
-
8
7
  http_basic realm: 'my_realm' do |user, password|
9
8
  user && password && user == password
10
9
  end
11
10
  get '/authorized' do
12
11
  'DONE'
13
12
  end
14
-
15
13
  end
16
-
17
14
  end
18
15
 
19
16
  def app
@@ -30,5 +27,4 @@ describe Grape::Middleware::Auth::Base do
30
27
  get '/authorized', {}, 'HTTP_AUTHORIZATION' => encode_basic_auth('admin', 'wrong')
31
28
  expect(last_response.status).to eq(401)
32
29
  end
33
-
34
30
  end
@@ -6,9 +6,9 @@ describe Grape::Middleware::Auth::DSL do
6
6
  let(:block) { ->() {} }
7
7
  let(:settings) do
8
8
  {
9
- opaque: "secret",
9
+ opaque: 'secret',
10
10
  proc: block,
11
- realm: "API Authorization",
11
+ realm: 'API Authorization',
12
12
  type: :http_digest
13
13
  }
14
14
  end
@@ -33,7 +33,6 @@ describe Grape::Middleware::Auth::DSL do
33
33
  expect(subject.auth).to eq(settings.merge(realm: 'super_secret'))
34
34
  expect(subject.auth.object_id).not_to eq(first_settings.object_id)
35
35
  end
36
-
37
36
  end
38
37
 
39
38
  describe '.http_basic' do
@@ -49,5 +48,4 @@ describe Grape::Middleware::Auth::DSL do
49
48
  expect(subject.auth).to eq(realm: 'my_realm', type: :http_digest, proc: block, opaque: 'my_opaque')
50
49
  end
51
50
  end
52
-
53
51
  end