apipie-rails 0.3.7 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 17995f18251d02f81382e0d01c72f257f708849c
4
- data.tar.gz: 5c7c04c928e4ec7639d589e4fb878e5ae60b8522
3
+ metadata.gz: 3557cb98f666126a55faa4fe95a955403adcaedf
4
+ data.tar.gz: 6fd75fb4ebd5e4b0652b81c77c0df65f6d96a41b
5
5
  SHA512:
6
- metadata.gz: f3f894d9d39a183ae146c9f9b8be3d9d402b8631cb7243294d01acbc0b5f84e1b2e7f39fd5170d1e7c989daa7493a2e9ded3653907ea4cd69e4285b7211e5bc2
7
- data.tar.gz: ce051627c13ca9435698f1e3d553d3aa22d30f77408b007ff127b1f6d64c495f90d30fa042bef3b25c527afa6f89d45baae6bc812931229daa3d5b6393cc5268
6
+ metadata.gz: 1f9c181cc455758e9411f0631f3e5a5d67953ce8eb6209ad079862ce2e4ab3c1550cd5deb05fae1541d8e48d6d4f27753c994876484d185551f3049583a2ec47
7
+ data.tar.gz: 77b58f2a00111e3dab471de451c9ddcf9ec82622dde6b3ba14d3e23f2138ec571157521092fdebc0a76c73ae22350a3c2d7693147d65b248285e5f608734398f
data/.travis.yml CHANGED
@@ -5,8 +5,17 @@ rvm:
5
5
  - 2.0.0
6
6
  - 2.1.7
7
7
  - 2.2.3
8
+ - 2.3.3
8
9
  gemfile:
9
- - Gemfile.rails32
10
10
  - Gemfile.rails40
11
11
  - Gemfile.rails41
12
12
  - Gemfile.rails42
13
+ - Gemfile.rails50 # Min ruby 2.2.2
14
+ matrix:
15
+ exclude:
16
+ - rvm: 1.9.3
17
+ gemfile: Gemfile.rails50
18
+ - rvm: 2.0.0
19
+ gemfile: Gemfile.rails50
20
+ - rvm: 2.1.7
21
+ gemfile: Gemfile.rails50
data/CHANGELOG.md CHANGED
@@ -2,6 +2,23 @@
2
2
  Changelog
3
3
  ===========
4
4
 
5
+ v0.4.0
6
+ ------
7
+
8
+ - Rails 5 compatibility [\#527](https://github.com/Apipie/apipie-rails/pull/527) ([iNecas](https://github.com/iNecas)) [\#420](https://github.com/Apipie/apipie-rails/pull/420) ([buren](https://github.com/buren)) [\#473](https://github.com/Apipie/apipie-rails/pull/473)([domcleal](https://github.com/domcleal))
9
+ - **This release is no longer compatible with Rails 3.x**
10
+ - Include delete request parmeters in generated documentation [\#524](https://github.com/Apipie/apipie-rails/pull/524) ([johnnaegle](https://github.com/johnnaegle))
11
+ - Allow a blank, not just nil, base\_url. [\#521](https://github.com/Apipie/apipie-rails/pull/521) ([johnnaegle](https://github.com/johnnaegle))
12
+ - Adds allow\_blank option [\#508](https://github.com/Apipie/apipie-rails/pull/508) ([MrLeebo](https://github.com/MrLeebo))
13
+ - Boolean Validator uses \<code\> instead of ' [\#502](https://github.com/Apipie/apipie-rails/pull/502) ([berfarah](https://github.com/berfarah))
14
+ - Fix type validator message [\#501](https://github.com/Apipie/apipie-rails/pull/501) ([cindygu-itglue](https://github.com/cindygu-itglue))
15
+ - Add IT locale [\#496](https://github.com/Apipie/apipie-rails/pull/496) ([alepore](https://github.com/alepore))
16
+ - Fix small typo on dsl\_definition data init [\#494](https://github.com/Apipie/apipie-rails/pull/494) ([begault](https://github.com/begault))
17
+ - Localize app info message [\#491](https://github.com/Apipie/apipie-rails/pull/491) ([belousovAV](https://github.com/belousovAV))
18
+ - Fix travis build [\#489](https://github.com/Apipie/apipie-rails/pull/489) ([mtparet](https://github.com/mtparet))
19
+ - Handle blank data when parsing a example's response [\#453](https://github.com/Apipie/apipie-rails/pull/453) ([stbenjam](https://github.com/stbenjam))
20
+ - Allow layouts to be overridable. Fixes a regression introduced in \#425. [\#447](https://github.com/Apipie/apipie-rails/pull/447) ([nilsojes](https://github.com/nilsojes))
21
+
5
22
  v0.3.7
6
23
  ------
7
24
 
data/Gemfile CHANGED
@@ -2,6 +2,6 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- # load local gemfile
6
- local_gemfile = File.join(File.dirname(__FILE__), 'Gemfile.local')
7
- self.instance_eval(Bundler.read_file(local_gemfile)) if File.exist?(local_gemfile)
5
+ gem 'rails', '~> 5.0'
6
+ gem 'mime-types', '~> 2.99.3'
7
+ gem 'rails-controller-testing'
data/Gemfile.rails40 CHANGED
@@ -3,4 +3,5 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', '~> 4.0.0'
6
- gem 'mime-types', '~> 2.99.3'
6
+ gem 'mime-types', '~> 2.99.3'
7
+ gem 'json', '~> 1.8'
data/Gemfile.rails41 CHANGED
@@ -3,4 +3,4 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', '~> 4.1.0'
6
- gem 'mime-types', '~> 2.99.3'
6
+ gem 'mime-types', '~> 2.99.3'
data/Gemfile.rails42 CHANGED
@@ -3,4 +3,9 @@ source "https://rubygems.org"
3
3
  gemspec
4
4
 
5
5
  gem 'rails', '~> 4.2.5'
6
- gem 'mime-types', '~> 2.99.3'
6
+ gem 'mime-types', '~> 2.99.3'
7
+
8
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.1.0')
9
+ gem 'nokogiri', '~> 1.6.8'
10
+ gem 'rdoc', '~> 4.2.2'
11
+ end
data/Gemfile.rails50 ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rails', '~> 5.0'
6
+ gem 'mime-types', '~> 2.99.3'
7
+ gem 'rails-controller-testing'
data/README.rst CHANGED
@@ -2,9 +2,9 @@
2
2
  API Documentation Tool
3
3
  ========================
4
4
 
5
- .. image:: https://travis-ci.org/Apipie/apipie-rails.png?branch=master
5
+ .. image:: https://travis-ci.org/Apipie/apipie-rails.svg?branch=master
6
6
  :target: https://travis-ci.org/Apipie/apipie-rails
7
- .. image:: https://codeclimate.com/github/Apipie/apipie-rails.png
7
+ .. image:: https://codeclimate.com/github/Apipie/apipie-rails.svg
8
8
  :target: https://codeclimate.com/github/Apipie/apipie-rails
9
9
  .. image:: https://badges.gitter.im/Apipie/apipie-rails.svg
10
10
  :alt: Join the chat at https://gitter.im/Apipie/apipie-rails
@@ -288,6 +288,9 @@ required
288
288
  allow_nil
289
289
  Setting this to true means that ``nil`` can be passed.
290
290
 
291
+ allow_blank
292
+ Like ``allow_nil``, but for blank values. ``false``, ``""``, ``' '``, ``nil``, ``[]``, and ``{}`` are all blank.
293
+
291
294
  as
292
295
  Used by the processing functionality to change the name of a key params.
293
296
 
@@ -528,7 +531,7 @@ default_version
528
531
  validate
529
532
  Parameters validation is turned off when set to false. When set to
530
533
  ``:explicitly``, you must invoke parameter validation yourself by calling
531
- controller method ``apipie_validations`` (typically in a before_filter).
534
+ controller method ``apipie_validations`` (typically in a before_action).
532
535
  When set to ``:implicitly`` (or just true), your controller's action
533
536
  methods are wrapped with generated methods which call ``apipie_validations``,
534
537
  and then call the action method. (``:implicitly`` by default)
@@ -726,17 +729,17 @@ is raised and can be rescued and processed. It contains a description
726
729
  of the parameter value expectations. Validations can be turned off
727
730
  in the configuration file.
728
731
 
729
- Parameter validation normally happens after before_filters, just before
732
+ Parameter validation normally happens after before_actions, just before
730
733
  your controller method is invoked. If you prefer to control when parameter
731
734
  validation occurs, set the configuration parameter ``validate`` to ``:explicitly``.
732
735
  You must then call the ``apipie_validations`` method yourself, e.g.:
733
736
 
734
737
  .. code:: ruby
735
738
 
736
- before_filter: :apipie_validations
739
+ before_action: :apipie_validations
737
740
 
738
- This is useful if you have before_filters which use parameter values: just add them
739
- after the ``apipie_validations`` before_filter.
741
+ This is useful if you have before_actions which use parameter values: just add them
742
+ after the ``apipie_validations`` before_action.
740
743
 
741
744
  TypeValidator
742
745
  -------------
@@ -1068,11 +1071,8 @@ When your project use I18n, localization related configuration could appear as f
1068
1071
  config.default_locale = 'en'
1069
1072
  config.locale = lambda { |loc| loc ? I18n.locale = loc : I18n.locale }
1070
1073
  config.translate = lambda do |str, loc|
1071
- old_loc = I18n.locale
1072
- I18n.locale = loc
1073
- trans = I18n.t(str)
1074
- I18n.locale = old_loc
1075
- trans
1074
+ return '' if str.blank?
1075
+ I18n.t str, locale: loc, scope: 'doc'
1076
1076
  end
1077
1077
  end
1078
1078
 
data/apipie-rails.gemspec CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
17
  s.require_paths = ["lib"]
18
18
 
19
- s.add_development_dependency "rails", ">= 3.0.20"
19
+ s.add_dependency "rails", ">= 4.0"
20
20
  s.add_dependency 'json'
21
21
  s.add_development_dependency "rspec-rails", "~> 3.0"
22
22
  s.add_development_dependency "sqlite3"
@@ -5,8 +5,8 @@ module Apipie
5
5
 
6
6
  layout Apipie.configuration.layout
7
7
 
8
- around_filter :set_script_name
9
- before_filter :authenticate
8
+ around_action :set_script_name
9
+ before_action :authenticate
10
10
 
11
11
  def authenticate
12
12
  if Apipie.configuration.authenticate
@@ -0,0 +1,31 @@
1
+ it:
2
+ apipie:
3
+ resources: Risorse
4
+ resource: Risorsa
5
+ description: Descrizione
6
+ no_docs_found: Nessuna documentazione trovata
7
+ no_docs_found_descr: Non abbiamo trovato nessuna documentazione per la tua API.
8
+ follow_instructions_html: Leggi su %{href} come descrivere i tuoi controller.
9
+ follow_instructions_href: ulteriori istruzioni
10
+ oops: Ops!!
11
+ resource_not_found_html: Risorsa %{resource} non trovata.
12
+ method_not_found_html: Metodo %{method} non trovato per la risorsa %{resource}.
13
+ goto_homepage_html: Prova ad andare su %{href}
14
+ goto_homepage_href: "%{app_name} Homepage della documentazione API"
15
+ required: richiesto
16
+ optional: opzionale
17
+ nil_allowed: consentito nil
18
+ param_name: Nome parametro
19
+ params: Parametri
20
+ examples: Esempi
21
+ metadata: Metadata
22
+ errors: Errori
23
+ error_code: Codice
24
+ error_description: Descrizione
25
+ error_metadata: Metadata
26
+ supported_formats: Formati supportati
27
+ enable_javascript_html: Abilita i JavaScript per vedere %{comments_href}.
28
+ comments_powered_by_disqus: commenti forniti da %{disqus}
29
+ api_documentation: Documentazione API
30
+ headers: Header
31
+ header_name: Nome Header
@@ -31,14 +31,16 @@ module Apipie
31
31
  end
32
32
 
33
33
  # get application description for given or default version
34
- def self.app_info(version = nil)
35
- if app_info_version_valid? version
36
- Apipie.markup_to_html(self.configuration.app_info[version])
34
+ def self.app_info(version = nil, lang = nil)
35
+ info = if app_info_version_valid? version
36
+ translate(self.configuration.app_info[version], lang)
37
37
  elsif app_info_version_valid? Apipie.configuration.default_version
38
- Apipie.markup_to_html(self.configuration.app_info[Apipie.configuration.default_version])
38
+ translate(self.configuration.app_info[Apipie.configuration.default_version], lang)
39
39
  else
40
40
  "Another API description"
41
41
  end
42
+
43
+ Apipie.markup_to_html info
42
44
  end
43
45
 
44
46
  def self.api_base_url(version = nil)
@@ -54,14 +54,9 @@ module Apipie
54
54
  # the app might be nested when using contraints, namespaces etc.
55
55
  # this method does in depth search for the route controller
56
56
  def route_app_controller(app, route, visited_apps = [])
57
- visited_apps << app
58
- if app.respond_to?(:controller)
59
- return app.controller(route.defaults)
60
- elsif app.respond_to?(:app) && !visited_apps.include?(app.app)
61
- return route_app_controller(app.app, route, visited_apps)
57
+ if route.defaults[:controller]
58
+ (route.defaults[:controller].camelize + "Controller").constantize
62
59
  end
63
- rescue ActionController::RoutingError
64
- # some errors in the routes will not stop us here: just ignoring
65
60
  end
66
61
 
67
62
  def routes_for_action(controller, method, args)
@@ -278,7 +273,7 @@ module Apipie
278
273
  {
279
274
  :docs => {
280
275
  :name => Apipie.configuration.app_name,
281
- :info => translate(Apipie.app_info(version), lang),
276
+ :info => Apipie.app_info(version, lang),
282
277
  :copyright => Apipie.configuration.copyright,
283
278
  :doc_url => Apipie.full_url(url_args),
284
279
  :api_url => Apipie.api_base_url(version),
@@ -392,7 +387,7 @@ module Apipie
392
387
  def version_prefix(klass)
393
388
  version = controller_versions(klass).first
394
389
  base_url = get_base_url(version)
395
- return "/" if base_url.nil?
390
+ return "/" if base_url.blank?
396
391
  base_url[1..-1] + "/"
397
392
  end
398
393
 
@@ -26,7 +26,7 @@ module Apipie
26
26
  :errors => [],
27
27
  :params => [],
28
28
  :headers => [],
29
- :resouce_id => nil,
29
+ :resource_id => nil,
30
30
  :short_description => nil,
31
31
  :description => nil,
32
32
  :examples => [],
@@ -9,7 +9,7 @@ require 'apipie/extractor/collector'
9
9
  class Apipie::Railtie
10
10
  initializer 'apipie.extractor' do |app|
11
11
  ActiveSupport.on_load :action_controller do
12
- before_filter do |controller|
12
+ before_action do |controller|
13
13
  if Apipie.configuration.record
14
14
  Apipie::Extractor.call_recorder.analyse_controller(controller)
15
15
  end
@@ -38,7 +38,7 @@ module Apipie
38
38
  @verb = request.request_method.to_sym
39
39
  @path = request.path
40
40
  @params = request.request_parameters
41
- if [:POST, :PUT, :PATCH].include?(@verb)
41
+ if [:POST, :PUT, :PATCH, :DELETE].include?(@verb)
42
42
  @request_data = @params
43
43
  else
44
44
  @query = request.query_string
@@ -8,7 +8,7 @@ module Apipie
8
8
  # validator - Validator::BaseValidator subclass
9
9
  class ParamDescription
10
10
 
11
- attr_reader :method_description, :name, :desc, :allow_nil, :validator, :options, :metadata, :show, :as, :validations
11
+ attr_reader :method_description, :name, :desc, :allow_nil, :allow_blank, :validator, :options, :metadata, :show, :as, :validations
12
12
  attr_accessor :parent, :required
13
13
 
14
14
  def self.from_dsl_data(method_description, args)
@@ -56,6 +56,7 @@ module Apipie
56
56
  end
57
57
 
58
58
  @allow_nil = @options[:allow_nil] || false
59
+ @allow_blank = @options[:allow_blank] || false
59
60
 
60
61
  action_awareness
61
62
 
@@ -71,8 +72,20 @@ module Apipie
71
72
  method_description.from_concern? || @from_concern
72
73
  end
73
74
 
75
+ def normalized_value(value)
76
+ if value.is_a?(ActionController::Parameters) && !value.is_a?(Hash)
77
+ value.to_unsafe_hash
78
+ elsif value.is_a? Array
79
+ value.map { |v| normalized_value (v) }
80
+ else
81
+ value
82
+ end
83
+ end
84
+
74
85
  def validate(value)
75
86
  return true if @allow_nil && value.nil?
87
+ return true if @allow_blank && value.blank?
88
+ value = normalized_value(value)
76
89
  if (!@allow_nil && value.nil?) || !@validator.valid?(value)
77
90
  error = @validator.error
78
91
  error = ParamError.new(error) unless error.is_a? StandardError
@@ -81,6 +94,7 @@ module Apipie
81
94
  end
82
95
 
83
96
  def process_value(value)
97
+ value = normalized_value(value)
84
98
  if @validator.respond_to?(:process_value)
85
99
  @validator.process_value(value)
86
100
  else
@@ -111,6 +125,7 @@ module Apipie
111
125
  :description => preformat_text(Apipie.app.translate(@options[:desc], lang)),
112
126
  :required => required,
113
127
  :allow_nil => allow_nil,
128
+ :allow_blank => allow_blank,
114
129
  :validator => validator.to_s,
115
130
  :expected_type => validator.expected_type,
116
131
  :metadata => metadata,
@@ -96,7 +96,7 @@ module Apipie
96
96
  end
97
97
 
98
98
  def description
99
- "Must be #{@type}"
99
+ "Must be a #{@type}"
100
100
  end
101
101
 
102
102
  def expected_type
@@ -413,7 +413,8 @@ module Apipie
413
413
  end
414
414
 
415
415
  def description
416
- "Must be 'true' or 'false' or '1' or '0'"
416
+ string = %w(true false 1 0).map { |value| "<code>#{value}</code>" }.join(', ')
417
+ "Must be one of: #{string}"
417
418
  end
418
419
  end
419
420
 
@@ -464,4 +465,3 @@ module Apipie
464
465
 
465
466
  end
466
467
  end
467
-
@@ -1,3 +1,3 @@
1
1
  module Apipie
2
- VERSION = '0.3.7'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -12,37 +12,37 @@ describe Apipie::ApipiesController do
12
12
  end
13
13
 
14
14
  it "succeeds on version details" do
15
- get :index, :version => "2.0"
15
+ get :index, :params => { :version => "2.0" }
16
16
 
17
17
  assert_response :success
18
18
  end
19
19
 
20
20
  it "returns not_found on wrong version" do
21
- get :index, :version => "wrong_version"
21
+ get :index, :params => { :version => "wrong_version" }
22
22
 
23
23
  assert_response :not_found
24
24
  end
25
25
 
26
26
  it "succeeds on resource details" do
27
- get :index, :version => "2.0", :resource => "architectures"
27
+ get :index, :params => { :version => "2.0", :resource => "architectures" }
28
28
 
29
29
  assert_response :success
30
30
  end
31
31
 
32
32
  it "returns not_found on wrong resource" do
33
- get :index, :version => "2.0", :resource => "wrong_resource"
33
+ get :index, :params => { :version => "2.0", :resource => "wrong_resource" }
34
34
 
35
35
  assert_response :not_found
36
36
  end
37
37
 
38
38
  it "succeeds on method details" do
39
- get :index, :version => "2.0", :resource => "architectures", :method => "index"
39
+ get :index, :params => { :version => "2.0", :resource => "architectures", :method => "index" }
40
40
 
41
41
  assert_response :success
42
42
  end
43
43
 
44
44
  it "returns not_found on wrong method" do
45
- get :index, :version => "2.0", :resource => "architectures", :method => "wrong_method"
45
+ get :index, :params => { :version => "2.0", :resource => "architectures", :method => "wrong_method" }
46
46
 
47
47
  assert_response :not_found
48
48
  end
@@ -215,17 +215,17 @@ describe Apipie::ApipiesController do
215
215
  it "uses the file in cache dir instead of generating the content on runtime" do
216
216
  get :index
217
217
  expect(response.body).to eq("apidoc.html cache v1")
218
- get :index, :version => 'v1'
218
+ get :index, :params => { :version => 'v1' }
219
219
  expect(response.body).to eq("apidoc.html cache v1")
220
- get :index, :version => 'v2'
220
+ get :index, :params => { :version => 'v2' }
221
221
  expect(response.body).to eq("apidoc.html cache v2")
222
- get :index, :version => 'v1', :format => "html"
222
+ get :index, :params => { :version => 'v1', :format => "html" }
223
223
  expect(response.body).to eq("apidoc.html cache v1")
224
- get :index, :version => 'v1', :format => "json"
224
+ get :index, :params => { :version => 'v1', :format => "json" }
225
225
  expect(response.body).to eq("apidoc.json cache")
226
- get :index, :version => 'v1', :format => "html", :resource => "resource"
226
+ get :index, :params => { :version => 'v1', :format => "html", :resource => "resource" }
227
227
  expect(response.body).to eq("resource.html cache")
228
- get :index, :version => 'v1', :format => "html", :resource => "resource", :method => "method"
228
+ get :index, :params => { :version => 'v1', :format => "html", :resource => "resource", :method => "method" }
229
229
  expect(response.body).to eq("method.html cache")
230
230
  end
231
231
 
@@ -8,7 +8,7 @@ describe ConcernsController do
8
8
  end
9
9
 
10
10
  it "should reply to valid request" do
11
- get :show, :id => '5', :session => "secret_hash"
11
+ get :show, :params => { :id => '5' }, :session => { :user_id => "secret_hash" }
12
12
  assert_response :success
13
13
  end
14
14
 
@@ -66,7 +66,7 @@ describe UsersController do
66
66
  end
67
67
 
68
68
  it "should reply to valid request" do
69
- get :show, :id => '5', :session => "secret_hash"
69
+ get :show, :params => { :id => '5', :session => "secret_hash" }
70
70
  assert_response :success
71
71
  end
72
72
 
@@ -92,17 +92,17 @@ describe UsersController do
92
92
  end
93
93
 
94
94
  it "should reply to valid request" do
95
- expect { get :show, :id => 5, :session => "secret_hash" }.not_to raise_error
95
+ expect { get :show, :params => { :id => 5, :session => "secret_hash" }}.not_to raise_error
96
96
  assert_response :success
97
97
  end
98
98
 
99
99
  it "should fail if required parameter is missing" do
100
- expect { get :show, :id => 5 }.to raise_error(Apipie::ParamMissing, /session_parameter_is_required/)
100
+ expect { get :show, :params => { :id => 5 }}.to raise_error(Apipie::ParamMissing, /session_parameter_is_required/)
101
101
  end
102
102
 
103
103
  it "should pass if required parameter has wrong type" do
104
- expect { get :show, :id => 5, :session => "secret_hash" }.not_to raise_error
105
- expect { get :show, :id => "ten", :session => "secret_hash" }.not_to raise_error
104
+ expect { get :show, :params => { :id => 5 , :session => "secret_hash" }}.not_to raise_error
105
+ expect { get :show, :params => { :id => "ten" , :session => "secret_hash" }}.not_to raise_error
106
106
  end
107
107
 
108
108
  end
@@ -115,12 +115,12 @@ describe UsersController do
115
115
  end
116
116
 
117
117
  it "should reply to valid request" do
118
- expect { get :show, :id => 5, :session => "secret_hash" }.not_to raise_error
118
+ expect { get :show, :params => { :id => 5, :session => 'secret_hash' }}.not_to raise_error
119
119
  assert_response :success
120
120
  end
121
121
 
122
122
  it "should fail if extra parameter is passed in" do
123
- expect { get :show, :id => 5, :session => "secret_hash", :badparam => 'badfoo' }.to raise_error(Apipie::UnknownParam, /\bbadparam\b/)
123
+ expect { get :show, :params => { :id => 5 , :badparam => 'badfoo', :session => "secret_hash" }}.to raise_error(Apipie::UnknownParam, /\bbadparam\b/)
124
124
  end
125
125
  end
126
126
 
@@ -132,81 +132,75 @@ describe UsersController do
132
132
  end
133
133
 
134
134
  it "should reply to valid request" do
135
- get :show, :id => '5', :session => "secret_hash"
135
+ get :show, :params => { :id => '5', :session => "secret_hash" }
136
136
  assert_response :success
137
137
  end
138
138
 
139
139
  it "should work with nil value for a required hash param" do
140
140
  expect {
141
- get :show, :id => '5', :session => "secret_hash", :hash_param => {:dummy_hash => nil}
141
+ get :show, :params => { :id => '5', :session => "secret_hash", :hash_param => {:dummy_hash => nil} }
142
142
  }.to raise_error(Apipie::ParamInvalid, /dummy_hash/)
143
143
  assert_response :success
144
144
  end
145
145
 
146
146
  it "should fail if required parameter is missing" do
147
- expect { get :show, :id => 5 }.to raise_error(Apipie::ParamMissing, /session_parameter_is_required/)
147
+ expect { get :show, :params => { :id => 5 }}.to raise_error(Apipie::ParamMissing, /session_parameter_is_required/)
148
148
  end
149
149
 
150
150
  it "should work with custom Type validator" do
151
151
  expect {
152
152
  get :show,
153
- :id => "not a number",
154
- :session => "secret_hash"
153
+ :params => { :id => "not a number", :session => "secret_hash" }
155
154
  }.to raise_error(Apipie::ParamError, /id/) # old-style error rather than ParamInvalid
156
155
  end
157
156
 
158
157
  it "should work with Regexp validator" do
159
- get :show,
160
- :id => 5,
161
- :session => "secret_hash",
162
- :regexp_param => "24 years"
158
+ get :show, :params => { :id => 5, :session => "secret_hash", :regexp_param => "24 years" }
163
159
  assert_response :success
164
160
 
165
161
  expect {
166
- get :show,
167
- :id => 5,
168
- :session => "secret_hash",
169
- :regexp_param => "ten years"
162
+ get :show, :params => { :id => 5,
163
+ :session => "secret_hash",
164
+ :regexp_param => "ten years" }
170
165
  }.to raise_error(Apipie::ParamInvalid, /regexp_param/)
171
166
  end
172
167
 
173
168
  it "should work with Array validator" do
174
- get :show, :id => 5, :session => "secret_hash", :array_param => "one"
175
- assert_response :success
176
- get :show, :id => 5, :session => "secret_hash", :array_param => "two"
169
+ get :show, :params => { :id => 5, :session => "secret_hash", :array_param => "one" }
177
170
  assert_response :success
178
- get :show, :id => 5, :session => "secret_hash", :array_param => '1'
171
+ get :show, :params => { :id => 5, :session => "secret_hash", :array_param => "two" }
179
172
  assert_response :success
180
- get :show, :id => 5, :session => "secret_hash", :boolean_param => false
173
+ get :show, :params => { :id => 5, :session => "secret_hash", :array_param => '1' }
181
174
  assert_response :success
182
175
 
183
176
  expect {
184
- get :show,
185
- :id => 5,
186
- :session => "secret_hash",
187
- :array_param => "blabla"
177
+ get :show, :params => { :id => 5,
178
+ :session => "secret_hash",
179
+ :array_param => "blabla" }
188
180
  }.to raise_error(Apipie::ParamInvalid, /array_param/)
189
181
 
190
182
  expect {
191
- get :show,
192
- :id => 5,
193
- :session => "secret_hash",
194
- :array_param => 3
183
+ get :show, :params => {
184
+ :id => 5,
185
+ :session => "secret_hash",
186
+ :array_param => 3 }
195
187
  }.to raise_error(Apipie::ParamInvalid, /array_param/)
196
188
  end
197
189
 
198
190
  it "should work with Proc validator" do
199
191
  expect {
200
192
  get :show,
201
- :id => 5,
202
- :session => "secret_hash",
203
- :proc_param => "asdgsag"
193
+ :params => {
194
+ :id => 5,
195
+ :session => "secret_hash",
196
+ :proc_param => "asdgsag" }
204
197
  }.to raise_error(Apipie::ParamInvalid, /proc_param/)
205
198
 
206
199
  get :show,
207
- :id => 5,
208
- :session => "secret_hash",
209
- :proc_param => "param value"
200
+ :params => {
201
+ :id => 5,
202
+ :session => "secret_hash",
203
+ :proc_param => "param value"}
210
204
  assert_response :success
211
205
  end
212
206
 
@@ -244,10 +238,11 @@ describe UsersController do
244
238
  params = Apipie[UsersController, :create].to_json[:params]
245
239
  expect(params).to include(:name => "facts",
246
240
  :full_name => "facts",
247
- :validator => "Must be Hash",
241
+ :validator => "Must be a Hash",
248
242
  :description => "\n<p>Additional optional facts about the user</p>\n",
249
243
  :required => false,
250
244
  :allow_nil => true,
245
+ :allow_blank => false,
251
246
  :metadata => nil,
252
247
  :show => true,
253
248
  :expected_type => "hash",
@@ -261,7 +256,18 @@ describe UsersController do
261
256
  :pass => "12345",
262
257
  :membership => "standard",
263
258
  },
264
- :facts => nil
259
+ :facts => { :test => 'test' }
260
+ assert_response :success
261
+ end
262
+
263
+ it "should allow blank when allow_blank is set to true" do
264
+ post :create,
265
+ :user => {
266
+ :name => "root",
267
+ :pass => "12345",
268
+ :membership => "standard"
269
+ },
270
+ :age => ""
265
271
  assert_response :success
266
272
  end
267
273
 
@@ -293,21 +299,21 @@ describe UsersController do
293
299
  it "should raise an error" do
294
300
  expect{
295
301
  put :update,
296
- {
297
- :id => 5,
298
- :user => {
299
- :name => "root",
300
- :pass => "12345"
301
- },
302
- :comments => [
303
- {
304
- :comment => 'comment1'
302
+ :params => {
303
+ :id => 5,
304
+ :user => {
305
+ :name => "root",
306
+ :pass => "12345"
305
307
  },
306
- {
307
- :comment => {:bad_input => 5}
308
- }
309
- ]
310
- }
308
+ :comments => [
309
+ {
310
+ :comment => {:bad_input => 4}
311
+ },
312
+ {
313
+ :comment => {:bad_input => 5}
314
+ }
315
+ ]
316
+ }
311
317
  }.to raise_error(Apipie::ParamInvalid)
312
318
  end
313
319
  end
@@ -525,7 +531,8 @@ describe UsersController do
525
531
  :params => [{:full_name=>"oauth",
526
532
  :required=>false,
527
533
  :allow_nil => false,
528
- :validator=>"Must be String",
534
+ :allow_blank => false,
535
+ :validator=>"Must be a String",
529
536
  :description=>"\n<p>Authorization</p>\n",
530
537
  :name=>"oauth",
531
538
  :show=>true,
@@ -534,6 +541,7 @@ describe UsersController do
534
541
  :description=>"\n<p>Deprecated parameter not documented</p>\n",
535
542
  :expected_type=>"hash",
536
543
  :allow_nil=>false,
544
+ :allow_blank => false,
537
545
  :name=>"legacy_param",
538
546
  :required=>false,
539
547
  :full_name=>"legacy_param",
@@ -543,6 +551,7 @@ describe UsersController do
543
551
  :description=>"\n<p>Param description for all methods</p>\n",
544
552
  :expected_type=>"hash",
545
553
  :allow_nil=>false,
554
+ :allow_blank => false,
546
555
  :name=>"resource_param",
547
556
  :required=>false,
548
557
  :full_name=>"resource_param",
@@ -550,14 +559,16 @@ describe UsersController do
550
559
  :params=>
551
560
  [{:required=>true,
552
561
  :allow_nil => false,
553
- :validator=>"Must be String",
562
+ :allow_blank => false,
563
+ :validator=>"Must be a String",
554
564
  :description=>"\n<p>Username for login</p>\n",
555
565
  :name=>"ausername", :full_name=>"resource_param[ausername]",
556
566
  :show=>true,
557
567
  :expected_type=>"string"},
558
568
  {:required=>true,
559
569
  :allow_nil => false,
560
- :validator=>"Must be String",
570
+ :allow_blank => false,
571
+ :validator=>"Must be a String",
561
572
  :description=>"\n<p>Password for login</p>\n",
562
573
  :name=>"apassword", :full_name=>"resource_param[apassword]",
563
574
  :show=>true,
@@ -567,6 +578,7 @@ describe UsersController do
567
578
  },
568
579
  {:required=>false, :validator=>"Parameter has to be Integer.",
569
580
  :allow_nil => false,
581
+ :allow_blank => false,
570
582
  :description=>"\n<p>Company ID</p>\n",
571
583
  :name=>"id", :full_name=>"id",
572
584
  :show=>true,
@@ -690,13 +702,16 @@ EOS2
690
702
 
691
703
  describe "Parameter processing / extraction" do
692
704
  before do
705
+ Apipie.configuration.validate = true
693
706
  Apipie.configuration.process_params = true
707
+ controllers_dirname = File.expand_path('../dummy/app/controllers', File.dirname(__FILE__))
708
+ Dir.glob("#{controllers_dirname}/**/*") { |file| load(file) if File.file?(file) }
694
709
  end
695
710
 
696
711
  it "process correctly the parameters" do
697
- post :create, {:user => {:name => 'dummy', :pass => 'dummy', :membership => 'standard'}, :facts => nil}
712
+ post :create, :user => {:name => 'dummy', :pass => 'dummy', :membership => 'standard' }, :facts => {:test => 'test'}
698
713
 
699
- expect(assigns(:api_params).with_indifferent_access).to eq({:user => {:name=>"dummy", :pass=>"dummy", :membership=>"standard"}, :facts => nil}.with_indifferent_access)
714
+ expect(assigns(:api_params).with_indifferent_access).to eq({:user => {:name=>"dummy", :pass=>"dummy", :membership=>"standard"}, :facts => {:test => 'test'}}.with_indifferent_access)
700
715
  end
701
716
 
702
717
  it "ignore not described parameters" do
@@ -1,5 +1,5 @@
1
1
  class ApplicationController < ActionController::Base
2
- before_filter :run_validations
2
+ before_action :run_validations
3
3
 
4
4
  resource_description do
5
5
  param :oauth, String, :desc => "Authorization", :required => false
@@ -221,6 +221,7 @@ class UsersController < ApplicationController
221
221
  param :permalink, String
222
222
  end
223
223
  param :facts, Hash, :desc => "Additional optional facts about the user", :allow_nil => true
224
+ param :age, :number, :desc => "Age is just a number", :allow_blank => true
224
225
  def create
225
226
  render :text => "OK #{params.inspect}"
226
227
  end
@@ -21,5 +21,8 @@ Dummy::Application.configure do
21
21
 
22
22
  # Only use best-standards-support built into browsers
23
23
  config.action_dispatch.best_standards_support = :builtin
24
+
25
+ # Do not eager load code on boot. (Rails 5)
26
+ config.eager_load = false
24
27
  end
25
28
 
@@ -46,4 +46,7 @@ Dummy::Application.configure do
46
46
 
47
47
  # Send deprecation notices to registered listeners
48
48
  config.active_support.deprecation = :notify
49
+
50
+ # Eager load code on boot (Rails 5)
51
+ config.eager_load = true
49
52
  end
@@ -32,4 +32,7 @@ Dummy::Application.configure do
32
32
 
33
33
  # Print deprecation notices to the stderr
34
34
  config.active_support.deprecation = :stderr
35
+
36
+ # Do not eager load code on boot. (Rails 5)
37
+ config.eager_load = false
35
38
  end
@@ -10,7 +10,7 @@ Dummy::Application.routes.draw do
10
10
  end
11
11
  resources :concerns, :only => [:index, :show]
12
12
  namespace :files do
13
- get '/*file_path', to: :download, format: false
13
+ get '/*file_path', format: false, :action => 'download'
14
14
  end
15
15
  resources :twitter_example do
16
16
  collection do
data/spec/spec_helper.rb CHANGED
@@ -9,6 +9,34 @@ require 'rspec/rails'
9
9
 
10
10
  require 'apipie-rails'
11
11
 
12
+ module Rails4Compatibility
13
+ module Testing
14
+ def process_with_rails4_compat(*args)
15
+ compatible_request(*args) { |*new_args| process_without_rails4_compat(*new_args) }
16
+ end
17
+
18
+ def self.included(base)
19
+ base.alias_method_chain :process, :rails4_compat
20
+ end
21
+
22
+ def compatible_request(method, action, hash = {})
23
+ if hash.is_a?(Hash)
24
+ if Gem::Version.new(Rails.version) < Gem::Version.new('5.0.0')
25
+ hash = hash.dup
26
+ hash.merge!(hash.delete(:params) || {})
27
+ elsif hash.key?(:params)
28
+ hash = { :params => hash }
29
+ end
30
+ end
31
+ if hash.empty?
32
+ yield method, action
33
+ else
34
+ yield method, action, hash
35
+ end
36
+ end
37
+ end
38
+ end
39
+
12
40
  # Requires supporting ruby files with custom matchers and macros, etc,
13
41
  # in spec/support/ and its subdirectories.
14
42
  Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f}
@@ -41,3 +69,7 @@ RSpec.configure do |config|
41
69
  # end
42
70
  config.infer_spec_type_from_file_location!
43
71
  end
72
+
73
+ require 'action_controller/test_case.rb'
74
+ # TODO: replace with prepend once we deprecate ruby 2.0.0
75
+ ActionController::TestCase::Behavior.send(:include, Rails4Compatibility::Testing)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apipie-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Pokorny
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-13 00:00:00.000000000 Z
12
+ date: 2017-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 3.0.20
21
- type: :development
20
+ version: '4.0'
21
+ type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 3.0.20
27
+ version: '4.0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: json
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -151,10 +151,10 @@ files:
151
151
  - APACHE-LICENSE-2.0
152
152
  - CHANGELOG.md
153
153
  - Gemfile
154
- - Gemfile.rails32
155
154
  - Gemfile.rails40
156
155
  - Gemfile.rails41
157
156
  - Gemfile.rails42
157
+ - Gemfile.rails50
158
158
  - MIT-LICENSE
159
159
  - NOTICE
160
160
  - README.rst
@@ -191,6 +191,7 @@ files:
191
191
  - config/locales/de.yml
192
192
  - config/locales/en.yml
193
193
  - config/locales/es.yml
194
+ - config/locales/it.yml
194
195
  - config/locales/pl.yml
195
196
  - config/locales/pt-BR.yml
196
197
  - config/locales/ru.yml
data/Gemfile.rails32 DELETED
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec
4
-
5
- gem 'rails', '~> 3.2.0'
6
- gem 'test-unit', '~> 3.0'