camille 1.8.0 → 1.8.1
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 +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/camille/pick_and_omit.rb +4 -0
- data/lib/camille/testing.rb +4 -0
- data/lib/camille/types/record.rb +34 -23
- data/lib/camille/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 43d1b00b15c6fb8dd557ad587bc0113f56328571ae309bf01e9f16a90cf6cc6e
|
|
4
|
+
data.tar.gz: f2f994348c8466586b6444885ea225446f15e45fac89f2942aa88ab135287195
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: be0fba9d87641faa8df13542937860f4d04d2cbfb5ec65b7e3ace488aff7d373f6c83d5601fe1aa046e6d6b0df6ab565cc8a5fbe9669a4084613822a6af3c328
|
|
7
|
+
data.tar.gz: 426ab4e50a688e656552d512bed7b9f324bab52e23165d461abdba7843228a80ab9e2956d7232664a0e0b9f953061316104f4e59544dfdc569b4455e6c0e2efe
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.8.1
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
* `Record`, `Pick` and `Omit` now implement `check_params`, so nested objects inside them get their camelCase keys converted instead of failing with errors like `Expected array, got nil`. Record keys are still not converted.
|
|
8
|
+
* `response.data` in `camille/testing` no longer type checks non-200 responses, matching `Camille::Controller#render`, which only checks and converts keys for 200 responses. Non-200 bodies are returned as-is.
|
|
9
|
+
|
|
3
10
|
## 1.8.0
|
|
4
11
|
|
|
5
12
|
### Added
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -304,7 +304,7 @@ get '/products/data'
|
|
|
304
304
|
expect(response.data[:product][:available_stock]).to eq(1)
|
|
305
305
|
```
|
|
306
306
|
|
|
307
|
-
If
|
|
307
|
+
Since `Camille::Controller#render` only type checks and converts keys for 200 responses, `response.data` returns non-200 bodies as-is without validation. If a 200 response body fails the type check the helper raises `Camille::Testing::ResponseTypeError`. If the route has no Camille endpoint it raises `Camille::Testing::MissingEndpointError`.
|
|
308
308
|
|
|
309
309
|
## Versioning
|
|
310
310
|
|
data/lib/camille/testing.rb
CHANGED
|
@@ -24,6 +24,10 @@ module Camille
|
|
|
24
24
|
"No camille endpoint for #{controller_class_name}##{action}."
|
|
25
25
|
end
|
|
26
26
|
|
|
27
|
+
# Camille::Controller#render only type checks and converts keys for
|
|
28
|
+
# 200 responses, so mirror that here and return non-200 bodies as-is.
|
|
29
|
+
return deep_indifferent(parsed_body) unless status == 200
|
|
30
|
+
|
|
27
31
|
result = endpoint.response_type.check_params(parsed_body)
|
|
28
32
|
if result.type_error?
|
|
29
33
|
io = StringIO.new
|
data/lib/camille/types/record.rb
CHANGED
|
@@ -11,28 +11,14 @@ module Camille
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def check value
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
results = value.map.with_index do |(k, v), index|
|
|
17
|
-
[index, check_pair(k, v)]
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
errors = results.map do |index, result|
|
|
21
|
-
if result.instance_of?(Camille::TypeError)
|
|
22
|
-
["record[#{index}]", result]
|
|
23
|
-
else
|
|
24
|
-
nil
|
|
25
|
-
end
|
|
26
|
-
end.compact
|
|
14
|
+
check_with_method(value, :check)
|
|
15
|
+
end
|
|
27
16
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
else
|
|
34
|
-
Camille::TypeError.new("Expected hash, got #{value.inspect}.")
|
|
35
|
-
end
|
|
17
|
+
# Record keys are dynamic, so they are never converted between
|
|
18
|
+
# camelCase and snake_case. Only the values are checked with
|
|
19
|
+
# `check_params` so nested objects get their keys converted.
|
|
20
|
+
def check_params value
|
|
21
|
+
check_with_method(value, :check_params)
|
|
36
22
|
end
|
|
37
23
|
|
|
38
24
|
def self.[] key, value
|
|
@@ -44,9 +30,34 @@ module Camille
|
|
|
44
30
|
end
|
|
45
31
|
|
|
46
32
|
private
|
|
47
|
-
def
|
|
33
|
+
def check_with_method value, method_name
|
|
34
|
+
if value.is_a? ::Hash
|
|
35
|
+
|
|
36
|
+
results = value.map.with_index do |(k, v), index|
|
|
37
|
+
[index, check_pair(k, v, method_name)]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
errors = results.map do |index, result|
|
|
41
|
+
if result.instance_of?(Camille::TypeError)
|
|
42
|
+
["record[#{index}]", result]
|
|
43
|
+
else
|
|
44
|
+
nil
|
|
45
|
+
end
|
|
46
|
+
end.compact
|
|
47
|
+
|
|
48
|
+
if errors.empty?
|
|
49
|
+
Camille::Checked.new(fingerprint, results.map{|_, result| [result[0].value, result[1].value]}.to_h)
|
|
50
|
+
else
|
|
51
|
+
Camille::TypeError.new(**errors.to_h)
|
|
52
|
+
end
|
|
53
|
+
else
|
|
54
|
+
Camille::TypeError.new("Expected hash, got #{value.inspect}.")
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def check_pair key, value, method_name
|
|
48
59
|
key_result = @key.check key
|
|
49
|
-
value_result = @value.
|
|
60
|
+
value_result = @value.public_send(method_name, value)
|
|
50
61
|
|
|
51
62
|
if key_result.checked? && value_result.checked?
|
|
52
63
|
[key_result, value_result]
|
data/lib/camille/version.rb
CHANGED