apipie-rails 0.5.20 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +12 -21
  3. data/.github/workflows/rubocop-challenger.yml +28 -0
  4. data/.github/workflows/rubocop.yml +18 -0
  5. data/.gitignore +1 -0
  6. data/.rubocop.yml +128 -0
  7. data/.rubocop_todo.yml +2062 -0
  8. data/.vscode/settings.json +3 -0
  9. data/CHANGELOG.md +144 -0
  10. data/Gemfile +20 -0
  11. data/README.rst +106 -15
  12. data/Rakefile +0 -5
  13. data/apipie-rails.gemspec +18 -9
  14. data/app/controllers/apipie/apipies_controller.rb +14 -29
  15. data/app/helpers/apipie_helper.rb +1 -1
  16. data/app/public/apipie/javascripts/bundled/bootstrap-collapse.js +70 -41
  17. data/app/public/apipie/javascripts/bundled/bootstrap.js +1033 -479
  18. data/app/public/apipie/javascripts/bundled/jquery.js +5 -5
  19. data/app/public/apipie/stylesheets/bundled/bootstrap-responsive.min.css +9 -12
  20. data/app/public/apipie/stylesheets/bundled/bootstrap.min.css +9 -689
  21. data/app/views/apipie/apipies/_deprecation.html.erb +16 -0
  22. data/app/views/apipie/apipies/_params.html.erb +7 -1
  23. data/config/locales/en.yml +8 -0
  24. data/config/locales/ko.yml +31 -0
  25. data/gemfiles/Gemfile.tools +9 -0
  26. data/lib/apipie/apipie_module.rb +7 -7
  27. data/lib/apipie/application.rb +132 -97
  28. data/lib/apipie/configuration.rb +43 -33
  29. data/lib/apipie/dsl_definition.rb +39 -27
  30. data/lib/apipie/error_description.rb +3 -3
  31. data/lib/apipie/errors.rb +16 -16
  32. data/lib/apipie/extractor/collector.rb +4 -5
  33. data/lib/apipie/extractor/recorder.rb +33 -6
  34. data/lib/apipie/extractor/writer.rb +14 -14
  35. data/lib/apipie/extractor.rb +6 -9
  36. data/lib/apipie/generator/config.rb +12 -0
  37. data/lib/apipie/generator/generator.rb +2 -0
  38. data/lib/apipie/generator/swagger/computed_interface_id.rb +23 -0
  39. data/lib/apipie/generator/swagger/config.rb +80 -0
  40. data/lib/apipie/generator/swagger/context.rb +38 -0
  41. data/lib/apipie/generator/swagger/method_description/api_decorator.rb +20 -0
  42. data/lib/apipie/generator/swagger/method_description/api_schema_service.rb +89 -0
  43. data/lib/apipie/generator/swagger/method_description/decorator.rb +22 -0
  44. data/lib/apipie/generator/swagger/method_description/parameters_service.rb +139 -0
  45. data/lib/apipie/generator/swagger/method_description/response_schema_service.rb +46 -0
  46. data/lib/apipie/generator/swagger/method_description/response_service.rb +58 -0
  47. data/lib/apipie/generator/swagger/method_description.rb +2 -0
  48. data/lib/apipie/generator/swagger/operation_id.rb +51 -0
  49. data/lib/apipie/generator/swagger/param_description/builder.rb +105 -0
  50. data/lib/apipie/generator/swagger/param_description/composite.rb +119 -0
  51. data/lib/apipie/generator/swagger/param_description/description.rb +15 -0
  52. data/lib/apipie/generator/swagger/param_description/in.rb +37 -0
  53. data/lib/apipie/generator/swagger/param_description/name.rb +18 -0
  54. data/lib/apipie/generator/swagger/param_description/path_params_composite.rb +61 -0
  55. data/lib/apipie/generator/swagger/param_description/referenced_composite.rb +36 -0
  56. data/lib/apipie/generator/swagger/param_description/type.rb +115 -0
  57. data/lib/apipie/generator/swagger/param_description.rb +18 -0
  58. data/lib/apipie/generator/swagger/path_decorator.rb +36 -0
  59. data/lib/apipie/generator/swagger/referenced_definitions.rb +17 -0
  60. data/lib/apipie/generator/swagger/resource_description_collection.rb +30 -0
  61. data/lib/apipie/generator/swagger/resource_description_composite.rb +56 -0
  62. data/lib/apipie/generator/swagger/schema.rb +63 -0
  63. data/lib/apipie/generator/swagger/swagger.rb +2 -0
  64. data/lib/apipie/generator/swagger/type.rb +16 -0
  65. data/lib/apipie/generator/swagger/type_extractor.rb +51 -0
  66. data/lib/apipie/generator/swagger/warning.rb +74 -0
  67. data/lib/apipie/generator/swagger/warning_writer.rb +54 -0
  68. data/lib/apipie/helpers.rb +3 -3
  69. data/lib/apipie/markup.rb +9 -8
  70. data/lib/apipie/method_description/api.rb +12 -0
  71. data/lib/apipie/method_description/apis_service.rb +82 -0
  72. data/lib/apipie/method_description.rb +12 -56
  73. data/lib/apipie/param_description/deprecation.rb +24 -0
  74. data/lib/apipie/param_description.rb +57 -24
  75. data/lib/apipie/resource_description.rb +42 -14
  76. data/lib/apipie/response_description.rb +3 -3
  77. data/lib/apipie/response_description_adapter.rb +10 -8
  78. data/lib/apipie/routing.rb +1 -1
  79. data/lib/apipie/rspec/response_validation_helper.rb +3 -3
  80. data/lib/apipie/static_dispatcher.rb +3 -1
  81. data/lib/apipie/swagger_generator.rb +28 -691
  82. data/lib/apipie/validator.rb +40 -10
  83. data/lib/apipie/version.rb +1 -1
  84. data/lib/apipie-rails.rb +36 -5
  85. data/lib/generators/apipie/install/install_generator.rb +1 -1
  86. data/lib/generators/apipie/views_generator.rb +1 -1
  87. data/lib/tasks/apipie.rake +35 -30
  88. data/spec/controllers/api/v2/architectures_controller_spec.rb +10 -3
  89. data/spec/controllers/api/v2/empty_middle_controller_spec.rb +23 -0
  90. data/spec/controllers/api/v2/nested/resources_controller_spec.rb +18 -2
  91. data/spec/controllers/api/v2/sub/footguns_controller_spec.rb +19 -0
  92. data/spec/controllers/included_param_group_controller_spec.rb +13 -0
  93. data/spec/{lib/swagger/response_validation_spec.rb → controllers/pets_controller_spec.rb} +26 -32
  94. data/spec/controllers/users_controller_spec.rb +47 -6
  95. data/spec/dummy/Rakefile +1 -1
  96. data/spec/dummy/app/controllers/api/v2/architectures_controller.rb +2 -1
  97. data/spec/dummy/app/controllers/api/v2/base_controller.rb +6 -0
  98. data/spec/dummy/app/controllers/api/v2/empty_middle_controller.rb +14 -0
  99. data/spec/dummy/app/controllers/api/v2/nested/resources_controller.rb +2 -2
  100. data/spec/dummy/app/controllers/api/v2/sub/footguns_controller.rb +30 -0
  101. data/spec/dummy/app/controllers/concerns_controller.rb +1 -1
  102. data/spec/dummy/app/controllers/{concerns/extending_concern.rb → extending_concern.rb} +0 -2
  103. data/spec/dummy/app/controllers/included_param_group_controller.rb +19 -0
  104. data/spec/dummy/app/controllers/overridden_concerns_controller.rb +2 -2
  105. data/spec/dummy/app/controllers/pets_controller.rb +4 -4
  106. data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +2 -2
  107. data/spec/dummy/app/controllers/{concerns/sample_controller.rb → sample_controller.rb} +0 -2
  108. data/spec/dummy/app/controllers/twitter_example_controller.rb +2 -2
  109. data/spec/dummy/app/controllers/users_controller.rb +17 -5
  110. data/spec/dummy/app/helpers/random_param_group.rb +8 -0
  111. data/spec/dummy/components/test_engine/test_engine.gemspec +1 -1
  112. data/spec/dummy/config/application.rb +2 -5
  113. data/spec/dummy/config/boot.rb +2 -2
  114. data/spec/dummy/config/environment.rb +1 -1
  115. data/spec/dummy/config/environments/development.rb +0 -3
  116. data/spec/dummy/config/environments/production.rb +0 -3
  117. data/spec/dummy/config/environments/test.rb +0 -5
  118. data/spec/dummy/config/initializers/apipie.rb +2 -2
  119. data/spec/dummy/config/routes.rb +8 -0
  120. data/spec/dummy/config.ru +1 -1
  121. data/spec/dummy/script/rails +2 -2
  122. data/spec/{controllers → lib/apipie}/apipies_controller_spec.rb +95 -23
  123. data/spec/lib/apipie/application_spec.rb +62 -0
  124. data/spec/lib/apipie/configuration_spec.rb +38 -0
  125. data/spec/lib/apipie/extractor/collector_spec.rb +57 -0
  126. data/spec/lib/apipie/extractor/recorder_spec.rb +77 -0
  127. data/spec/lib/{extractor → apipie/extractor}/writer_spec.rb +8 -6
  128. data/spec/lib/{file_handler_spec.rb → apipie/file_handler_spec.rb} +7 -0
  129. data/spec/lib/apipie/generator/swagger/config_spec.rb +19 -0
  130. data/spec/lib/apipie/generator/swagger/context_spec.rb +56 -0
  131. data/spec/lib/apipie/generator/swagger/method_description/api_schema_service_spec.rb +119 -0
  132. data/spec/lib/apipie/generator/swagger/method_description/response_schema_service_spec.rb +105 -0
  133. data/spec/lib/apipie/generator/swagger/operation_id_spec.rb +63 -0
  134. data/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +203 -0
  135. data/spec/lib/apipie/generator/swagger/param_description/composite_spec.rb +95 -0
  136. data/spec/lib/apipie/generator/swagger/param_description/description_spec.rb +79 -0
  137. data/spec/lib/apipie/generator/swagger/param_description/in_spec.rb +86 -0
  138. data/spec/lib/apipie/generator/swagger/param_description/name_spec.rb +81 -0
  139. data/spec/lib/apipie/generator/swagger/param_description/type_spec.rb +178 -0
  140. data/spec/lib/apipie/generator/swagger/param_description_spec.rb +28 -0
  141. data/spec/lib/apipie/generator/swagger/path_decorator_spec.rb +57 -0
  142. data/spec/lib/apipie/generator/swagger/referenced_definitions_spec.rb +35 -0
  143. data/spec/lib/apipie/generator/swagger/resource_description_composite_spec.rb +37 -0
  144. data/spec/lib/apipie/generator/swagger/resource_descriptions_collection_spec.rb +57 -0
  145. data/spec/lib/apipie/generator/swagger/schema_spec.rb +89 -0
  146. data/spec/lib/apipie/generator/swagger/type_extractor_spec.rb +38 -0
  147. data/spec/lib/apipie/generator/swagger/warning_spec.rb +51 -0
  148. data/spec/lib/apipie/generator/swagger/warning_writer_spec.rb +71 -0
  149. data/spec/lib/apipie/method_description/apis_service_spec.rb +60 -0
  150. data/spec/lib/apipie/method_description_spec.rb +133 -0
  151. data/spec/lib/apipie/no_documented_method_spec.rb +17 -0
  152. data/spec/lib/apipie/param_description/deprecation_spec.rb +31 -0
  153. data/spec/lib/{param_description_spec.rb → apipie/param_description_spec.rb} +332 -6
  154. data/spec/lib/{param_group_spec.rb → apipie/param_group_spec.rb} +6 -5
  155. data/spec/lib/apipie/resource_description_spec.rb +91 -0
  156. data/spec/lib/apipie/response_does_not_match_swagger_schema_spec.rb +35 -0
  157. data/spec/lib/apipie/swagger_generator_spec.rb +94 -0
  158. data/spec/lib/{validator_spec.rb → apipie/validator_spec.rb} +48 -12
  159. data/spec/lib/rake_spec.rb +3 -5
  160. data/spec/lib/swagger/openapi_2_0_schema.json +8 -1
  161. data/spec/lib/swagger/rake_swagger_spec.rb +24 -9
  162. data/spec/lib/swagger/swagger_dsl_spec.rb +18 -12
  163. data/spec/lib/validators/array_validator_spec.rb +1 -1
  164. data/spec/spec_helper.rb +10 -32
  165. data/spec/support/custom_bool_validator.rb +17 -0
  166. data/spec/{controllers → test_engine}/memes_controller_spec.rb +1 -1
  167. metadata +169 -122
  168. data/Gemfile +0 -1
  169. data/gemfiles/Gemfile.rails42 +0 -14
  170. data/gemfiles/Gemfile.rails42.lock +0 -160
  171. data/gemfiles/Gemfile.rails52 +0 -9
  172. data/gemfiles/Gemfile.rails60 +0 -10
  173. data/gemfiles/Gemfile.rails61 +0 -10
  174. data/spec/lib/application_spec.rb +0 -49
  175. data/spec/lib/method_description_spec.rb +0 -98
  176. data/spec/lib/resource_description_spec.rb +0 -48
  177. data/spec/support/rails-42-ruby-26.rb +0 -15
  178. /data/spec/lib/{extractor → apipie/extractor/recorder}/middleware_spec.rb +0 -0
  179. /data/spec/lib/{extractor → apipie}/extractor_spec.rb +0 -0
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apipie::MethodDescription::ApisService do
4
+ let(:resource) {}
5
+ let(:controller_action) {}
6
+ let(:api_args) { [] }
7
+ let(:dsl) { { api_args: api_args } }
8
+ let(:service) { described_class.new(resource, controller_action, dsl) }
9
+
10
+ describe '#call' do
11
+ subject { service.call }
12
+
13
+ it { is_expected.to eq(api_args) }
14
+
15
+ context 'when api_from_routes is given' do
16
+ let(:controller) { UsersController }
17
+ let(:controller_action) { :show }
18
+ let(:resource) { Apipie::ResourceDescription.new(controller, 'dummy') }
19
+ let(:short_description) { 'Short description' }
20
+
21
+ let(:dsl) do
22
+ super().merge({
23
+ api_from_routes: {
24
+ desc: short_description,
25
+ options: {}
26
+ }
27
+ })
28
+ end
29
+
30
+ it 'returns an array of Apipie::MethodDescription::Api' do
31
+ expect(subject).to all(be_an_instance_of(Apipie::MethodDescription::Api))
32
+ expect(subject.count).to eq(1)
33
+ end
34
+
35
+ context 'Apipie::MethodDescription::Api' do
36
+ subject { service.call.first }
37
+
38
+ it 'has the correct values' do
39
+ expect(subject.short_description).to eq(short_description)
40
+ expect(subject.path).to eq('/api/users/:id')
41
+ expect(subject.from_routes).to eq(true)
42
+ expect(subject.options).to eq({ from_routes: true })
43
+ end
44
+
45
+ context "when it's from concern" do
46
+ let(:controller) { ConcernsController }
47
+ let(:controller_action) { :custom }
48
+ let(:dsl) { super().merge(from_concern: true ) }
49
+
50
+ it 'has the correct values' do
51
+ expect(subject.short_description).to eq(short_description)
52
+ expect(subject.path).to eq('/api/concern_resources/custom')
53
+ expect(subject.from_routes).to eq(true)
54
+ expect(subject.options).to eq({ from_routes: true })
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,133 @@
1
+ require "spec_helper"
2
+
3
+ describe Apipie::MethodDescription do
4
+ let(:dsl_data) { ActionController::Base.send(:_apipie_dsl_data_init) }
5
+ let(:deprecated_resource_description) { false }
6
+ let(:method_description_method) { :some_method }
7
+
8
+ let(:resource_description_dsl) do
9
+ ActionController::Base.send(:_apipie_dsl_data_init).merge(
10
+ {
11
+ deprecated: deprecated_resource_description
12
+ }
13
+ )
14
+ end
15
+
16
+ let(:resource_description) do
17
+ Apipie::ResourceDescription.new(
18
+ ApplicationController,
19
+ 'dummy',
20
+ resource_description_dsl
21
+ )
22
+ end
23
+
24
+ let(:method_description) do
25
+ Apipie::MethodDescription.new(
26
+ method_description_method,
27
+ resource_description,
28
+ dsl_data
29
+ )
30
+ end
31
+
32
+ describe '#to_json' do
33
+ describe 'metadata' do
34
+ subject { method_description.to_json[:metadata] }
35
+
36
+ it { is_expected.to be_nil }
37
+
38
+ context 'when meta are given' do
39
+ let(:meta) { { length: 32, weight: '830g' } }
40
+ let(:dsl_data) { super().merge(meta: meta) }
41
+
42
+ it { is_expected.to eq(meta) }
43
+ end
44
+ end
45
+
46
+ describe 'params' do
47
+ subject(:json_params) { method_description.to_json[:params].map { |h| h[:name] } }
48
+
49
+ let(:dsl_data) do
50
+ super().merge(
51
+ {
52
+ params: [
53
+ [:a, String, nil, {}, nil],
54
+ [:b, String, nil, {}, nil],
55
+ [:c, String, nil, {}, nil]
56
+ ]
57
+ }
58
+ )
59
+ end
60
+
61
+ it 'should be ordered' do
62
+ expect(json_params).to eq(%w[a b c])
63
+ end
64
+
65
+ context 'when param is only for response' do
66
+ let(:dsl_data) do
67
+ super().merge(
68
+ {
69
+ params: [
70
+ [:a, String, nil, { only_in: :request }, nil],
71
+ [:b, String, nil, { only_in: :response }, nil],
72
+ [:c, String, nil, {}, nil]
73
+ ]
74
+ }
75
+ )
76
+ end
77
+
78
+ it 'should ignore response-only parameters' do
79
+ expect(json_params).to eq(%w[a c])
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ describe '#method_apis_to_json' do
86
+ describe 'deprecated' do
87
+ subject { method_description.method_apis_to_json.first[:deprecated] }
88
+
89
+ let(:api_deprecated) { false }
90
+ let(:dsl_data) { super().merge(api_args: api_args) }
91
+
92
+ let(:api_args) do
93
+ [[:GET, "/foo/bar", "description", { deprecated: api_deprecated }]]
94
+ end
95
+
96
+ it { is_expected.to eq(false) }
97
+
98
+ context 'when api is deprecated' do
99
+ let(:api_deprecated) { true }
100
+
101
+ it { is_expected.to eq(true) }
102
+ end
103
+
104
+ context 'when resource description is deprecated' do
105
+ let(:deprecated_resource_description) { true }
106
+
107
+ it { is_expected.to eq(true) }
108
+ end
109
+ end
110
+ end
111
+
112
+ describe '#returns' do
113
+ subject(:method_desc) { method_description }
114
+
115
+ context 'when both :param_group and :array_of are specified' do
116
+ let(:returns) do
117
+ { 200 => [{ param_group: 'pet', array_of: 'pet' }, nil, nil] }
118
+ end
119
+
120
+ let(:dsl_data) { super().merge({ returns: returns }) }
121
+
122
+ it 'raises an error' do
123
+ expect { method_desc }.to raise_error(Apipie::ReturnsMultipleDefinitionError)
124
+ end
125
+ end
126
+ end
127
+
128
+ describe '#method_name' do
129
+ subject { method_description.method_name }
130
+
131
+ it { is_expected.to eq(method_description_method.to_s) }
132
+ end
133
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apipie::NoDocumentedMethod do
4
+ let(:error) { described_class.new(controller_name, method_name) }
5
+ let(:controller_name) { 'UserController' }
6
+ let(:method_name) { 'index' }
7
+
8
+ describe '#to_s' do
9
+ subject { error.to_s }
10
+
11
+ let(:error_message) do
12
+ "There is no documented method #{controller_name}##{method_name}"
13
+ end
14
+
15
+ it { is_expected.to eq(error_message) }
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ require "spec_helper"
2
+
3
+ describe Apipie::ParamDescription::Deprecation do
4
+ let(:info) { nil }
5
+ let(:deprecated_in) { nil }
6
+ let(:sunset_at) { nil }
7
+
8
+ let(:deprecation) do
9
+ described_class.new(
10
+ info: info,
11
+ deprecated_in: deprecated_in,
12
+ sunset_at: sunset_at
13
+ )
14
+ end
15
+
16
+ describe '#to_json' do
17
+ subject { deprecation.to_json }
18
+
19
+ it { is_expected.to eq({ info: nil, deprecated_in: nil, sunset_at: nil }) }
20
+
21
+ context 'when attributes are given' do
22
+ let(:info) { 'info' }
23
+ let(:deprecated_in) { '2.3' }
24
+ let(:sunset_at) { '3.0' }
25
+
26
+ it 'returns the correct attributes' do
27
+ expect(subject).to eq({ info: info, deprecated_in: deprecated_in, sunset_at: sunset_at })
28
+ end
29
+ end
30
+ end
31
+ end
@@ -113,6 +113,216 @@ describe Apipie::ParamDescription do
113
113
 
114
114
  end
115
115
 
116
+ describe 'validate' do
117
+ subject { param_description.validate(validation_value) }
118
+
119
+ let(:allow_blank) { nil }
120
+
121
+ let(:param_description) do
122
+ Apipie::ParamDescription.new(
123
+ method_desc,
124
+ :param,
125
+ validation_type,
126
+ allow_blank: allow_blank
127
+ )
128
+ end
129
+
130
+ context 'when allow_blank is ignored, as it was before 0.7.0' do
131
+ before { Apipie.configuration.ignore_allow_blank_false = true }
132
+ after { Apipie.configuration.ignore_allow_blank_false = false }
133
+
134
+ context 'when validation type is :boolean' do
135
+ let(:validation_type) { :boolean }
136
+
137
+ context 'when validation value is false' do
138
+ let(:validation_value) { false }
139
+
140
+ it 'should not raise an error' do
141
+ expect { subject }.not_to raise_error
142
+ end
143
+ end
144
+
145
+ context 'when validation value is an empty string' do
146
+ let(:validation_value) { '' }
147
+
148
+ it 'should raise an error' do
149
+ expect { subject }.to raise_error(Apipie::ParamInvalid)
150
+ end
151
+ end
152
+ end
153
+
154
+ context 'when validation type is a boolean array' do
155
+ let(:validation_type) { [true, false] }
156
+
157
+ context 'when validation value is false' do
158
+ let(:validation_value) { false }
159
+
160
+ it 'should not raise an error' do
161
+ expect { subject }.not_to raise_error
162
+ end
163
+ end
164
+
165
+ context 'when validation value is true' do
166
+ let(:validation_value) { true }
167
+
168
+ it 'should not raise an error' do
169
+ expect { subject }.not_to raise_error
170
+ end
171
+ end
172
+
173
+ context 'when validation value is an empty string' do
174
+ let(:validation_value) { '' }
175
+
176
+ it 'should raise an error' do
177
+ expect { subject }.to raise_error(Apipie::ParamInvalid)
178
+ end
179
+ end
180
+ end
181
+
182
+ context 'when validation type is String' do
183
+ let(:validation_type) { String }
184
+
185
+ context 'when validation value is empty string' do
186
+ let(:validation_value) { '' }
187
+
188
+ it 'should not raise an error' do
189
+ expect { subject }.not_to raise_error
190
+ end
191
+
192
+ context 'when allow_blank is specified as true' do
193
+ let(:allow_blank) { true }
194
+
195
+ it 'should not raise an error' do
196
+ expect { subject }.not_to raise_error
197
+ end
198
+ end
199
+ end
200
+ end
201
+ end
202
+
203
+ context 'when the validation type is :boolean' do
204
+ let(:validation_type) { :boolean }
205
+
206
+ context 'when validation value' do
207
+ let(:validation_value) { false }
208
+
209
+ it 'should not raise an error' do
210
+ expect { subject }.not_to raise_error
211
+ end
212
+
213
+ context 'when allow_blank is false' do
214
+ let(:allow_blank) { false }
215
+
216
+ it 'should not raise an error' do
217
+ expect { subject }.not_to raise_error
218
+ end
219
+ end
220
+
221
+ context 'when allow_blank is true' do
222
+ let(:allow_blank) { true }
223
+
224
+ it 'should not raise an error' do
225
+ expect { subject }.not_to raise_error
226
+ end
227
+ end
228
+ end
229
+
230
+ context 'when validation value is empty string' do
231
+ let(:validation_value) { '' }
232
+
233
+ it 'should raise an error' do
234
+ expect { subject }.to raise_error(Apipie::ParamInvalid)
235
+ end
236
+ end
237
+ end
238
+
239
+ context 'when validation type is a boolean array' do
240
+ let(:validation_type) { [true, false] }
241
+
242
+ context 'when validation value is false' do
243
+ let(:validation_value) { false }
244
+
245
+ it 'should not raise an error' do
246
+ expect { subject }.not_to raise_error
247
+ end
248
+ end
249
+
250
+ context 'when validation value is true' do
251
+ let(:validation_value) { true }
252
+
253
+ it 'should not raise an error' do
254
+ expect { subject }.not_to raise_error
255
+ end
256
+ end
257
+
258
+ context 'when validation value is an empty string' do
259
+ let(:validation_value) { '' }
260
+
261
+ it 'should raise an error' do
262
+ expect { subject }.to raise_error(Apipie::ParamInvalid)
263
+ end
264
+ end
265
+ end
266
+
267
+ context 'when the validation type is a custom one' do
268
+ let(:validation_type) { :custom_bool }
269
+
270
+ context 'when ignore_allow_blank? returning true' do
271
+ before do
272
+ allow(CustomBoolValidator).to receive(:ignore_allow_blank?).and_return(true)
273
+ end
274
+
275
+ context 'when a blank but valid value is passed' do
276
+ let(:validation_value) { false }
277
+
278
+ it 'should not raise an error' do
279
+ expect { subject }.not_to raise_error
280
+ end
281
+
282
+ context 'when allow_blank is false' do
283
+ let(:allow_blank) { false }
284
+
285
+ it 'should not raise an error' do
286
+ expect { subject }.not_to raise_error
287
+ end
288
+ end
289
+ end
290
+
291
+ context 'when a blank but invalid value is passed' do
292
+ let(:validation_value) { '' }
293
+
294
+ it 'should raise an error' do
295
+ expect { subject }.to raise_error(Apipie::ParamInvalid)
296
+ end
297
+ end
298
+ end
299
+ end
300
+
301
+ context 'when validation type is String' do
302
+ let(:validation_type) { String }
303
+
304
+ context 'when a blank but invalid value is passed' do
305
+ let(:validation_value) { '' }
306
+
307
+ it 'should raise an error' do
308
+ expect { subject }.to raise_error(Apipie::ParamInvalid)
309
+ end
310
+ end
311
+
312
+ context 'when allow_blank is specified as true' do
313
+ let(:allow_blank) { true }
314
+
315
+ context 'when and empty string is given' do
316
+ let(:validation_value) { '' }
317
+
318
+ it 'should not raise an error' do
319
+ expect { subject }.not_to raise_error
320
+ end
321
+ end
322
+ end
323
+ end
324
+ end
325
+
116
326
  describe "concern substitution" do
117
327
 
118
328
  let(:concern_dsl_data) { dsl_data.merge(:from_concern => true) }
@@ -151,7 +361,6 @@ describe Apipie::ParamDescription do
151
361
  end
152
362
  end
153
363
 
154
-
155
364
  describe "required_by_default config option" do
156
365
  context "parameters required by default" do
157
366
 
@@ -281,14 +490,13 @@ describe Apipie::ParamDescription do
281
490
  end
282
491
  end
283
492
 
284
-
285
493
  describe 'sub params' do
286
494
 
287
495
  context 'with HashValidator' do
288
496
 
289
497
  subject do
290
498
  Apipie::ParamDescription.new(method_desc, :param, Hash) do
291
- param :answer, Fixnum
499
+ param :answer, Integer
292
500
  end
293
501
  end
294
502
 
@@ -306,7 +514,7 @@ describe Apipie::ParamDescription do
306
514
 
307
515
  subject do
308
516
  Apipie::ParamDescription.new(method_desc, :param, Array) do
309
- param :answer, Fixnum
517
+ param :answer, Integer
310
518
  end
311
519
  end
312
520
 
@@ -336,10 +544,128 @@ describe Apipie::ParamDescription do
336
544
 
337
545
  describe "Array with classes" do
338
546
  it "should be valid for objects included in class array" do
339
- param = Apipie::ParamDescription.new(method_desc, :param, [Fixnum, String])
547
+ param = Apipie::ParamDescription.new(method_desc, :param, [Integer, String])
340
548
  expect { param.validate("1") }.not_to raise_error
341
- expect { param.validate(Fixnum) }.to raise_error(Apipie::ParamInvalid)
549
+ expect { param.validate(Integer) }.to raise_error(Apipie::ParamInvalid)
342
550
  end
343
551
  end
344
552
 
553
+ describe '#deprecated?' do
554
+ subject do
555
+ Apipie::ParamDescription.new(method_desc, :param, Integer, options)
556
+ end
557
+
558
+ let(:options) { {} }
559
+
560
+ it { is_expected.not_to be_deprecated }
561
+
562
+ context 'when deprecated option is passed' do
563
+ context 'and is true' do
564
+ let(:options) { { deprecated: true } }
565
+
566
+ it { is_expected.to be_deprecated }
567
+ end
568
+
569
+ context 'and is false' do
570
+ let(:options) { { deprecated: false } }
571
+
572
+ it { is_expected.not_to be_deprecated }
573
+ end
574
+
575
+ context 'and is a string' do
576
+ let(:options) { { deprecated: 'Some description' } }
577
+
578
+ it { is_expected.to be_deprecated }
579
+ end
580
+
581
+ context 'and deprecation options are given' do
582
+ let(:options) do
583
+ { deprecated: { in: '2.3', info: 'Something', sunset: '3.0' } }
584
+ end
585
+
586
+ it { is_expected.to be_deprecated }
587
+ end
588
+ end
589
+ end
590
+
591
+ describe '#deprecation' do
592
+ subject { param_description.deprecation }
593
+
594
+ let(:options) { {} }
595
+
596
+ let(:param_description) do
597
+ Apipie::ParamDescription.new(method_desc, :param, Integer, options)
598
+ end
599
+
600
+ it { is_expected.to be_blank }
601
+
602
+ context 'when deprecated option is passed' do
603
+ context 'and is true' do
604
+ let(:options) { { deprecated: true } }
605
+
606
+ it { is_expected.to be_blank }
607
+ end
608
+
609
+ context 'and is false' do
610
+ let(:options) { { deprecated: false } }
611
+
612
+ it { is_expected.to be_blank }
613
+ end
614
+
615
+ context 'and is a string' do
616
+ let(:options) { { deprecated: 'Some description' } }
617
+
618
+ it { is_expected.to be_an_instance_of(Apipie::ParamDescription::Deprecation) }
619
+ end
620
+
621
+ context 'and deprecation options are given' do
622
+ let(:options) do
623
+ { deprecated: { in: '2.3', info: 'Something', sunset: '3.0' } }
624
+ end
625
+
626
+ it { is_expected.to be_an_instance_of(Apipie::ParamDescription::Deprecation) }
627
+ end
628
+ end
629
+ end
630
+
631
+ describe '#required' do
632
+ subject { param_description.required }
633
+
634
+ let(:param_description) do
635
+ Apipie::ParamDescription.new(method_desc, :param, validator, options)
636
+ end
637
+
638
+ context 'when is passed in options' do
639
+ let(:validator) { String }
640
+
641
+ context 'when is false' do
642
+ let(:options) { { required: false } }
643
+
644
+ it { is_expected.to eq(false) }
645
+ end
646
+
647
+ context 'when is true' do
648
+ let(:options) { { required: true } }
649
+
650
+ it { is_expected.to eq(true) }
651
+ end
652
+ end
653
+
654
+ context 'when validator options are passed' do
655
+ let(:options) { { only_in: :response } }
656
+ let(:validator) { { array_of: String, required: required } }
657
+
658
+ context 'when required is false' do
659
+ let(:required) { false }
660
+
661
+ it { is_expected.to eq(false) }
662
+ end
663
+
664
+ context 'when required is true' do
665
+ let(:required) { true }
666
+
667
+ it { is_expected.to eq(true) }
668
+ end
669
+ end
670
+ end
345
671
  end
@@ -1,6 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "param groups" do
4
+ before { Apipie.reload_documentation }
4
5
 
5
6
  it "lets reuse the params description in more actions" do
6
7
  user_create_desc = Apipie["users#create"].params[:user]
@@ -43,17 +44,17 @@ describe "param groups" do
43
44
  end
44
45
 
45
46
  it "should replace parameter name in a group when it comes from concern" do
46
- expect(Apipie["overridden_concern_resources#update"].params.has_key?(:user)).to eq(true)
47
+ expect(Apipie["overridden_concern_resources#update"].params.key?(:user)).to eq(true)
47
48
  end
48
49
 
49
50
  it "shouldn't replace parameter name in a group redefined in the controller" do
50
- expect(Apipie["overridden_concern_resources#create"].params.has_key?(:concern)).to eq(true)
51
- expect(Apipie["overridden_concern_resources#create"].params.has_key?(:user)).to eq(false)
51
+ expect(Apipie["overridden_concern_resources#create"].params.key?(:concern)).to eq(true)
52
+ expect(Apipie["overridden_concern_resources#create"].params.key?(:user)).to eq(false)
52
53
  end
53
54
 
54
55
  it "shouldn't replace name of a parameter defined in the controller" do
55
- expect(Apipie["overridden_concern_resources#custom"].params.has_key?(:concern)).to eq(true)
56
- expect(Apipie["overridden_concern_resources#custom"].params.has_key?(:user)).to eq(false)
56
+ expect(Apipie["overridden_concern_resources#custom"].params.key?(:concern)).to eq(true)
57
+ expect(Apipie["overridden_concern_resources#custom"].params.key?(:user)).to eq(false)
57
58
  end
58
59
 
59
60
  end