grape 1.6.2 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -1
  3. data/README.md +120 -19
  4. data/UPGRADING.md +15 -0
  5. data/lib/grape/api/instance.rb +1 -1
  6. data/lib/grape/dry_types.rb +12 -0
  7. data/lib/grape/dsl/api.rb +0 -2
  8. data/lib/grape/dsl/callbacks.rb +0 -2
  9. data/lib/grape/dsl/configuration.rb +0 -2
  10. data/lib/grape/dsl/desc.rb +0 -15
  11. data/lib/grape/dsl/helpers.rb +0 -2
  12. data/lib/grape/dsl/inside_route.rb +33 -29
  13. data/lib/grape/dsl/middleware.rb +0 -2
  14. data/lib/grape/dsl/parameters.rb +5 -7
  15. data/lib/grape/dsl/request_response.rb +0 -2
  16. data/lib/grape/dsl/routing.rb +4 -2
  17. data/lib/grape/dsl/settings.rb +0 -2
  18. data/lib/grape/dsl/validations.rb +0 -15
  19. data/lib/grape/error_formatter/json.rb +7 -1
  20. data/lib/grape/exceptions/base.rb +2 -2
  21. data/lib/grape/exceptions/missing_group_type.rb +8 -1
  22. data/lib/grape/exceptions/too_many_multipart_files.rb +11 -0
  23. data/lib/grape/exceptions/unsupported_group_type.rb +8 -1
  24. data/lib/grape/exceptions/validation.rb +0 -4
  25. data/lib/grape/locale/en.yml +9 -8
  26. data/lib/grape/middleware/auth/dsl.rb +0 -1
  27. data/lib/grape/middleware/error.rb +2 -2
  28. data/lib/grape/request.rb +2 -0
  29. data/lib/grape/util/json.rb +2 -0
  30. data/lib/grape/validations/attributes_doc.rb +58 -0
  31. data/lib/grape/validations/params_scope.rb +66 -40
  32. data/lib/grape/validations/types/array_coercer.rb +0 -2
  33. data/lib/grape/validations/types/dry_type_coercer.rb +3 -7
  34. data/lib/grape/validations/types/primitive_coercer.rb +14 -6
  35. data/lib/grape/validations/types/set_coercer.rb +0 -2
  36. data/lib/grape/validations/types.rb +98 -30
  37. data/lib/grape/validations/validators/{all_or_none.rb → all_or_none_of_validator.rb} +0 -2
  38. data/lib/grape/validations/validators/{allow_blank.rb → allow_blank_validator.rb} +0 -0
  39. data/lib/grape/validations/validators/{as.rb → as_validator.rb} +0 -0
  40. data/lib/grape/validations/validators/{at_least_one_of.rb → at_least_one_of_validator.rb} +0 -2
  41. data/lib/grape/validations/validators/base.rb +7 -0
  42. data/lib/grape/validations/validators/{coerce.rb → coerce_validator.rb} +0 -0
  43. data/lib/grape/validations/validators/{default.rb → default_validator.rb} +0 -0
  44. data/lib/grape/validations/validators/{exactly_one_of.rb → exactly_one_of_validator.rb} +0 -2
  45. data/lib/grape/validations/validators/{except_values.rb → except_values_validator.rb} +0 -0
  46. data/lib/grape/validations/validators/{mutual_exclusion.rb → mutual_exclusion_validator.rb} +0 -2
  47. data/lib/grape/validations/validators/{presence.rb → presence_validator.rb} +0 -0
  48. data/lib/grape/validations/validators/{regexp.rb → regexp_validator.rb} +0 -0
  49. data/lib/grape/validations/validators/{same_as.rb → same_as_validator.rb} +0 -0
  50. data/lib/grape/validations/validators/{values.rb → values_validator.rb} +0 -0
  51. data/lib/grape/validations.rb +16 -12
  52. data/lib/grape/version.rb +1 -1
  53. data/lib/grape.rb +66 -28
  54. data/spec/grape/api/custom_validations_spec.rb +41 -2
  55. data/spec/grape/api/deeply_included_options_spec.rb +0 -2
  56. data/spec/grape/api/defines_boolean_in_params_spec.rb +0 -2
  57. data/spec/grape/api/documentation_spec.rb +59 -0
  58. data/spec/grape/api/inherited_helpers_spec.rb +0 -2
  59. data/spec/grape/api/instance_spec.rb +0 -1
  60. data/spec/grape/api/invalid_format_spec.rb +0 -2
  61. data/spec/grape/api/namespace_parameters_in_route_spec.rb +0 -2
  62. data/spec/grape/api/nested_helpers_spec.rb +0 -2
  63. data/spec/grape/api/optional_parameters_in_route_spec.rb +0 -2
  64. data/spec/grape/api/parameters_modification_spec.rb +0 -2
  65. data/spec/grape/api/patch_method_helpers_spec.rb +0 -2
  66. data/spec/grape/api/recognize_path_spec.rb +0 -2
  67. data/spec/grape/api/required_parameters_in_route_spec.rb +0 -2
  68. data/spec/grape/api/required_parameters_with_invalid_method_spec.rb +0 -2
  69. data/spec/grape/api/routes_with_requirements_spec.rb +0 -2
  70. data/spec/grape/api/shared_helpers_exactly_one_of_spec.rb +0 -2
  71. data/spec/grape/api/shared_helpers_spec.rb +0 -2
  72. data/spec/grape/api_remount_spec.rb +0 -1
  73. data/spec/grape/api_spec.rb +18 -5
  74. data/spec/grape/config_spec.rb +0 -2
  75. data/spec/grape/dsl/callbacks_spec.rb +0 -2
  76. data/spec/grape/dsl/configuration_spec.rb +0 -2
  77. data/spec/grape/dsl/desc_spec.rb +0 -2
  78. data/spec/grape/dsl/headers_spec.rb +2 -4
  79. data/spec/grape/dsl/helpers_spec.rb +0 -2
  80. data/spec/grape/dsl/inside_route_spec.rb +10 -12
  81. data/spec/grape/dsl/logger_spec.rb +0 -2
  82. data/spec/grape/dsl/middleware_spec.rb +0 -2
  83. data/spec/grape/dsl/parameters_spec.rb +0 -2
  84. data/spec/grape/dsl/request_response_spec.rb +6 -8
  85. data/spec/grape/dsl/routing_spec.rb +1 -3
  86. data/spec/grape/dsl/settings_spec.rb +0 -2
  87. data/spec/grape/dsl/validations_spec.rb +0 -17
  88. data/spec/grape/endpoint/declared_spec.rb +2 -4
  89. data/spec/grape/endpoint_spec.rb +22 -3
  90. data/spec/grape/entity_spec.rb +0 -1
  91. data/spec/grape/exceptions/base_spec.rb +16 -2
  92. data/spec/grape/exceptions/body_parse_errors_spec.rb +0 -2
  93. data/spec/grape/exceptions/invalid_accept_header_spec.rb +0 -2
  94. data/spec/grape/exceptions/invalid_formatter_spec.rb +0 -2
  95. data/spec/grape/exceptions/invalid_response_spec.rb +0 -2
  96. data/spec/grape/exceptions/invalid_versioner_option_spec.rb +1 -3
  97. data/spec/grape/exceptions/missing_group_type_spec.rb +21 -0
  98. data/spec/grape/exceptions/missing_mime_type_spec.rb +0 -2
  99. data/spec/grape/exceptions/missing_option_spec.rb +1 -3
  100. data/spec/grape/exceptions/unknown_options_spec.rb +0 -2
  101. data/spec/grape/exceptions/unknown_validator_spec.rb +0 -2
  102. data/spec/grape/exceptions/unsupported_group_type_spec.rb +23 -0
  103. data/spec/grape/exceptions/validation_errors_spec.rb +0 -1
  104. data/spec/grape/exceptions/validation_spec.rb +1 -3
  105. data/spec/grape/extensions/param_builders/hash_spec.rb +0 -2
  106. data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +0 -2
  107. data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +0 -2
  108. data/spec/grape/integration/global_namespace_function_spec.rb +0 -2
  109. data/spec/grape/integration/rack_sendfile_spec.rb +0 -2
  110. data/spec/grape/integration/rack_spec.rb +0 -2
  111. data/spec/grape/loading_spec.rb +0 -2
  112. data/spec/grape/middleware/auth/base_spec.rb +0 -1
  113. data/spec/grape/middleware/auth/dsl_spec.rb +0 -2
  114. data/spec/grape/middleware/auth/strategies_spec.rb +0 -2
  115. data/spec/grape/middleware/base_spec.rb +0 -2
  116. data/spec/grape/middleware/error_spec.rb +6 -1
  117. data/spec/grape/middleware/exception_spec.rb +0 -2
  118. data/spec/grape/middleware/formatter_spec.rb +0 -2
  119. data/spec/grape/middleware/globals_spec.rb +0 -2
  120. data/spec/grape/middleware/stack_spec.rb +0 -2
  121. data/spec/grape/middleware/versioner/accept_version_header_spec.rb +0 -2
  122. data/spec/grape/middleware/versioner/header_spec.rb +18 -4
  123. data/spec/grape/middleware/versioner/param_spec.rb +0 -2
  124. data/spec/grape/middleware/versioner/path_spec.rb +0 -2
  125. data/spec/grape/middleware/versioner_spec.rb +0 -2
  126. data/spec/grape/named_api_spec.rb +0 -2
  127. data/spec/grape/parser_spec.rb +0 -2
  128. data/spec/grape/path_spec.rb +0 -2
  129. data/spec/grape/presenters/presenter_spec.rb +0 -2
  130. data/spec/grape/request_spec.rb +0 -2
  131. data/spec/grape/util/inheritable_setting_spec.rb +0 -1
  132. data/spec/grape/util/inheritable_values_spec.rb +0 -1
  133. data/spec/grape/util/reverse_stackable_values_spec.rb +0 -1
  134. data/spec/grape/util/stackable_values_spec.rb +0 -1
  135. data/spec/grape/util/strict_hash_configuration_spec.rb +0 -1
  136. data/spec/grape/validations/attributes_doc_spec.rb +153 -0
  137. data/spec/grape/validations/attributes_iterator_spec.rb +0 -2
  138. data/spec/grape/validations/instance_behaivour_spec.rb +0 -2
  139. data/spec/grape/validations/multiple_attributes_iterator_spec.rb +0 -2
  140. data/spec/grape/validations/params_scope_spec.rb +315 -86
  141. data/spec/grape/validations/single_attribute_iterator_spec.rb +0 -2
  142. data/spec/grape/validations/types/array_coercer_spec.rb +0 -2
  143. data/spec/grape/validations/types/primitive_coercer_spec.rb +20 -5
  144. data/spec/grape/validations/types/set_coercer_spec.rb +0 -2
  145. data/spec/grape/validations/types_spec.rb +28 -2
  146. data/spec/grape/validations/validators/all_or_none_spec.rb +0 -2
  147. data/spec/grape/validations/validators/allow_blank_spec.rb +0 -2
  148. data/spec/grape/validations/validators/at_least_one_of_spec.rb +0 -2
  149. data/spec/grape/validations/validators/coerce_spec.rb +0 -2
  150. data/spec/grape/validations/validators/default_spec.rb +0 -2
  151. data/spec/grape/validations/validators/exactly_one_of_spec.rb +0 -2
  152. data/spec/grape/validations/validators/except_values_spec.rb +0 -2
  153. data/spec/grape/validations/validators/mutual_exclusion_spec.rb +0 -2
  154. data/spec/grape/validations/validators/presence_spec.rb +0 -2
  155. data/spec/grape/validations/validators/regexp_spec.rb +0 -2
  156. data/spec/grape/validations/validators/same_as_spec.rb +0 -2
  157. data/spec/grape/validations/validators/values_spec.rb +0 -2
  158. data/spec/grape/validations_spec.rb +50 -22
  159. data/spec/integration/multi_json/json_spec.rb +0 -2
  160. data/spec/integration/multi_xml/xml_spec.rb +0 -2
  161. data/spec/spec_helper.rb +9 -4
  162. metadata +30 -21
  163. data/spec/support/eager_load.rb +0 -19
@@ -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 eq(nil)
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 Grape::Extensions::Hash::ParamBuilder do
6
4
  subject { Class.new(Grape::API) }
7
5
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder do
6
4
  subject { Class.new(Grape::API) }
7
5
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Extensions::Hashie::Mash::ParamBuilder do
6
4
  subject { Class.new(Grape::API) }
7
5
 
@@ -2,8 +2,6 @@
2
2
 
3
3
  # see https://github.com/ruby-grape/grape/issues/1348
4
4
 
5
- require 'spec_helper'
6
-
7
5
  def namespace
8
6
  raise
9
7
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Rack::Sendfile do
6
4
  subject do
7
5
  content_object = file_object
@@ -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'
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::API do
6
4
  subject do
7
5
  CombinedApi = combined_api
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
3
  require 'base64'
5
4
 
6
5
  describe Grape::Middleware::Auth::Base do
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Middleware::Auth::DSL do
6
4
  subject { Class.new(Grape::API) }
7
5
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  require 'base64'
6
4
 
7
5
  describe Grape::Middleware::Auth::Strategies do
@@ -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
 
@@ -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::Error do
6
4
  let(:exception_app) do
7
5
  Class.new do
@@ -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
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Middleware::Globals do
6
4
  subject { described_class.new(blank_app) }
7
5
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Middleware::Stack do
6
4
  module StackSpec
7
5
  class FooMiddleware; end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Middleware::Versioner::AcceptVersionHeader do
6
4
  subject { described_class.new(app, **(@options || {})) }
7
5
 
@@ -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 be nil
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 be nil
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
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Middleware::Versioner::Param do
6
4
  subject { described_class.new(app, **options) }
7
5
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Middleware::Versioner::Path do
6
4
  subject { described_class.new(app, **options) }
7
5
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Middleware::Versioner do
6
4
  let(:klass) { described_class }
7
5
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe 'A named API' do
6
4
  subject(:api_name) { NamedAPI.endpoints.last.options[:for].to_s }
7
5
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Parser do
6
4
  subject { described_class }
7
5
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  module Grape
6
4
  describe Path do
7
5
  describe '#initialize' do
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  module Grape
6
4
  module Presenters
7
5
  module PresenterSpec
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  module Grape
6
4
  describe Request do
7
5
  let(:default_method) { 'GET' }
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
3
  module Grape
5
4
  module Util
6
5
  describe InheritableSetting do
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
3
  module Grape
5
4
  module Util
6
5
  describe InheritableValues do
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
3
  module Grape
5
4
  module Util
6
5
  describe ReverseStackableValues do
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
3
  module Grape
5
4
  module Util
6
5
  describe StackableValues do
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
3
  module Grape
5
4
  module Util
6
5
  describe 'StrictHashConfiguration' do
@@ -0,0 +1,153 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe Grape::Validations::ParamsScope::AttributesDoc do
4
+ shared_examples 'an optional doc attribute' do |attr|
5
+ it 'does not mention it' do
6
+ expected_opts.delete(attr)
7
+ validations.delete(attr)
8
+
9
+ expect(subject.first['nested[engine_age]']).not_to have_key(attr)
10
+ end
11
+ end
12
+
13
+ let(:api) { Class.new(Grape::API::Instance) }
14
+ let(:scope) do
15
+ params = nil
16
+ api_instance = api
17
+
18
+ # just to get nested params
19
+ Grape::Validations::ParamsScope.new(type: Hash, api: api) do
20
+ params = Grape::Validations::ParamsScope.new(element: 'nested',
21
+ type: Hash,
22
+ api: api_instance,
23
+ parent: self)
24
+ end
25
+
26
+ params
27
+ end
28
+
29
+ let(:validations) do
30
+ {
31
+ presence: true,
32
+ desc: 'Age of...',
33
+ documentation: 'Age is...',
34
+ default: 1
35
+ }
36
+ end
37
+
38
+ let(:doc) { described_class.new(api, scope) }
39
+
40
+ describe '#extract_details' do
41
+ subject { doc.extract_details(validations) }
42
+
43
+ it 'cleans up doc attrs needed for documentation only' do
44
+ subject
45
+
46
+ expect(validations[:desc]).to be_nil
47
+ expect(validations[:documentation]).to be_nil
48
+ end
49
+
50
+ it 'does not clean up doc attrs mandatory for validators' do
51
+ subject
52
+
53
+ expect(validations[:presence]).not_to be_nil
54
+ expect(validations[:default]).not_to be_nil
55
+ end
56
+
57
+ it 'tells when attributes are required' do
58
+ subject
59
+
60
+ expect(doc.required).to be_truthy
61
+ end
62
+ end
63
+
64
+ describe '#document' do
65
+ subject do
66
+ doc.extract_details validations
67
+ doc.document attrs
68
+ end
69
+
70
+ let(:attrs) { %w[engine_age car_age] }
71
+ let(:valid_values) { [1, 3, 5, 8] }
72
+
73
+ let!(:expected_opts) do
74
+ {
75
+ required: true,
76
+ desc: validations[:desc],
77
+ documentation: validations[:documentation],
78
+ default: validations[:default],
79
+ type: 'Integer',
80
+ values: valid_values
81
+ }
82
+ end
83
+
84
+ before do
85
+ doc.type = Integer
86
+ doc.values = valid_values
87
+ end
88
+
89
+ context 'documentation is enabled' do
90
+ subject do
91
+ super()
92
+ api.namespace_stackable(:params)
93
+ end
94
+
95
+ it 'documents attributes' do
96
+ expect(subject.first).to eq('nested[engine_age]' => expected_opts,
97
+ 'nested[car_age]' => expected_opts)
98
+ end
99
+
100
+ it_behaves_like 'an optional doc attribute', :default
101
+ it_behaves_like 'an optional doc attribute', :documentation
102
+ it_behaves_like 'an optional doc attribute', :desc
103
+ it_behaves_like 'an optional doc attribute', :type do
104
+ before { doc.type = nil }
105
+ end
106
+ it_behaves_like 'an optional doc attribute', :values do
107
+ before { doc.values = nil }
108
+ end
109
+
110
+ context 'false as a default value' do
111
+ before { validations[:default] = false }
112
+
113
+ it 'is still documented' do
114
+ doc = subject.first['nested[engine_age]']
115
+
116
+ expect(doc).to have_key(:default)
117
+ expect(doc[:default]).to be(false)
118
+ end
119
+ end
120
+
121
+ context 'nil as a default value' do
122
+ before { validations[:default] = nil }
123
+
124
+ it 'is still documented' do
125
+ doc = subject.first['nested[engine_age]']
126
+
127
+ expect(doc).to have_key(:default)
128
+ expect(doc[:default]).to be_nil
129
+ end
130
+ end
131
+
132
+ context 'the description key instead of desc' do
133
+ let!(:desc) { validations.delete(:desc) }
134
+
135
+ before { validations[:description] = desc }
136
+
137
+ it 'adds the given description' do
138
+ expect(subject.first['nested[engine_age]'][:desc]).to eq(desc)
139
+ end
140
+ end
141
+ end
142
+
143
+ context 'documentation is disabled' do
144
+ before { api.namespace_inheritable :do_not_document, true }
145
+
146
+ it 'does not document attributes' do
147
+ subject
148
+
149
+ expect(api.namespace_stackable(:params)).to eq([])
150
+ end
151
+ end
152
+ end
153
+ end
@@ -1,6 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Validations::AttributesIterator do
6
4
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe 'Validator with instance variables' do
6
4
  let(:validator_type) do
7
5
  Class.new(Grape::Validations::Validators::Base) do
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'spec_helper'
4
-
5
3
  describe Grape::Validations::MultipleAttributesIterator do
6
4
  describe '#each' do
7
5
  subject(:iterator) { described_class.new(validator, scope, params) }