standardapi 6.0.0.29 → 6.0.0.30

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
  SHA256:
3
- metadata.gz: 3670132e90418137f095c8e7741310e2911bfde21e78579e27ea6c54ae88d0f1
4
- data.tar.gz: 205778759e7188eda509e289495a383d6a5ff037116fd5043a519f95c5b7222d
3
+ metadata.gz: bf7ed75a06eda9f024ebd87caccab44573802435d0494944137d92da6403fca2
4
+ data.tar.gz: f44ad9cdd0d8bb87bc971f0b11b8f50b5f5f1289911d7bf4764f6f867b59b407
5
5
  SHA512:
6
- metadata.gz: 2d4a009d0ea47b18ebc5088d81bdf4518e9a22749b1ea0a17e8f7b5504be42dbeea60945ad75eeb5a4cdfda866f39edc12391262ff64b2a5cc3748011cb0c4bc
7
- data.tar.gz: 49a638815647e3fbe6d63dc4eda87eda4703425b2c36e4565763cc0aad1abf0934d54d8f18858d00ac733f1e4662873f5ff586e1cdf27aafdaebfbc825703b71
6
+ metadata.gz: 2f0f4ba53a851f87467a584b0a37708a1d2c6a52fc3360c31fbd50462af17918b7c43b435001410984291db24a451940e97487fc549f993d35ecc63d832d3b20
7
+ data.tar.gz: 26d70be42fd115039c04a4a0ba614225c05a549af0847d3473659c9d593002cd11addcfd330000163eb9d1597843c274593ba99ddd6f9a57ee39b83e8a05fcbb
@@ -7,6 +7,7 @@ module StandardAPI
7
7
  klass.helper_method :includes, :orders, :model, :models, :resource_limit,
8
8
  :default_limit
9
9
  klass.before_action :set_standardapi_headers
10
+ klass.rescue_from StandardAPI::ParameterMissing, with: :bad_request
10
11
  klass.rescue_from StandardAPI::UnpermittedParameters, with: :bad_request
11
12
  klass.append_view_path(File.join(File.dirname(__FILE__), 'views'))
12
13
  klass.extend(ClassMethods)
@@ -284,9 +285,9 @@ module StandardAPI
284
285
  limit = params.permit(:limit)[:limit]&.to_i || default_limit
285
286
 
286
287
  if !limit
287
- raise ActionController::ParameterMissing.new(:limit)
288
+ raise StandardAPI::ParameterMissing.new(:limit)
288
289
  elsif limit > resource_limit
289
- raise ActionController::UnpermittedParameters.new([:limit, limit])
290
+ raise StandardAPI::UnpermittedParameters.new([:limit, limit])
290
291
  end
291
292
 
292
293
  limit
@@ -2,6 +2,15 @@ module StandardAPI
2
2
  class StandardAPIError < StandardError
3
3
  end
4
4
 
5
+ class ParameterMissing < StandardAPIError
6
+ attr_reader :param
7
+
8
+ def initialize(param)
9
+ @param = param
10
+ super("param is missing or the value is empty: #{param}")
11
+ end
12
+ end
13
+
5
14
  class UnpermittedParameters < StandardAPIError
6
15
  attr_reader :params
7
16
 
@@ -85,9 +85,12 @@ module StandardAPI
85
85
  end
86
86
 
87
87
  test '#create.html' do
88
- return unless supports_format(:html)
88
+ return unless supports_format(:html, :create)
89
+
90
+ attrs = attributes_for(singular_name, :nested).select do |k,v|
91
+ !model.readonly_attributes.include?(k.to_s)
92
+ end
89
93
 
90
- attrs = attributes_for(singular_name, :nested).select{ |k,v| !model.readonly_attributes.include?(k.to_s) }
91
94
  mask.each { |k, v| attrs[k] = v }
92
95
  create_webmocks(attrs)
93
96
 
@@ -98,7 +101,7 @@ module StandardAPI
98
101
  end
99
102
 
100
103
  test '#create.html with invalid attributes renders edit action' do
101
- return unless supports_format(:html)
104
+ return unless supports_format(:html, :create)
102
105
 
103
106
  trait = FactoryBot.factories[singular_name].definition.defined_traits.any? { |x| x.name.to_s == 'invalid' }
104
107
 
@@ -37,10 +37,10 @@ module StandardAPI
37
37
 
38
38
  test '#index.json params[:limit] does not exceed maximum limit' do
39
39
  return if !resource_limit || resource_limit == Float::INFINITY
40
-
41
- assert_raises ActionController::UnpermittedParameters do
42
- get resource_path(:index, format: :json), params: { limit: resource_limit + 1 }
43
- end
40
+
41
+ get resource_path(:index, format: :json), params: { limit: resource_limit + 1 }
42
+ assert_response :bad_request
43
+ assert_equal 'found unpermitted parameters: :limit, 1001', response.body
44
44
  end
45
45
 
46
46
  test '#index.json params[:where]' do
@@ -18,7 +18,7 @@ module StandardAPI::TestCase
18
18
  assert_equal(expected, *args)
19
19
  end
20
20
  end
21
-
21
+
22
22
  def self.included(klass)
23
23
  [:filters, :orders, :includes].each do |attribute|
24
24
  klass.send(:class_attribute, attribute)
@@ -53,14 +53,14 @@ module StandardAPI::TestCase
53
53
  end
54
54
  end
55
55
 
56
- def supports_format(format)
56
+ def supports_format(format, action=nil)
57
57
  count = controller_class.view_paths.count do |path|
58
- !Dir.glob("#{path.instance_variable_get(:@path)}/{#{model.name.underscore},application}/**/*.#{format}*").empty?
58
+ !Dir.glob("#{path.instance_variable_get(:@path)}/{#{model.name.underscore},application}/**/#{action || '*'}.#{format}*").empty?
59
59
  end
60
-
60
+
61
61
  count > 0
62
62
  end
63
-
63
+
64
64
  def default_orders
65
65
  controller_class.new.send(:default_orders)
66
66
  end
@@ -76,7 +76,7 @@ module StandardAPI::TestCase
76
76
  def model
77
77
  self.class.model
78
78
  end
79
-
79
+
80
80
  def mask
81
81
  {}
82
82
  end
@@ -98,11 +98,11 @@ module StandardAPI::TestCase
98
98
  def singular_name
99
99
  model.model_name.singular
100
100
  end
101
-
101
+
102
102
  def plural_name
103
103
  model.model_name.plural
104
104
  end
105
-
105
+
106
106
  def create_webmocks(attributes)
107
107
  attributes.each do |attribute, value|
108
108
  self.class.model.validators_on(attribute)
@@ -122,7 +122,7 @@ module StandardAPI::TestCase
122
122
  value
123
123
  end
124
124
  end
125
-
125
+
126
126
  def normalize_to_json(record, attribute, value)
127
127
  value = normalize_attribute(record, attribute, value)
128
128
  return nil if value.nil?
@@ -149,7 +149,7 @@ module StandardAPI::TestCase
149
149
 
150
150
  def controller_class
151
151
  controller_class_name = self.name.gsub(/Test$/, '')
152
- controller_class_name.constantize
152
+ controller_class_name.constantize
153
153
  rescue NameError => e
154
154
  raise e if e.message != "uninitialized constant #{controller_class_name}"
155
155
  end
@@ -166,7 +166,7 @@ module StandardAPI::TestCase
166
166
  return @model if defined?(@model) && @model
167
167
 
168
168
  klass_name = controller_class.name.gsub(/Controller$/, '').singularize
169
-
169
+
170
170
  begin
171
171
  @model = klass_name.constantize
172
172
  rescue NameError
@@ -1,3 +1,3 @@
1
1
  module StandardAPI
2
- VERSION = '6.0.0.29'
2
+ VERSION = '6.0.0.30'
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: 6.0.0.29
4
+ version: 6.0.0.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Bracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-12 00:00:00.000000000 Z
11
+ date: 2020-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails