apipie-rails 0.8.2 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rubocop-challenger.yml +28 -0
  3. data/.rubocop.yml +37 -0
  4. data/.rubocop_todo.yml +2001 -0
  5. data/CHANGELOG.md +14 -0
  6. data/README.rst +2 -2
  7. data/Rakefile +0 -5
  8. data/apipie-rails.gemspec +10 -7
  9. data/lib/apipie/dsl_definition.rb +3 -3
  10. data/lib/apipie/extractor/writer.rb +2 -2
  11. data/lib/apipie/generator/generator.rb +2 -0
  12. data/lib/apipie/generator/swagger/swagger.rb +2 -0
  13. data/lib/apipie/generator/swagger/type.rb +16 -0
  14. data/lib/apipie/generator/swagger/type_extractor.rb +70 -0
  15. data/lib/apipie/generator/swagger/warning.rb +77 -0
  16. data/lib/apipie/generator/swagger/warning_writer.rb +48 -0
  17. data/lib/apipie/method_description/api.rb +12 -0
  18. data/lib/apipie/method_description/apis_service.rb +82 -0
  19. data/lib/apipie/method_description.rb +1 -46
  20. data/lib/apipie/swagger_generator.rb +76 -81
  21. data/lib/apipie/validator.rb +4 -0
  22. data/lib/apipie/version.rb +1 -1
  23. data/lib/apipie-rails.rb +9 -1
  24. data/lib/generators/apipie/install/install_generator.rb +1 -1
  25. data/lib/generators/apipie/views_generator.rb +1 -1
  26. data/lib/tasks/apipie.rake +2 -2
  27. data/spec/dummy/Rakefile +1 -1
  28. data/spec/dummy/components/test_engine/test_engine.gemspec +1 -1
  29. data/spec/dummy/config/application.rb +1 -1
  30. data/spec/dummy/config/boot.rb +2 -2
  31. data/spec/dummy/config/environment.rb +1 -1
  32. data/spec/dummy/config/routes.rb +1 -0
  33. data/spec/dummy/config.ru +1 -1
  34. data/spec/dummy/script/rails +2 -2
  35. data/spec/lib/application_spec.rb +1 -1
  36. data/spec/lib/extractor/writer_spec.rb +7 -5
  37. data/spec/lib/generator/swagger/type_extractor_spec.rb +61 -0
  38. data/spec/lib/generator/swagger/warning_spec.rb +51 -0
  39. data/spec/lib/generator/swagger/warning_writer_spec.rb +59 -0
  40. data/spec/lib/method_description/apis_service_spec.rb +60 -0
  41. data/spec/lib/rake_spec.rb +1 -1
  42. data/spec/lib/swagger/rake_swagger_spec.rb +4 -4
  43. data/spec/spec_helper.rb +4 -4
  44. metadata +39 -38
@@ -128,33 +128,75 @@ module Apipie
128
128
  method.resource.controller.name + "#" + method.method
129
129
  end
130
130
 
131
+ def warn_missing_method_summary
132
+ warn(Apipie::Generator::Swagger::Warning::MISSING_METHOD_SUMMARY_CODE)
133
+ end
131
134
 
132
- def warn_missing_method_summary() warn 100, "missing short description for method"; end
133
- def warn_added_missing_slash(path) warn 101,"added missing / at beginning of path: #{path}"; end
134
- def warn_no_return_codes_specified() warn 102,"no return codes ('errors') specified"; end
135
- def warn_hash_without_internal_typespec(param_name) warn 103,"the parameter :#{param_name} is a generic Hash without an internal type specification"; end
136
- def warn_optional_param_in_path(param_name) warn 104, "the parameter :#{param_name} is 'in-path'. Ignoring 'not required' in DSL"; end
137
- def warn_optional_without_default_value(param_name) warn 105,"the parameter :#{param_name} is optional but default value is not specified (use :default_value => ...)"; end
138
- def warn_param_ignored_in_form_data(param_name) warn 106,"ignoring param :#{param_name} -- cannot include Hash without fields in a formData specification"; end
139
- def warn_path_parameter_not_described(name,path) warn 107,"the parameter :#{name} appears in the path #{path} but is not described"; end
140
- def warn_inferring_boolean(name) warn 108,"the parameter [#{name}] is Enum with [true,false] values. Inferring 'boolean'"; end
141
-
142
- def warn(warning_num, msg)
143
- suppress = Apipie.configuration.swagger_suppress_warnings
144
- return if suppress == true
145
- return if suppress.is_a?(Array) && suppress.include?(warning_num)
135
+ def warn_added_missing_slash(path)
136
+ warn(
137
+ Apipie::Generator::Swagger::Warning::ADDED_MISSING_SLASH_CODE,
138
+ { path: path }
139
+ )
140
+ end
146
141
 
147
- method_id = ruby_name_for_method(@current_method)
148
- warning_id = "#{method_id}#{warning_num}#{msg}"
142
+ def warn_no_return_codes_specified
143
+ warn(Apipie::Generator::Swagger::Warning::NO_RETURN_CODES_SPECIFIED_CODE)
144
+ end
149
145
 
150
- if @issued_warnings.include?(warning_id)
151
- # Already issued this warning for the current method
152
- return
153
- end
146
+ def warn_hash_without_internal_typespec(param_name)
147
+ warn(
148
+ Apipie::Generator::Swagger::Warning::HASH_WITHOUT_INTERNAL_TYPESPEC_CODE,
149
+ { parameter: param_name }
150
+ )
151
+ end
152
+
153
+ def warn_optional_param_in_path(param_name)
154
+ warn(
155
+ Apipie::Generator::Swagger::Warning::OPTIONAL_PARAM_IN_PATH_CODE,
156
+ { parameter: param_name }
157
+ )
158
+ end
159
+
160
+ def warn_optional_without_default_value(param_name)
161
+ warn(
162
+ Apipie::Generator::Swagger::Warning::OPTIONAL_WITHOUT_DEFAULT_VALUE_CODE,
163
+ { parameter: param_name }
164
+ )
165
+ end
166
+
167
+ def warn_param_ignored_in_form_data(param_name)
168
+ warn(
169
+ Apipie::Generator::Swagger::Warning::PARAM_IGNORED_IN_FORM_DATA_CODE,
170
+ { parameter: param_name }
171
+ )
172
+ end
173
+
174
+ def warn_path_parameter_not_described(name, path)
175
+ warn(
176
+ Apipie::Generator::Swagger::Warning::PATH_PARAM_NOT_DESCRIBED_CODE,
177
+ { name: name, path: path }
178
+ )
179
+ end
154
180
 
155
- print "WARNING (#{warning_num}): [#{method_id}] -- #{msg}\n"
156
- @issued_warnings.push(warning_id)
157
- @warnings_issued = true
181
+ def warn_inferring_boolean(name)
182
+ warn(
183
+ Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE,
184
+ { name: name }
185
+ )
186
+ end
187
+
188
+ # @param [Integer] warning_code
189
+ # @param [Hash] message_attributes
190
+ def warn(warning_code, message_attributes = {})
191
+ Apipie::Generator::Swagger::Warning.for_code(
192
+ warning_code,
193
+ ruby_name_for_method(@current_method),
194
+ message_attributes
195
+ ).warn_through_writer
196
+
197
+ @warnings_issued = Apipie::Generator::Swagger::WarningWriter.
198
+ instance.
199
+ issued_warnings?
158
200
  end
159
201
 
160
202
  def info(msg)
@@ -276,68 +318,21 @@ module Apipie
276
318
  http_method.downcase + path.gsub(/\//,'_').gsub(/:(\w+)/, '\1').gsub(/_$/,'')
277
319
  end
278
320
 
279
- class SwaggerTypeWithFormat
280
- attr_reader :str_format
281
- def initialize(type, str_format)
282
- @type = type
283
- @str_format = str_format
284
- end
285
-
286
- def to_s
287
- @type
288
- end
289
-
290
- def ==(other)
291
- other.to_s == self.to_s
292
- end
293
- end
294
-
295
- def lookup
296
- @lookup ||= {
297
- numeric: "number",
298
- hash: "object",
299
- array: "array",
300
-
301
- # see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#data-types
302
- integer: SwaggerTypeWithFormat.new("integer", "int32"),
303
- long: SwaggerTypeWithFormat.new("integer", "int64"),
304
- number: SwaggerTypeWithFormat.new("number", nil), # here just for completeness
305
- float: SwaggerTypeWithFormat.new("number", "float"),
306
- double: SwaggerTypeWithFormat.new("number", "double"),
307
- string: SwaggerTypeWithFormat.new("string", nil), # here just for completeness
308
- byte: SwaggerTypeWithFormat.new("string", "byte"),
309
- binary: SwaggerTypeWithFormat.new("string", "binary"),
310
- boolean: SwaggerTypeWithFormat.new("boolean", nil), # here just for completeness
311
- date: SwaggerTypeWithFormat.new("string", "date"),
312
- dateTime: SwaggerTypeWithFormat.new("string", "date-time"),
313
- password: SwaggerTypeWithFormat.new("string", "password"),
314
- }
315
- end
316
-
317
-
318
321
  def swagger_param_type(param_desc)
319
- if param_desc.nil?
320
- raise("problem")
321
- end
322
-
323
- v = param_desc.validator
324
- if v.nil?
325
- return "string"
322
+ if param_desc.blank?
323
+ raise ArgumentError, 'param_desc is required'
326
324
  end
327
325
 
328
- if v.class == Apipie::Validator::EnumValidator || (v.respond_to?(:is_enum?) && v.is_enum?)
329
- if v.values - [true, false] == [] && [true, false] - v.values == []
330
- warn_inferring_boolean(param_desc.name)
331
- return "boolean"
332
- else
333
- return "enum"
334
- end
335
- elsif v.class == Apipie::Validator::HashValidator
336
- # pp v
337
- end
326
+ method_id = ruby_name_for_method(@current_method)
338
327
 
328
+ warning = Apipie::Generator::Swagger::Warning.for_code(
329
+ Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE,
330
+ method_id,
331
+ { parameter: param_desc.name }
332
+ )
339
333
 
340
- return lookup[v.expected_type.to_sym] || v.expected_type
334
+ Apipie::Generator::Swagger::TypeExtractor.new(param_desc.validator).
335
+ extract_with_warnings({ boolean: warning })
341
336
  end
342
337
 
343
338
 
@@ -473,7 +468,7 @@ module Apipie
473
468
 
474
469
  swg_param_type = swagger_param_type(param_desc)
475
470
  swagger_def[:type] = swg_param_type.to_s
476
- if (swg_param_type.is_a? SwaggerTypeWithFormat) && !swg_param_type.str_format.nil?
471
+ if (swg_param_type.is_a? Apipie::Generator::Swagger::Type) && !swg_param_type.str_format.nil?
477
472
  swagger_def[:format] = swg_param_type.str_format
478
473
  end
479
474
 
@@ -432,6 +432,10 @@ module Apipie
432
432
  "Must be a decimal number."
433
433
  end
434
434
 
435
+ def expected_type
436
+ 'numeric'
437
+ end
438
+
435
439
  def self.validate(value)
436
440
  value.to_s =~ /\A^[-+]?[0-9]+([,.][0-9]+)?\Z$/
437
441
  end
@@ -1,3 +1,3 @@
1
1
  module Apipie
2
- VERSION = "0.8.2"
2
+ VERSION = "0.9.0"
3
3
  end
data/lib/apipie-rails.rb CHANGED
@@ -2,7 +2,7 @@ require 'i18n'
2
2
  require 'json'
3
3
  require 'active_support/hash_with_indifferent_access'
4
4
 
5
- require 'apipie/core_ext/route.rb'
5
+ require 'apipie/core_ext/route'
6
6
 
7
7
  require "apipie/routing"
8
8
  require "apipie/markup"
@@ -12,6 +12,8 @@ require "apipie/configuration"
12
12
  require "apipie/method_description"
13
13
  require "apipie/resource_description"
14
14
  require "apipie/param_description"
15
+ require "apipie/method_description/api"
16
+ require "apipie/method_description/apis_service"
15
17
  require "apipie/errors"
16
18
  require "apipie/error_description"
17
19
  require "apipie/response_description"
@@ -23,3 +25,9 @@ require "apipie/railtie"
23
25
  require 'apipie/extractor'
24
26
  require "apipie/version"
25
27
  require "apipie/swagger_generator"
28
+ require "apipie/generator/generator"
29
+ require "apipie/generator/swagger/swagger"
30
+ require "apipie/generator/swagger/warning"
31
+ require "apipie/generator/swagger/warning_writer"
32
+ require "apipie/generator/swagger/type"
33
+ require "apipie/generator/swagger/type_extractor"
@@ -1,6 +1,6 @@
1
1
  module Apipie
2
2
  class InstallGenerator < ::Rails::Generators::Base
3
- source_root File.expand_path("../templates", __FILE__)
3
+ source_root File.expand_path('templates', __dir__)
4
4
 
5
5
  class_option(:route,
6
6
  :aliases => "-r",
@@ -1,6 +1,6 @@
1
1
  module Apipie
2
2
  class ViewsGenerator < ::Rails::Generators::Base
3
- source_root File.expand_path("../../../../app/views", __FILE__)
3
+ source_root File.expand_path('../../../app/views', __dir__)
4
4
  desc 'Copy Apipie views to your application'
5
5
 
6
6
  def copy_views
@@ -166,10 +166,10 @@ namespace :apipie do
166
166
  def renderer
167
167
  return @apipie_renderer if @apipie_renderer
168
168
 
169
- base_paths = [File.expand_path("../../../app/views/apipie/apipies", __FILE__)]
169
+ base_paths = [File.expand_path('../../app/views/apipie/apipies', __dir__)]
170
170
  base_paths.unshift("#{Rails.root}/app/views/apipie/apipies") if File.directory?("#{Rails.root}/app/views/apipie/apipies")
171
171
 
172
- layouts_paths = [File.expand_path("../../../app/views/layouts", __FILE__)]
172
+ layouts_paths = [File.expand_path('../../app/views/layouts', __dir__)]
173
173
  layouts_paths.unshift("#{Rails.root}/app/views/layouts") if File.directory?("#{Rails.root}/app/views/layouts/apipie")
174
174
 
175
175
  if ActionView::Base.respond_to?(:with_empty_template_cache) && ActionView::Base.respond_to?(:with_view_paths)
data/spec/dummy/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # Add your own tasks in files placed in lib/tasks ending in .rake,
2
2
  # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
3
 
4
- require File.expand_path('../config/application', __FILE__)
4
+ require File.expand_path('config/application', __dir__)
5
5
  require 'rake'
6
6
 
7
7
  Dummy::Application.load_tasks
@@ -1,4 +1,4 @@
1
- $:.push File.expand_path('../lib', __FILE__)
1
+ $:.push File.expand_path('lib', __dir__)
2
2
 
3
3
  # Describe your gem and declare its dependencies:
4
4
  Gem::Specification.new do |s|
@@ -1,4 +1,4 @@
1
- require File.expand_path('../boot', __FILE__)
1
+ require File.expand_path('boot', __dir__)
2
2
 
3
3
  require "action_controller/railtie"
4
4
  require "action_view/railtie"
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- gemfile = File.expand_path('../../../../Gemfile', __FILE__)
2
+ gemfile = File.expand_path('../../../Gemfile', __dir__)
3
3
 
4
4
  if File.exist?(gemfile)
5
5
  ENV['BUNDLE_GEMFILE'] = gemfile
@@ -7,4 +7,4 @@ if File.exist?(gemfile)
7
7
  Bundler.setup
8
8
  end
9
9
 
10
- $:.unshift File.expand_path('../../../../lib', __FILE__)
10
+ $:.unshift File.expand_path('../../../lib', __dir__)
@@ -2,7 +2,7 @@
2
2
  # ENV['RAILS_RELATIVE_URL_ROOT'] = '/relative/path'
3
3
 
4
4
  # Load the rails application
5
- require File.expand_path('../application', __FILE__)
5
+ require File.expand_path('application', __dir__)
6
6
 
7
7
  # Initialize the rails application
8
8
  Dummy::Application.initialize!
@@ -11,6 +11,7 @@ Dummy::Application.routes.draw do
11
11
  end
12
12
  end
13
13
  resources :concerns, :only => [:index, :show]
14
+ get '/:resource_id/:custom_subst' => 'concerns#custom'
14
15
  namespace :files do
15
16
  get '/*file_path', format: false, :action => 'download'
16
17
  end
data/spec/dummy/config.ru CHANGED
@@ -1,4 +1,4 @@
1
1
  # This file is used by Rack-based servers to start the application.
2
2
 
3
- require ::File.expand_path('../config/environment', __FILE__)
3
+ require ::File.expand_path('config/environment', __dir__)
4
4
  run Dummy::Application
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
3
 
4
- APP_PATH = File.expand_path('../../config/application', __FILE__)
5
- require File.expand_path('../../config/boot', __FILE__)
4
+ APP_PATH = File.expand_path('../config/application', __dir__)
5
+ require File.expand_path('../config/boot', __dir__)
6
6
  require 'rails/commands'
@@ -27,7 +27,7 @@ describe Apipie::Application do
27
27
  end
28
28
 
29
29
  context "with an undefined base url" do
30
- before {allow(Apipie.app).to receive(:get_base_url) { nil }}
30
+ before {allow(Apipie.app).to receive(:get_base_url).and_return(nil)}
31
31
 
32
32
  it "should not raise an error" do
33
33
  expect { Apipie.get_resource_name(Api::V2::ArchitecturesController) }.
@@ -6,7 +6,8 @@ describe Apipie::Extractor::Writer do
6
6
  let(:writer_class) { Apipie::Extractor::Writer }
7
7
  let(:writer) { writer_class.new(collector) }
8
8
  let(:test_examples_file) { File.join(Rails.root, "doc", "apipie_examples_test.json") }
9
- let(:records) { {
9
+ let(:records) {
10
+ {
10
11
  "concern_resources#show" =>
11
12
  [{
12
13
  :controller=>ConcernsController,
@@ -31,7 +32,8 @@ describe Apipie::Extractor::Writer do
31
32
  }]
32
33
  }
33
34
  }
34
- let(:loaded_records) { {
35
+ let(:loaded_records) {
36
+ {
35
37
  "concern_resources#show" =>
36
38
  [{
37
39
  "verb"=>:GET,
@@ -57,16 +59,16 @@ describe Apipie::Extractor::Writer do
57
59
  }
58
60
  }
59
61
 
60
- context 'with doc_path overriden in configuration' do
62
+ context 'with doc_path overridden in configuration' do
61
63
  around(:each) do |example|
62
64
  standard_path = Apipie.configuration.doc_path
63
- Apipie.configuration.doc_path = 'user_specified_doc_path'
65
+ Apipie.configuration.doc_path = 'tmp/user_specified_doc_path'
64
66
  example.run
65
67
  Apipie.configuration.doc_path = standard_path
66
68
  end
67
69
 
68
70
  it 'should use the doc_path specified in configuration' do
69
- expect(writer_class.examples_file).to eql(File.join(Rails.root, 'user_specified_doc_path', 'apipie_examples.json'))
71
+ expect(writer_class.examples_file).to eql(File.join(Rails.root, 'tmp', 'user_specified_doc_path', 'apipie_examples.json'))
70
72
  end
71
73
  end
72
74
 
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apipie::Generator::Swagger::TypeExtractor do
4
+ let(:validator) {}
5
+ let(:extractor) { described_class.new(validator) }
6
+
7
+ describe '#extarct_with_warnings' do
8
+ let(:warnings) { {} }
9
+
10
+ before { Apipie.configuration.swagger_suppress_warnings = false }
11
+
12
+ subject { extractor.extract_with_warnings(warnings) }
13
+
14
+ it { is_expected.to eq(Apipie::Generator::Swagger::TypeExtractor::TYPES[:string]) }
15
+
16
+ context "when enum validator is used" do
17
+ let(:enum_values) { ["Name"] }
18
+
19
+ context "of type Apipie::Validator::EnumValidator" do
20
+ let(:validator) { Apipie::Validator::EnumValidator.new(nil, enum_values) }
21
+
22
+ it { is_expected.to eq("enum") }
23
+ end
24
+
25
+ context "that responds to is_enum?" do
26
+ let(:validator) do
27
+ Apipie::ResponseDescriptionAdapter::PropDesc::Validator.new('some-type', enum_values)
28
+ end
29
+
30
+ it 'returns an enum type' do
31
+ expect(subject).to eq(Apipie::Generator::Swagger::TypeExtractor::TYPES[:enum])
32
+ end
33
+
34
+ context 'and has `true`, `false` as values' do
35
+ let(:param_description_name) { :visible }
36
+ let(:enum_values) { [true, false] }
37
+
38
+ it 'returns a boolean type' do
39
+ expect(subject).to eq(Apipie::Generator::Swagger::TypeExtractor::TYPES[:boolean])
40
+ end
41
+
42
+ context 'and a boolean warning is passed' do
43
+ let(:boolean_warning) do
44
+ Apipie::Generator::Swagger::Warning.for_code(
45
+ Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE,
46
+ 'SampleController#action',
47
+ { parameter: 'some-param' }
48
+ )
49
+ end
50
+
51
+ let(:warnings) { { boolean: boolean_warning } }
52
+
53
+ it 'outputs the warning' do
54
+ expect { subject }.to output(boolean_warning.warning_message).to_stderr
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,51 @@
1
+ require "spec_helper"
2
+
3
+ describe Apipie::Generator::Swagger::Warning do
4
+ let(:code) { Apipie::Generator::Swagger::Warning::MISSING_METHOD_SUMMARY_CODE }
5
+ let(:method_id) { 'Examples#index' }
6
+ let(:info_message) { 'Something went wrong' }
7
+
8
+ let(:warning) { described_class.new(code, info_message, method_id) }
9
+
10
+ describe '#id' do
11
+ subject { warning.id }
12
+
13
+ it { is_expected.to eq("#{method_id}#{code}#{info_message}") }
14
+ end
15
+
16
+ describe '#warning_message' do
17
+ subject { warning.warning_message }
18
+
19
+ it { is_expected.to eq("WARNING (#{code}): [#{method_id}] -- #{info_message}") }
20
+ end
21
+
22
+ describe '#warn' do
23
+ subject { warning.warn }
24
+
25
+ it 'outputs the warning' do
26
+ expect { subject }.to output(warning.warning_message).to_stderr
27
+ end
28
+ end
29
+
30
+ describe '#warn_through_writer' do
31
+ subject { warning.warn }
32
+
33
+ it 'outputs the warning' do
34
+ expect { subject }.to output(warning.warning_message).to_stderr
35
+ end
36
+ end
37
+
38
+ describe '.for_code' do
39
+ subject { described_class.for_code(code, method_id) }
40
+
41
+ it { is_expected.to be_an_instance_of(described_class)}
42
+
43
+ context 'when code is invalid' do
44
+ let(:code) { 12345 }
45
+
46
+ it 'raises an argument error' do
47
+ expect { subject }.to raise_error(ArgumentError)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe Apipie::Generator::Swagger::WarningWriter do
4
+ let(:writer) { described_class.clone.instance }
5
+
6
+ let(:warning) do
7
+ Apipie::Generator::Swagger::Warning.for_code(
8
+ Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE,
9
+ 'SampleController#action',
10
+ { parameter: 'some-param' }
11
+ )
12
+ end
13
+
14
+ before do
15
+ Apipie.configuration.swagger_suppress_warnings = false
16
+ Singleton.__init__(described_class)
17
+ end
18
+
19
+ describe '#warn' do
20
+ subject { writer.warn(warning) }
21
+
22
+ it 'outputs the warning' do
23
+ expect { subject }.to output(warning.warning_message).to_stderr
24
+ end
25
+
26
+ context 'when Apipie.configuration.swagger_suppress_warnings is true' do
27
+ before { Apipie.configuration.swagger_suppress_warnings = true }
28
+
29
+ it { is_expected.to be_falsey }
30
+ end
31
+
32
+ context 'when Apipie.configuration.swagger_suppress_warnings includes warning code' do
33
+ before do
34
+ Apipie.configuration.swagger_suppress_warnings =
35
+ Array(Apipie::Generator::Swagger::Warning::INFERRING_BOOLEAN_CODE)
36
+ end
37
+
38
+ it { is_expected.to be_falsey }
39
+ end
40
+
41
+ context 'when a warning already been logged' do
42
+ before { writer.warn(warning) }
43
+
44
+ it { is_expected.to be_falsey }
45
+ end
46
+ end
47
+
48
+ describe '#issued_warnings?' do
49
+ subject { writer.issued_warnings? }
50
+
51
+ it { is_expected.to be_falsey }
52
+
53
+ context 'when a warning already been logged' do
54
+ before { writer.warn(warning) }
55
+
56
+ it { is_expected.to be_truthy }
57
+ end
58
+ end
59
+ end
@@ -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
@@ -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
@@ -1,14 +1,14 @@
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