apipie-rails 0.5.19 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +31 -0
  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 +2056 -0
  8. data/.vscode/settings.json +3 -0
  9. data/CHANGELOG.md +161 -0
  10. data/Gemfile +20 -0
  11. data/README.rst +117 -23
  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 +44 -33
  30. data/lib/apipie/error_description.rb +3 -3
  31. data/lib/apipie/errors.rb +17 -17
  32. data/lib/apipie/extractor/collector.rb +5 -6
  33. data/lib/apipie/extractor/recorder.rb +35 -8
  34. data/lib/apipie/extractor/writer.rb +15 -15
  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 +114 -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 +128 -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 +12 -10
  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 +10 -2
  81. data/lib/apipie/swagger_generator.rb +28 -691
  82. data/lib/apipie/validator.rb +41 -11
  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 +37 -32
  88. data/rel-eng/gem_release.ipynb +41 -9
  89. data/spec/controllers/api/v2/architectures_controller_spec.rb +10 -3
  90. data/spec/controllers/api/v2/empty_middle_controller_spec.rb +23 -0
  91. data/spec/controllers/api/v2/nested/resources_controller_spec.rb +18 -2
  92. data/spec/controllers/api/v2/sub/footguns_controller_spec.rb +19 -0
  93. data/spec/controllers/included_param_group_controller_spec.rb +13 -0
  94. data/spec/{lib/swagger/response_validation_spec.rb → controllers/pets_controller_spec.rb} +26 -32
  95. data/spec/controllers/users_controller_spec.rb +47 -6
  96. data/spec/dummy/Rakefile +1 -1
  97. data/spec/dummy/app/controllers/api/v2/architectures_controller.rb +2 -1
  98. data/spec/dummy/app/controllers/api/v2/base_controller.rb +6 -0
  99. data/spec/dummy/app/controllers/api/v2/empty_middle_controller.rb +14 -0
  100. data/spec/dummy/app/controllers/api/v2/nested/resources_controller.rb +2 -2
  101. data/spec/dummy/app/controllers/api/v2/sub/footguns_controller.rb +30 -0
  102. data/spec/dummy/app/controllers/concerns_controller.rb +1 -1
  103. data/spec/dummy/app/controllers/{concerns/extending_concern.rb → extending_concern.rb} +0 -2
  104. data/spec/dummy/app/controllers/included_param_group_controller.rb +19 -0
  105. data/spec/dummy/app/controllers/overridden_concerns_controller.rb +2 -2
  106. data/spec/dummy/app/controllers/pets_controller.rb +5 -5
  107. data/spec/dummy/app/controllers/pets_using_self_describing_classes_controller.rb +2 -2
  108. data/spec/dummy/app/controllers/{concerns/sample_controller.rb → sample_controller.rb} +0 -2
  109. data/spec/dummy/app/controllers/twitter_example_controller.rb +2 -2
  110. data/spec/dummy/app/controllers/users_controller.rb +17 -5
  111. data/spec/dummy/app/helpers/random_param_group.rb +8 -0
  112. data/spec/dummy/components/test_engine/test_engine.gemspec +1 -1
  113. data/spec/dummy/config/application.rb +2 -5
  114. data/spec/dummy/config/boot.rb +2 -2
  115. data/spec/dummy/config/environment.rb +1 -1
  116. data/spec/dummy/config/environments/development.rb +0 -3
  117. data/spec/dummy/config/environments/production.rb +0 -3
  118. data/spec/dummy/config/environments/test.rb +0 -5
  119. data/spec/dummy/config/initializers/apipie.rb +2 -2
  120. data/spec/dummy/config/routes.rb +8 -0
  121. data/spec/dummy/config.ru +1 -1
  122. data/spec/dummy/script/rails +2 -2
  123. data/spec/{controllers → lib/apipie}/apipies_controller_spec.rb +95 -23
  124. data/spec/lib/apipie/application_spec.rb +62 -0
  125. data/spec/lib/apipie/configuration_spec.rb +38 -0
  126. data/spec/lib/apipie/extractor/collector_spec.rb +57 -0
  127. data/spec/lib/apipie/extractor/recorder_spec.rb +77 -0
  128. data/spec/lib/{extractor → apipie/extractor}/writer_spec.rb +8 -6
  129. data/spec/lib/{extractor → apipie}/extractor_spec.rb +1 -1
  130. data/spec/lib/{file_handler_spec.rb → apipie/file_handler_spec.rb} +7 -0
  131. data/spec/lib/apipie/generator/swagger/config_spec.rb +19 -0
  132. data/spec/lib/apipie/generator/swagger/context_spec.rb +56 -0
  133. data/spec/lib/apipie/generator/swagger/method_description/api_schema_service_spec.rb +119 -0
  134. data/spec/lib/apipie/generator/swagger/method_description/response_schema_service_spec.rb +105 -0
  135. data/spec/lib/apipie/generator/swagger/operation_id_spec.rb +63 -0
  136. data/spec/lib/apipie/generator/swagger/param_description/builder_spec.rb +215 -0
  137. data/spec/lib/apipie/generator/swagger/param_description/composite_spec.rb +95 -0
  138. data/spec/lib/apipie/generator/swagger/param_description/description_spec.rb +79 -0
  139. data/spec/lib/apipie/generator/swagger/param_description/in_spec.rb +86 -0
  140. data/spec/lib/apipie/generator/swagger/param_description/name_spec.rb +81 -0
  141. data/spec/lib/apipie/generator/swagger/param_description/type_spec.rb +183 -0
  142. data/spec/lib/apipie/generator/swagger/param_description_spec.rb +28 -0
  143. data/spec/lib/apipie/generator/swagger/path_decorator_spec.rb +57 -0
  144. data/spec/lib/apipie/generator/swagger/referenced_definitions_spec.rb +35 -0
  145. data/spec/lib/apipie/generator/swagger/resource_description_composite_spec.rb +37 -0
  146. data/spec/lib/apipie/generator/swagger/resource_descriptions_collection_spec.rb +57 -0
  147. data/spec/lib/apipie/generator/swagger/schema_spec.rb +89 -0
  148. data/spec/lib/apipie/generator/swagger/type_extractor_spec.rb +38 -0
  149. data/spec/lib/apipie/generator/swagger/warning_spec.rb +51 -0
  150. data/spec/lib/apipie/generator/swagger/warning_writer_spec.rb +71 -0
  151. data/spec/lib/apipie/method_description/apis_service_spec.rb +60 -0
  152. data/spec/lib/apipie/method_description_spec.rb +133 -0
  153. data/spec/lib/apipie/no_documented_method_spec.rb +17 -0
  154. data/spec/lib/apipie/param_description/deprecation_spec.rb +31 -0
  155. data/spec/lib/{param_description_spec.rb → apipie/param_description_spec.rb} +332 -6
  156. data/spec/lib/{param_group_spec.rb → apipie/param_group_spec.rb} +6 -5
  157. data/spec/lib/apipie/resource_description_spec.rb +91 -0
  158. data/spec/lib/apipie/response_does_not_match_swagger_schema_spec.rb +35 -0
  159. data/spec/lib/apipie/swagger_generator_spec.rb +94 -0
  160. data/spec/lib/{validator_spec.rb → apipie/validator_spec.rb} +48 -12
  161. data/spec/lib/rake_spec.rb +3 -5
  162. data/spec/lib/swagger/openapi_2_0_schema.json +8 -1
  163. data/spec/lib/swagger/rake_swagger_spec.rb +30 -10
  164. data/spec/lib/swagger/swagger_dsl_spec.rb +18 -12
  165. data/spec/lib/validators/array_validator_spec.rb +1 -1
  166. data/spec/spec_helper.rb +10 -32
  167. data/spec/support/custom_bool_validator.rb +17 -0
  168. data/spec/{controllers → test_engine}/memes_controller_spec.rb +1 -1
  169. metadata +173 -125
  170. data/.travis.yml +0 -41
  171. data/Gemfile +0 -1
  172. data/Gemfile.rails41 +0 -7
  173. data/Gemfile.rails42 +0 -14
  174. data/Gemfile.rails50 +0 -9
  175. data/Gemfile.rails51 +0 -9
  176. data/Gemfile.rails60 +0 -10
  177. data/Gemfile.rails61 +0 -10
  178. data/spec/lib/application_spec.rb +0 -49
  179. data/spec/lib/method_description_spec.rb +0 -98
  180. data/spec/lib/resource_description_spec.rb +0 -48
  181. /data/spec/lib/{extractor → apipie/extractor/recorder}/middleware_spec.rb +0 -0
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe 'rake tasks' do
4
4
  include_context "rake"
5
5
 
6
- let(:doc_path) { "user_specified_doc_path" }
6
+ let(:doc_path) { 'tmp/user_specified_doc_path' }
7
7
 
8
8
  before do
9
9
  Apipie.configuration.doc_path = doc_path
@@ -18,7 +18,7 @@ describe 'rake tasks' do
18
18
  end
19
19
 
20
20
  let(:doc_output) do
21
- File.join(::Rails.root, doc_path, 'apidoc')
21
+ File.join(Rails.root, doc_path, 'apidoc')
22
22
  end
23
23
 
24
24
  after do
@@ -49,9 +49,7 @@ describe 'rake tasks' do
49
49
  end
50
50
 
51
51
  describe 'apipie:cache' do
52
- let(:cache_output) do
53
- File.join(::Rails.root, 'public', 'apipie-cache')
54
- end
52
+ let(:cache_output) { Apipie.configuration.cache_dir }
55
53
 
56
54
  let(:apidoc_html) do
57
55
  File.read("#{cache_output}.html")
@@ -996,7 +996,14 @@
996
996
  "$ref": "http://json-schema.org/draft-04/schema#/definitions/positiveIntegerDefault0"
997
997
  },
998
998
  "required": {
999
- "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray"
999
+ "anyOf": [
1000
+ {
1001
+ "$ref": "http://json-schema.org/draft-04/schema#/definitions/stringArray"
1002
+ },
1003
+ {
1004
+ "type": "boolean"
1005
+ }
1006
+ ]
1000
1007
  },
1001
1008
  "enum": {
1002
1009
  "$ref": "http://json-schema.org/draft-04/schema#/properties/enum"
@@ -1,18 +1,18 @@
1
1
  require 'spec_helper'
2
2
  require "json-schema"
3
3
 
4
- require File.expand_path("../../../dummy/app/controllers/twitter_example_controller.rb", __FILE__)
5
- require File.expand_path("../../../dummy/app/controllers/users_controller.rb", __FILE__)
6
- require File.expand_path("../../../dummy/app/controllers/pets_controller.rb", __FILE__)
4
+ require File.expand_path('../../dummy/app/controllers/twitter_example_controller.rb', __dir__)
5
+ require File.expand_path('../../dummy/app/controllers/users_controller.rb', __dir__)
6
+ require File.expand_path('../../dummy/app/controllers/pets_controller.rb', __dir__)
7
7
 
8
8
  describe 'rake tasks' do
9
9
  include_context "rake"
10
10
 
11
- let(:doc_path) { "user_specified_doc_path" }
11
+ let(:doc_path) { 'tmp/user_specified_doc_path' }
12
12
 
13
13
  before do
14
14
  Apipie.configuration.doc_path = doc_path
15
- Apipie.configuration.swagger_suppress_warnings = true
15
+ Apipie.configuration.generator.swagger.suppress_warnings = true
16
16
  allow(Apipie).to receive(:reload_documentation)
17
17
  subject.invoke(*task_args)
18
18
  end
@@ -37,11 +37,11 @@ describe 'rake tasks' do
37
37
  end
38
38
 
39
39
  let(:doc_output) do
40
- File.join(::Rails.root, doc_path, 'apidoc')
40
+ File.join(Rails.root, doc_path, 'apidoc')
41
41
  end
42
42
 
43
43
  let(:ref_output) do
44
- File.join(::Rails.root, doc_path, 'apidoc_ref')
44
+ File.join(Rails.root, doc_path, 'apidoc_ref')
45
45
  end
46
46
 
47
47
 
@@ -51,6 +51,17 @@ describe 'rake tasks' do
51
51
  expect(param[field]).to eq(value)
52
52
  end
53
53
 
54
+ def expect_array_param_def(http_method, path, param_name, value)
55
+ params = apidoc_swagger["paths"][path][http_method]["parameters"]
56
+ param = params.select { |p| p if p["name"] == param_name }[0]
57
+
58
+ expect(param['type']).to eq('array')
59
+ expect(param['items']).to eq(
60
+ 'type' => 'string',
61
+ 'enum' => value
62
+ )
63
+ end
64
+
54
65
  def expect_tags_def(http_method, path, value)
55
66
  params = apidoc_swagger["paths"][path][http_method]["tags"]
56
67
  expect(params).to eq(value)
@@ -71,6 +82,10 @@ describe 'rake tasks' do
71
82
  expect(param[field]).to eq(value)
72
83
  end
73
84
 
85
+ def expect_response_params_def(http_method, path, response_code, param_name, field, value)
86
+ param = apidoc_swagger["paths"][path][http_method]["responses"][response_code.to_s]["schema"]["properties"][param_name]
87
+ expect(param[field]).to eq(value)
88
+ end
74
89
 
75
90
  describe 'apipie:static_swagger_json[development,json,_tmp]' do
76
91
  it "generates static swagger files for the default version of apipie docs" do
@@ -91,9 +106,10 @@ describe 'rake tasks' do
91
106
 
92
107
  expect_param_def("get", "/users/by_department", "department", "in", "query")
93
108
  expect_param_def("get", "/users/by_department", "department", "enum",
94
- ["finance", "operations", "sales", "marketing", "HR"])
109
+ %w[finance operations sales marketing HR])
95
110
 
96
111
  expect_tags_def("get", "/twitter_example/{id}/followers", %w[twitter_example following index search])
112
+ expect_response_params_def("get", "/pets/{id}/as_properties", 200, "pet_name", "example", "mypet")
97
113
  end
98
114
 
99
115
  it "generates a valid swagger file" do
@@ -117,7 +133,11 @@ describe 'rake tasks' do
117
133
  expect_param_def("put", "/users/{id}", "oauth", "in", "formData")
118
134
  expect_param_def("get", "/users/by_department", "department", "in", "query")
119
135
  expect_param_def("get", "/users/by_department", "department", "enum",
120
- ["finance", "operations", "sales", "marketing", "HR"])
136
+ %w[finance operations sales marketing HR])
137
+
138
+ expect_param_def("get", "/users/in_departments", "departments", "in", "query")
139
+ expect_array_param_def("get", "/users/in_departments", "departments",
140
+ %w[finance operations sales marketing HR])
121
141
 
122
142
  expect_tags_def("get", "/twitter_example/{id}/followers", %w[twitter_example following index search])
123
143
 
@@ -131,7 +151,7 @@ describe 'rake tasks' do
131
151
 
132
152
  describe 'apipie:did_swagger_change[development,form_data,_tmp]' do
133
153
  it "keeps a reference file" do
134
- expect(Pathname(ref_output).children.count).to eq(2) # one file for each language
154
+ expect(Pathname(ref_output).children.count).to eq(2) # one file for each language
135
155
  end
136
156
  end
137
157
  end
@@ -6,7 +6,7 @@ describe "Swagger Responses" do
6
6
  let(:desc) { Apipie.get_resource_description(controller_class, Apipie.configuration.default_version) }
7
7
 
8
8
  let(:swagger) {
9
- Apipie.configuration.swagger_suppress_warnings = true
9
+ Apipie.configuration.generator.swagger.suppress_warnings = true
10
10
  Apipie.to_swagger_json(Apipie.configuration.default_version, controller_class.to_s.underscore.sub("_controller", ""))
11
11
  }
12
12
 
@@ -24,20 +24,20 @@ describe "Swagger Responses" do
24
24
  schema
25
25
  end
26
26
 
27
- def swagger_response_for(path, code=200, method='get')
27
+ def swagger_response_for(path, code = 200, method = 'get')
28
28
  response = swagger[:paths][path][method][:responses][code]
29
29
  response[:schema] = resolve_refs(response[:schema])
30
30
  response
31
31
  end
32
32
 
33
- def swagger_params_for(path, method='get')
33
+ def swagger_params_for(path, method = 'get')
34
34
  swagger[:paths][path][method][:parameters]
35
35
  end
36
36
 
37
- def swagger_param_by_name(param_name, path, method='get')
37
+ def swagger_param_by_name(param_name, path, method = 'get')
38
38
  params = swagger_params_for(path, method)
39
39
  matching = params.select{|p| p[:name] == param_name }
40
- raise "multiple params named [#{param_name}] in swagger definition for [#{method } #{path}]" if matching.length > 1
40
+ raise "multiple params named [#{param_name}] in swagger definition for [#{method} #{path}]" if matching.length > 1
41
41
 
42
42
  nil if matching.length == 0
43
43
 
@@ -72,7 +72,7 @@ describe "Swagger Responses" do
72
72
  deep_match?(actual, expected)
73
73
  end
74
74
 
75
- def deep_match?(actual, expected, breadcrumb=[])
75
+ def deep_match?(actual, expected, breadcrumb = [])
76
76
  pending_params = actual.params_ordered.dup
77
77
  expected.each do |expected_param|
78
78
  expected_param_name = expected_param.is_a?(Hash) ? expected_param.keys.first : expected_param
@@ -141,7 +141,7 @@ describe "Swagger Responses" do
141
141
 
142
142
  a_schema = resolve_refs(schema[:items])
143
143
  expect(a_schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
144
- expect(a_schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => ['dog','cat','iguana','kangaroo']})
144
+ expect(a_schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
145
145
  end
146
146
 
147
147
 
@@ -210,7 +210,7 @@ describe "Swagger Responses" do
210
210
 
211
211
  schema = response[:schema]
212
212
  expect(schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
213
- expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => ['dog','cat','iguana','kangaroo']})
213
+ expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
214
214
  end
215
215
 
216
216
  it 'should have the 404 response description overridden' do
@@ -247,7 +247,7 @@ describe "Swagger Responses" do
247
247
 
248
248
  schema = response[:schema]
249
249
  expect(schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
250
- expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => ['dog','cat','iguana','kangaroo']})
250
+ expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
251
251
  end
252
252
  end
253
253
 
@@ -282,7 +282,7 @@ describe "Swagger Responses" do
282
282
  schema = response[:schema]
283
283
  expect(schema).to have_field(:pet_id, 'number', {:description => 'id of pet'})
284
284
  expect(schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
285
- expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => ['dog','cat','iguana','kangaroo']})
285
+ expect(schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
286
286
  expect(schema).not_to have_field(:partial_match_allowed, 'boolean', {:required => false})
287
287
  end
288
288
 
@@ -338,6 +338,7 @@ describe "Swagger Responses" do
338
338
 
339
339
  expect(returns_obj).to match_field_structure([:pet_name, :animal_type])
340
340
  end
341
+
341
342
  it 'should have the 201 response described in the swagger' do
342
343
  response = swagger_response_for('/pets/{id}/extra_info', 201)
343
344
  expect(response[:description]).to eq("Found a pet")
@@ -359,6 +360,7 @@ describe "Swagger Responses" do
359
360
  {:pet_measurements => [:weight, :height, :num_legs]}
360
361
  ])
361
362
  end
363
+
362
364
  it 'should have the 202 response described in the swagger' do
363
365
  response = swagger_response_for('/pets/{id}/extra_info', 202)
364
366
  expect(response[:description]).to eq('Accepted')
@@ -388,6 +390,7 @@ describe "Swagger Responses" do
388
390
  {:additional_histories => [:did_visit_vet, :avg_meals_per_day]}
389
391
  ])
390
392
  end
393
+
391
394
  it 'should have the 203 response described in the swagger' do
392
395
  response = swagger_response_for('/pets/{id}/extra_info', 203)
393
396
  expect(response[:description]).to eq('Non-Authoritative Information')
@@ -424,12 +427,13 @@ describe "Swagger Responses" do
424
427
 
425
428
  expect(returns_obj).to match_field_structure([:int_array, :enum_array])
426
429
  end
430
+
427
431
  it 'should have the 204 response described in the swagger' do
428
432
  response = swagger_response_for('/pets/{id}/extra_info', 204)
429
433
 
430
434
  schema = response[:schema]
431
435
  expect(schema).to have_field(:int_array, 'array', {items: {type: 'number'}})
432
- expect(schema).to have_field(:enum_array, 'array', {items: {type: 'string', enum: ['v1','v2','v3']}})
436
+ expect(schema).to have_field(:enum_array, 'array', {items: {type: 'string', enum: %w[v1 v2 v3]}})
433
437
  end
434
438
 
435
439
 
@@ -444,6 +448,7 @@ describe "Swagger Responses" do
444
448
  :num_fleas
445
449
  ])
446
450
  end
451
+
447
452
  it 'should have the 422 response described in the swagger' do
448
453
  response = swagger_response_for('/pets/{id}/extra_info', 422)
449
454
  expect(response[:description]).to eq('Fleas were discovered on the pet')
@@ -546,7 +551,7 @@ describe "Swagger Responses" do
546
551
 
547
552
  a_schema = schema[:items]
548
553
  expect(a_schema).to have_field(:pet_name, 'string', {:description => 'Name of pet', :required => false})
549
- expect(a_schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => ['dog','cat','iguana','kangaroo']})
554
+ expect(a_schema).to have_field(:animal_type, 'string', {:description => 'Type of pet', :enum => %w[dog cat iguana kangaroo]})
550
555
  end
551
556
  end
552
557
 
@@ -568,6 +573,7 @@ describe "Swagger Responses" do
568
573
  {:pet_measurements => [:weight, :height, :num_legs]}
569
574
  ])
570
575
  end
576
+
571
577
  it 'should have the 200 response described in the swagger' do
572
578
  response = swagger_response_for('/pets_with_measurements_described_as_class/{id}', 200)
573
579
  expect(response[:description]).to eq('measurements of the pet')
@@ -30,7 +30,7 @@ module Apipie::Validator
30
30
  let(:type) { String }
31
31
 
32
32
  it "accepts array of specified type" do
33
- expect(validator.validate(['string1', 'string2'])).to eq(true)
33
+ expect(validator.validate(%w[string1 string2])).to eq(true)
34
34
  end
35
35
 
36
36
  it "accepts empty array" do
data/spec/spec_helper.rb CHANGED
@@ -1,40 +1,19 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
3
 
4
+ require 'simplecov'
5
+ SimpleCov.minimum_coverage 91
6
+ SimpleCov.start
7
+
4
8
  ENV["RAILS_ENV"] ||= 'test'
5
- APIPIE_ROOT = File.expand_path('../..', __FILE__)
6
- require File.expand_path("../dummy/config/environment", __FILE__)
9
+ APIPIE_ROOT = File.expand_path('..', __dir__)
10
+ require File.expand_path('dummy/config/environment', __dir__)
7
11
 
8
12
  require 'rspec/rails'
9
13
 
10
14
  require 'apipie-rails'
11
15
  require 'test_engine'
12
16
 
13
- module Rails4Compatibility
14
- module Testing
15
- def process(*args)
16
- compatible_request(*args) { |*new_args| super(*new_args) }
17
- end
18
-
19
- def compatible_request(method, action, hash = {})
20
- if hash.is_a?(Hash)
21
- if Gem::Version.new(Rails.version) < Gem::Version.new('5.0.0')
22
- hash = hash.dup
23
- hash.merge!(hash.delete(:params) || {})
24
- elsif hash.key?(:params)
25
- hash = { :params => hash }
26
- end
27
- end
28
- if hash.empty?
29
- yield method, action
30
- else
31
- yield method, action, hash
32
- end
33
- end
34
- end
35
- end
36
-
37
-
38
17
  #
39
18
  # Matcher to validate the properties (name, type and options) of a single field in the
40
19
  # internal representation of a swagger schema
@@ -45,7 +24,7 @@ end
45
24
  #
46
25
  # will verify that the selected response schema includes a required string field called 'pet_name'
47
26
  #
48
- RSpec::Matchers.define :have_field do |name, type, opts={}|
27
+ RSpec::Matchers.define :have_field do |name, type, opts = {}|
49
28
  def fail(msg)
50
29
  @fail_message = msg
51
30
  false
@@ -76,14 +55,14 @@ end
76
55
 
77
56
  # Requires supporting ruby files with custom matchers and macros, etc,
78
57
  # in spec/support/ and its subdirectories.
79
- Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f}
58
+ Dir[File.expand_path('support/**/*.rb', __dir__)].sort.each {|f| require f}
80
59
 
81
60
  RSpec.configure do |config|
82
61
 
83
62
  config.mock_with :rspec
84
63
 
85
64
  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
86
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
65
+ config.fixture_path = "#{Rails.root}/spec/fixtures"
87
66
 
88
67
  # If you're not using ActiveRecord, or you'd prefer not to run each of your
89
68
  # examples within a transaction, remove the following line or assign false
@@ -107,5 +86,4 @@ RSpec.configure do |config|
107
86
  config.infer_spec_type_from_file_location!
108
87
  end
109
88
 
110
- require 'action_controller/test_case.rb'
111
- ActionController::TestCase::Behavior.send(:prepend, Rails4Compatibility::Testing)
89
+ require 'action_controller/test_case'
@@ -0,0 +1,17 @@
1
+ class CustomBoolValidator < Apipie::Validator::BaseValidator
2
+ def validate(value)
3
+ value.in?([true, false])
4
+ end
5
+
6
+ def self.build(param_description, argument, options, block)
7
+ new(param_description) if argument == :custom_bool
8
+ end
9
+
10
+ def description
11
+ "Must be a boolean."
12
+ end
13
+
14
+ def ignore_allow_blank?
15
+ true
16
+ end
17
+ end
@@ -4,7 +4,7 @@ describe TestEngine::MemesController do
4
4
 
5
5
  describe "#index" do
6
6
  it "should have the full mounted path of engine" do
7
- Apipie.routes_for_action(TestEngine::MemesController, :index, {}).first[:path].should eq("/test/memes")
7
+ expect(Apipie.routes_for_action(TestEngine::MemesController, :index, {}).first[:path]).to eq("/test/memes")
8
8
  end
9
9
  end
10
10
  end