apipie-rails 0.3.6 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +13 -3
  3. data/CHANGELOG.md +33 -0
  4. data/Gemfile +3 -3
  5. data/Gemfile.rails41 +1 -0
  6. data/Gemfile.rails42 +7 -1
  7. data/Gemfile.rails50 +7 -0
  8. data/Gemfile.rails51 +7 -0
  9. data/README.rst +12 -12
  10. data/apipie-rails.gemspec +2 -3
  11. data/app/controllers/apipie/apipies_controller.rb +10 -6
  12. data/config/locales/it.yml +31 -0
  13. data/config/locales/ja.yml +31 -0
  14. data/lib/apipie/apipie_module.rb +6 -4
  15. data/lib/apipie/application.rb +6 -11
  16. data/lib/apipie/dsl_definition.rb +2 -2
  17. data/lib/apipie/extractor/recorder.rb +5 -9
  18. data/lib/apipie/extractor/writer.rb +18 -13
  19. data/lib/apipie/extractor.rb +2 -2
  20. data/lib/apipie/param_description.rb +16 -1
  21. data/lib/apipie/validator.rb +3 -3
  22. data/lib/apipie/version.rb +1 -1
  23. data/lib/apipie-rails.rb +1 -0
  24. data/lib/tasks/apipie.rake +5 -1
  25. data/spec/controllers/apipies_controller_spec.rb +12 -12
  26. data/spec/controllers/concerns_controller_spec.rb +2 -2
  27. data/spec/controllers/users_controller_spec.rb +93 -74
  28. data/spec/dummy/app/controllers/application_controller.rb +1 -1
  29. data/spec/dummy/app/controllers/concerns/sample_controller.rb +5 -5
  30. data/spec/dummy/app/controllers/users_controller.rb +11 -10
  31. data/spec/dummy/config/environments/development.rb +3 -0
  32. data/spec/dummy/config/environments/production.rb +3 -0
  33. data/spec/dummy/config/environments/test.rb +3 -0
  34. data/spec/dummy/config/initializers/apipie.rb +1 -1
  35. data/spec/dummy/config/routes.rb +1 -1
  36. data/spec/spec_helper.rb +27 -0
  37. metadata +10 -22
  38. data/Gemfile.rails32 +0 -6
  39. data/Gemfile.rails40 +0 -5
@@ -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,12 +8,12 @@ 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
 
15
15
  it "should pass if required parameter is missing" do
16
- expect { get :show, :id => '5' }.not_to raise_error
16
+ expect { get :show, :params => { :id => '5' } }.not_to raise_error
17
17
  end
18
18
 
19
19
  it "peserved the order of methods being defined in file" do
@@ -66,12 +66,12 @@ 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
 
73
73
  it "should pass if required parameter is missing" do
74
- expect { get :show, :id => 5 }.not_to raise_error
74
+ expect { get :show, :params => { :id => 5 } }.not_to raise_error
75
75
  end
76
76
 
77
77
  end
@@ -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,86 +132,80 @@ 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
 
213
207
  it "should work with Hash validator" do
214
- post :create, :user => { :name => "root", :pass => "12345", :membership => "standard" }
208
+ post :create, params: { :user => { :name => "root", :pass => "12345", :membership => "standard" } }
215
209
  assert_response :success
216
210
 
217
211
  a = Apipie[UsersController, :create]
@@ -225,18 +219,18 @@ describe UsersController do
225
219
  hash_params[2].name == :membership
226
220
 
227
221
  expect {
228
- post :create, :user => { :name => "root", :pass => "12345", :membership => "____" }
222
+ post :create, :params => { :user => { :name => "root", :pass => "12345", :membership => "____" } }
229
223
  }.to raise_error(Apipie::ParamInvalid, /membership/)
230
224
 
231
225
  expect {
232
- post :create, :user => { :name => "root" }
226
+ post :create, :params => { :user => { :name => "root" } }
233
227
  }.to raise_error(Apipie::ParamMissing, /pass/)
234
228
 
235
229
  expect {
236
- post :create, :user => "a string is not a hash"
230
+ post :create, :params => { :user => "a string is not a hash" }
237
231
  }.to raise_error(Apipie::ParamInvalid, /user/)
238
232
 
239
- post :create, :user => { :name => "root", :pass => "pwd" }
233
+ post :create, :params => { :user => { :name => "root", :pass => "pwd" } }
240
234
  assert_response :success
241
235
  end
242
236
 
@@ -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",
@@ -256,12 +251,27 @@ describe UsersController do
256
251
 
257
252
  it "should allow nil when allow_nil is set to true" do
258
253
  post :create,
259
- :user => {
260
- :name => "root",
261
- :pass => "12345",
262
- :membership => "standard",
263
- },
264
- :facts => nil
254
+ :params => {
255
+ :user => {
256
+ :name => "root",
257
+ :pass => "12345",
258
+ :membership => "standard",
259
+ },
260
+ :facts => { :test => 'test' }
261
+ }
262
+ assert_response :success
263
+ end
264
+
265
+ it "should allow blank when allow_blank is set to true" do
266
+ post :create,
267
+ :params => {
268
+ :user => {
269
+ :name => "root",
270
+ :pass => "12345",
271
+ :membership => "standard"
272
+ },
273
+ :age => ""
274
+ }
265
275
  assert_response :success
266
276
  end
267
277
 
@@ -270,7 +280,7 @@ describe UsersController do
270
280
  context "with valid input" do
271
281
  it "should succeed" do
272
282
  put :update,
273
- {
283
+ :params => {
274
284
  :id => 5,
275
285
  :user => {
276
286
  :name => "root",
@@ -293,27 +303,27 @@ describe UsersController do
293
303
  it "should raise an error" do
294
304
  expect{
295
305
  put :update,
296
- {
297
- :id => 5,
298
- :user => {
299
- :name => "root",
300
- :pass => "12345"
301
- },
302
- :comments => [
303
- {
304
- :comment => 'comment1'
306
+ :params => {
307
+ :id => 5,
308
+ :user => {
309
+ :name => "root",
310
+ :pass => "12345"
305
311
  },
306
- {
307
- :comment => {:bad_input => 5}
308
- }
309
- ]
310
- }
312
+ :comments => [
313
+ {
314
+ :comment => {:bad_input => 4}
315
+ },
316
+ {
317
+ :comment => {:bad_input => 5}
318
+ }
319
+ ]
320
+ }
311
321
  }.to raise_error(Apipie::ParamInvalid)
312
322
  end
313
323
  end
314
324
  it "should work with empty array" do
315
325
  put :update,
316
- {
326
+ :params => {
317
327
  :id => 5,
318
328
  :user => {
319
329
  :name => "root",
@@ -525,7 +535,8 @@ describe UsersController do
525
535
  :params => [{:full_name=>"oauth",
526
536
  :required=>false,
527
537
  :allow_nil => false,
528
- :validator=>"Must be String",
538
+ :allow_blank => false,
539
+ :validator=>"Must be a String",
529
540
  :description=>"\n<p>Authorization</p>\n",
530
541
  :name=>"oauth",
531
542
  :show=>true,
@@ -534,6 +545,7 @@ describe UsersController do
534
545
  :description=>"\n<p>Deprecated parameter not documented</p>\n",
535
546
  :expected_type=>"hash",
536
547
  :allow_nil=>false,
548
+ :allow_blank => false,
537
549
  :name=>"legacy_param",
538
550
  :required=>false,
539
551
  :full_name=>"legacy_param",
@@ -543,6 +555,7 @@ describe UsersController do
543
555
  :description=>"\n<p>Param description for all methods</p>\n",
544
556
  :expected_type=>"hash",
545
557
  :allow_nil=>false,
558
+ :allow_blank => false,
546
559
  :name=>"resource_param",
547
560
  :required=>false,
548
561
  :full_name=>"resource_param",
@@ -550,14 +563,16 @@ describe UsersController do
550
563
  :params=>
551
564
  [{:required=>true,
552
565
  :allow_nil => false,
553
- :validator=>"Must be String",
566
+ :allow_blank => false,
567
+ :validator=>"Must be a String",
554
568
  :description=>"\n<p>Username for login</p>\n",
555
569
  :name=>"ausername", :full_name=>"resource_param[ausername]",
556
570
  :show=>true,
557
571
  :expected_type=>"string"},
558
572
  {:required=>true,
559
573
  :allow_nil => false,
560
- :validator=>"Must be String",
574
+ :allow_blank => false,
575
+ :validator=>"Must be a String",
561
576
  :description=>"\n<p>Password for login</p>\n",
562
577
  :name=>"apassword", :full_name=>"resource_param[apassword]",
563
578
  :show=>true,
@@ -567,6 +582,7 @@ describe UsersController do
567
582
  },
568
583
  {:required=>false, :validator=>"Parameter has to be Integer.",
569
584
  :allow_nil => false,
585
+ :allow_blank => false,
570
586
  :description=>"\n<p>Company ID</p>\n",
571
587
  :name=>"id", :full_name=>"id",
572
588
  :show=>true,
@@ -690,17 +706,20 @@ EOS2
690
706
 
691
707
  describe "Parameter processing / extraction" do
692
708
  before do
709
+ Apipie.configuration.validate = true
693
710
  Apipie.configuration.process_params = true
711
+ controllers_dirname = File.expand_path('../dummy/app/controllers', File.dirname(__FILE__))
712
+ Dir.glob("#{controllers_dirname}/**/*") { |file| load(file) if File.file?(file) }
694
713
  end
695
714
 
696
715
  it "process correctly the parameters" do
697
- post :create, {:user => {:name => 'dummy', :pass => 'dummy', :membership => 'standard'}, :facts => nil}
716
+ post :create, :params => {:user => {:name => 'dummy', :pass => 'dummy', :membership => 'standard' }, :facts => {:test => 'test'}}
698
717
 
699
- expect(assigns(:api_params).with_indifferent_access).to eq({:user => {:name=>"dummy", :pass=>"dummy", :membership=>"standard"}, :facts => nil}.with_indifferent_access)
718
+ expect(assigns(:api_params).with_indifferent_access).to eq({:user => {:name=>"dummy", :pass=>"dummy", :membership=>"standard"}, :facts => {:test => 'test'}}.with_indifferent_access)
700
719
  end
701
720
 
702
721
  it "ignore not described parameters" do
703
- post :create, {:user => {:name => 'dummy', :pass => 'dummy', :membership => 'standard', :id => 0}}
722
+ post :create, :params => {:user => {:name => 'dummy', :pass => 'dummy', :membership => 'standard', :id => 0}}
704
723
 
705
724
  expect(assigns(:api_params).with_indifferent_access).to eq({:user => {:name=>"dummy", :pass=>"dummy", :membership=>"standard"}}.with_indifferent_access)
706
725
  end
@@ -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
@@ -4,13 +4,13 @@ module Concerns
4
4
 
5
5
  api!
6
6
  def index
7
- render :text => "OK #{params.inspect}"
7
+ render :plain => "OK #{params.inspect}"
8
8
  end
9
9
 
10
10
  api :GET, '/:resource_id/:id'
11
11
  param :id, String
12
12
  def show
13
- render :text => "OK #{params.inspect}"
13
+ render :plain => "OK #{params.inspect}"
14
14
  end
15
15
 
16
16
  def_param_group :concern do
@@ -23,19 +23,19 @@ module Concerns
23
23
  api :POST, '/:resource_id', "Create a :concern"
24
24
  param_group :concern
25
25
  def create
26
- render :text => "OK #{params.inspect}"
26
+ render :plain => "OK #{params.inspect}"
27
27
  end
28
28
 
29
29
  api :PUT, '/:resource_id/:id'
30
30
  param :id, String
31
31
  param_group :concern
32
32
  def update
33
- render :text => "OK #{params.inspect}"
33
+ render :plain => "OK #{params.inspect}"
34
34
  end
35
35
 
36
36
  api :GET, '/:resource_id/:custom_subst'
37
37
  def custom
38
- render :text => "OK #{params.inspect}"
38
+ render :plain => "OK #{params.inspect}"
39
39
  end
40
40
  end
41
41
  end
@@ -192,15 +192,15 @@ class UsersController < ApplicationController
192
192
  end
193
193
  def show
194
194
  unless params[:session] == "secret_hash"
195
- render :text => "Not authorized", :status => 401
195
+ render :plain => "Not authorized", :status => 401
196
196
  return
197
197
  end
198
198
 
199
199
  unless params[:id].to_i == 5
200
- render :text => "Not Found", :status => 404 and return
200
+ render :plain => "Not Found", :status => 404 and return
201
201
  end
202
202
 
203
- render :text => "OK"
203
+ render :plain => "OK"
204
204
  end
205
205
 
206
206
  def_param_group :credentials do
@@ -221,8 +221,9 @@ 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
- render :text => "OK #{params.inspect}"
226
+ render :plain => "OK #{params.inspect}"
226
227
  end
227
228
 
228
229
  api :PUT, "/users/:id", "Update an user"
@@ -231,13 +232,13 @@ class UsersController < ApplicationController
231
232
  param :comment, String
232
233
  end
233
234
  def update
234
- render :text => "OK #{params.inspect}"
235
+ render :plain => "OK #{params.inspect}"
235
236
  end
236
237
 
237
238
  api :POST, "/users/admin", "Create admin user"
238
239
  param_group :user, :as => :create
239
240
  def admin_create
240
- render :text => "OK #{params.inspect}"
241
+ render :plain => "OK #{params.inspect}"
241
242
  end
242
243
 
243
244
  api :GET, "/users", "List users"
@@ -247,14 +248,14 @@ class UsersController < ApplicationController
247
248
  param :oauth, nil,
248
249
  :desc => "Hide this global param (eg dont need auth here)"
249
250
  def index
250
- render :text => "List of users"
251
+ render :plain => "List of users"
251
252
  end
252
253
 
253
254
  api :GET, '/company_users', 'Get company users'
254
255
  api :GET, '/company/:id/users', 'Get users working in given company'
255
256
  param :id, Integer, :desc => "Company ID"
256
257
  def two_urls
257
- render :text => 'List of users'
258
+ render :plain => 'List of users'
258
259
  end
259
260
 
260
261
  api :GET, '/users/see_another', 'Boring method'
@@ -263,14 +264,14 @@ class UsersController < ApplicationController
263
264
  see 'development#users#index', "very interesting method reference"
264
265
  desc 'This method is boring, look at users#create. It is hidden from documentation.'
265
266
  def see_another
266
- render :text => 'This is very similar to create action'
267
+ render :plain => 'This is very similar to create action'
267
268
  end
268
269
 
269
270
 
270
271
  api :GET, '/users/desc_from_file', 'desc from file'
271
272
  document 'users/desc_from_file.md'
272
273
  def desc_from_file
273
- render :text => 'document from file action'
274
+ render :plain => 'document from file action'
274
275
  end
275
276
 
276
277
  api! 'Create user'
@@ -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
@@ -6,7 +6,7 @@ Apipie.configure do |config|
6
6
  # can be overriden in resource_description
7
7
  # by default is it 1.0 if not specified anywhere
8
8
  # this must be defined before api_base_url and app_info
9
- config.default_version = "development"
9
+ config.default_version = "development".freeze
10
10
 
11
11
  config.doc_base_url = "/apidoc"
12
12
 
@@ -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,30 @@ require 'rspec/rails'
9
9
 
10
10
  require 'apipie-rails'
11
11
 
12
+ module Rails4Compatibility
13
+ module Testing
14
+ def process(*args)
15
+ compatible_request(*args) { |*new_args| super(*new_args) }
16
+ end
17
+
18
+ def compatible_request(method, action, hash = {})
19
+ if hash.is_a?(Hash)
20
+ if Gem::Version.new(Rails.version) < Gem::Version.new('5.0.0')
21
+ hash = hash.dup
22
+ hash.merge!(hash.delete(:params) || {})
23
+ elsif hash.key?(:params)
24
+ hash = { :params => hash }
25
+ end
26
+ end
27
+ if hash.empty?
28
+ yield method, action
29
+ else
30
+ yield method, action, hash
31
+ end
32
+ end
33
+ end
34
+ end
35
+
12
36
  # Requires supporting ruby files with custom matchers and macros, etc,
13
37
  # in spec/support/ and its subdirectories.
14
38
  Dir[File.expand_path("../support/**/*.rb", __FILE__)].each {|f| require f}
@@ -41,3 +65,6 @@ RSpec.configure do |config|
41
65
  # end
42
66
  config.infer_spec_type_from_file_location!
43
67
  end
68
+
69
+ require 'action_controller/test_case.rb'
70
+ ActionController::TestCase::Behavior.send(:prepend, Rails4Compatibility::Testing)