axn 0.1.0.pre.alpha.2.5.1 → 0.1.0.pre.alpha.2.5.1.2
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/.rubocop.yml +5 -2
- data/CHANGELOG.md +7 -0
- data/lib/action/core/contract.rb +12 -1
- data/lib/action/core/contract_for_subfields.rb +1 -12
- data/lib/action/core/validation/validators/type_validator.rb +1 -1
- data/lib/axn/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: 42cc1a4a04b3e66593f20e8c705d21b18d0805b335ecc0f466aadbe66a4b34b1
|
4
|
+
data.tar.gz: 6e402f557bac045b01271a782a549264b52435a31ce4422b9023df3305cc378d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dc07f5c6be221dc0d46961c8ea2810ed42a8b17d5bc195f4b695b782695f489259f6e9f6c4369b2e13e2b87f1a779db7fb71dbf8fd59b5712169512bac2c217
|
7
|
+
data.tar.gz: d772ed5b642945eaa6ed3c09d0161b26e7763ec692e481d70df893b88a9d1779018978806fb10459d84f8479eb2a5616a56e4c109723dc610227ec0e41998502
|
data/.rubocop.yml
CHANGED
@@ -33,17 +33,20 @@ Style/DoubleNegation:
|
|
33
33
|
Metrics/BlockLength:
|
34
34
|
Enabled: false
|
35
35
|
|
36
|
+
Metrics/ModuleLength:
|
37
|
+
Enabled: false
|
38
|
+
|
36
39
|
Metrics/MethodLength:
|
37
40
|
Max: 60
|
38
41
|
|
39
42
|
Metrics/PerceivedComplexity:
|
40
|
-
Max:
|
43
|
+
Max: 16
|
41
44
|
|
42
45
|
Metrics/AbcSize:
|
43
46
|
Max: 60
|
44
47
|
|
45
48
|
Metrics/CyclomaticComplexity:
|
46
|
-
Max:
|
49
|
+
Max: 16
|
47
50
|
|
48
51
|
Lint/EmptyBlock:
|
49
52
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.1.0-alpha.2.5.1.2
|
4
|
+
* [BUGFIX] Subfield expectations: now support hashes with string keys (using with_indifferent_access)
|
5
|
+
* [BUGFIX] Subfield expectations: Model reader fields now cache initial value (otherwise get fresh instance each call, cannot make in-memory changes)
|
6
|
+
|
7
|
+
## 0.1.0-alpha.2.5.1.1
|
8
|
+
* [BUGFIX] TypeValidator must handle anonymous classes when determining if given argument is an RSpec mock
|
9
|
+
|
3
10
|
## 0.1.0-alpha.2.5.1
|
4
11
|
* Added new `model` validator for expectations
|
5
12
|
* [FEAT] Extended `expects` with the `on:` key to allow declaring nested data shapes/validations
|
data/lib/action/core/contract.rb
CHANGED
@@ -109,6 +109,17 @@ module Action
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
+
def define_memoized_reader_method(field, &block)
|
113
|
+
define_method(field) do
|
114
|
+
ivar = :"@_memoized_reader_#{field}"
|
115
|
+
cached_val = instance_variable_get(ivar)
|
116
|
+
return cached_val if cached_val.present?
|
117
|
+
|
118
|
+
value = instance_exec(&block)
|
119
|
+
instance_variable_set(ivar, value)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
112
123
|
def _define_field_reader(field)
|
113
124
|
# Allow local access to explicitly-expected fields -- even externally-expected needs to be available locally
|
114
125
|
# (e.g. to allow success message callable to reference exposed fields)
|
@@ -120,7 +131,7 @@ module Action
|
|
120
131
|
raise ArgumentError, "Model validation expects to be given a field ending in _id (given: #{field})" unless field.to_s.end_with?("_id")
|
121
132
|
raise ArgumentError, "Failed to define model reader - #{name} is already defined" if method_defined?(name)
|
122
133
|
|
123
|
-
|
134
|
+
define_memoized_reader_method(name) do
|
124
135
|
Validators::ModelValidator.instance_for(field:, klass:, id: public_send(field))
|
125
136
|
end
|
126
137
|
end
|
@@ -82,22 +82,11 @@ module Action
|
|
82
82
|
raise ArgumentError, "expects does not support duplicate sub-keys (i.e. `#{field}` is already defined)" if method_defined?(field)
|
83
83
|
|
84
84
|
define_memoized_reader_method(field) do
|
85
|
-
public_send(on)
|
85
|
+
Action::Validation::Subfields.extract(field, public_send(on))
|
86
86
|
end
|
87
87
|
|
88
88
|
_define_model_reader(field, validations[:model]) if validations.key?(:model)
|
89
89
|
end
|
90
|
-
|
91
|
-
def define_memoized_reader_method(field, &block)
|
92
|
-
define_method(field) do
|
93
|
-
ivar = :"@_memoized_reader_#{field}"
|
94
|
-
cached_val = instance_variable_get(ivar)
|
95
|
-
return cached_val if cached_val.present?
|
96
|
-
|
97
|
-
value = instance_exec(&block)
|
98
|
-
instance_variable_set(ivar, value)
|
99
|
-
end
|
100
|
-
end
|
101
90
|
end
|
102
91
|
|
103
92
|
module InstanceMethods
|
@@ -19,7 +19,7 @@ module Action
|
|
19
19
|
value.is_a?(String) && value.match?(/\A[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}\z/i)
|
20
20
|
else
|
21
21
|
# NOTE: allow mocks to pass type validation by default (much easier testing ergonomics)
|
22
|
-
next true if Action.config.env.test? && value.class.name
|
22
|
+
next true if Action.config.env.test? && value.class.name&.start_with?("RSpec::Mocks::")
|
23
23
|
|
24
24
|
value.is_a?(type)
|
25
25
|
end
|
data/lib/axn/version.rb
CHANGED