standardapi 5.2.0.5 → 5.2.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e091251cb3cfdcaaca2c8779fe6104dbd64e184004e98c8185574103c7fb4ebf
4
- data.tar.gz: 7f256e0dc1c67018b147ad3b0b3784ed07edd8cea49f2c26d8f9958eb3c0e9db
3
+ metadata.gz: e4b7a8c23e3996a005396e58c1586e921276a66d9c7bb69a2c3679d72eb4e56a
4
+ data.tar.gz: 840ae632d429e954b66edbba5f4cba69c5c0ab17ec6bda8b2e18e34c10040880
5
5
  SHA512:
6
- metadata.gz: d92f6d09f3559bde47d8d30750e60359c527e6bdbebafaf036971720dfca80be6315a4b64f0c17675bd7bc00b6de45cb59c9f57740e6c38ae269b437df1a226f
7
- data.tar.gz: 04e267511914cbd3e3bb047ad8287fe43d10587b0e3b08a6579bcdca785dcd45336f9e7497c940ff7ff9b63efdeed8d7a0c6389dcd87b891ea7f55f718f6dae4
6
+ metadata.gz: c395e361f79fce96f322ab5311a812300c416b05a28e46ae070164da15f8df23a2754663843ecf7969b736f0d7188142586d8c7b18a1d3d5d300a255cefc63bb
7
+ data.tar.gz: 863685a1c335afc5315545f0c511472a58cc588eccbe2a3273cac6a43d11cb86118eab40bdf6043ab3165a107fbddcca7381114dbdf3cb38fb6ed41ea51fd6b3
@@ -2,7 +2,7 @@ module StandardAPI
2
2
  module Controller
3
3
 
4
4
  def self.included(klass)
5
- klass.helper_method :includes, :orders, :model, :resource_limit
5
+ klass.helper_method :includes, :orders, :model, :resource_limit, :default_limit
6
6
  klass.before_action :set_standardapi_headers
7
7
  klass.append_view_path(File.join(File.dirname(__FILE__), 'views'))
8
8
  klass.extend(ClassMethods)
@@ -208,11 +208,20 @@ module StandardAPI
208
208
  1000
209
209
  end
210
210
 
211
+ # The default limit if params[:limit] is no specified in a request.
212
+ # If this value should be less than the `resource_limit`. Return `nil` if
213
+ # you want the limit param to be required.
214
+ def default_limit
215
+ nil
216
+ end
217
+
211
218
  def limit
212
219
  if resource_limit
213
- limit = params.require(:limit).to_i
220
+ limit = params.permit(:limit)[:limit]&.to_i || default_limit
214
221
 
215
- if limit > resource_limit
222
+ if !limit
223
+ raise ActionController::ParameterMissing.new(:limit)
224
+ elsif limit > resource_limit
216
225
  raise ActionController::UnpermittedParameters.new([:limit, limit])
217
226
  end
218
227
 
@@ -69,6 +69,10 @@ module StandardAPI::TestCase
69
69
  controller_class.new.send(:resource_limit)
70
70
  end
71
71
 
72
+ def default_limit
73
+ controller_class.new.send(:default_limit)
74
+ end
75
+
72
76
  def model
73
77
  self.class.model
74
78
  end
@@ -13,6 +13,7 @@ module StandardAPI
13
13
 
14
14
  test '#index.json requires limit' do
15
15
  return if !resource_limit || resource_limit == Float::INFINITY
16
+ return if default_limit
16
17
 
17
18
  begin
18
19
  get resource_path(:index, format: :json)
@@ -21,6 +22,13 @@ module StandardAPI
21
22
  end
22
23
  end
23
24
 
25
+ test '#index.json uses default_limit' do
26
+ return if !default_limit
27
+
28
+ get resource_path(:index, format: :json)
29
+ assert_response :ok
30
+ end
31
+
24
32
  test '#index.json params[:limit]' do
25
33
  get resource_path(:index, format: :json), params: { limit: 1 }
26
34
  models = @controller.instance_variable_get("@#{plural_name}")
@@ -1,3 +1,3 @@
1
1
  module StandardAPI
2
- VERSION = '5.2.0.5'
2
+ VERSION = '5.2.0.6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standardapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0.5
4
+ version: 5.2.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Bracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-06 00:00:00.000000000 Z
11
+ date: 2018-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -324,7 +324,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
324
324
  version: '0'
325
325
  requirements: []
326
326
  rubyforge_project:
327
- rubygems_version: 2.7.6
327
+ rubygems_version: 2.7.7
328
328
  signing_key:
329
329
  specification_version: 4
330
330
  summary: StandardAPI makes it easy to expose a query interface for your Rails models