salestation 5.0.2 → 5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/salestation/rspec/glia_input_validation_error_matcher.rb +35 -14
- data/lib/salestation/rspec.rb +17 -0
- data/salestation.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43663c5f6d78d7238e66e9ac88a06a49facfcaf45a329534e44e20891ea1baa9
|
4
|
+
data.tar.gz: 97661dd29a53ab956cbe0c78522b382d052bd4c6f339208fe126f7d3c51f8526
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee4cf2f592d41548e187277789ec6d3484748dc7cc152f3a9b4e4b63b438314e5fe96ab3aeb92dbd4729a485b4d9e73b518904459309b19f3da7a507595100ce
|
7
|
+
data.tar.gz: 22a1c5415ded67ebc22c5f67ef6332706571a156000aac7e5195101c73be14dc950b5f208fb24b19e27c94b70c3c854dc8a5da485a01b030d578e9ccaac92c57
|
data/.gitignore
CHANGED
@@ -15,24 +15,24 @@ module Salestation
|
|
15
15
|
@field_error_messages = {}
|
16
16
|
end
|
17
17
|
|
18
|
-
def on(
|
19
|
-
@fields <<
|
18
|
+
def on(*nested_fields)
|
19
|
+
@fields << nested_fields
|
20
20
|
self
|
21
21
|
end
|
22
22
|
|
23
23
|
def with_type(*types)
|
24
|
-
@field_error_types[@fields.last] = types
|
24
|
+
@field_error_types[field_to_key(@fields.last)] = types
|
25
25
|
self
|
26
26
|
end
|
27
27
|
|
28
28
|
def with_message(*messages)
|
29
|
-
@field_error_messages[@fields.last] = messages
|
29
|
+
@field_error_messages[field_to_key(@fields.last)] = messages
|
30
30
|
self
|
31
31
|
end
|
32
32
|
|
33
33
|
def matches?(actual)
|
34
34
|
@fields.all? do |field|
|
35
|
-
check_field_exists(
|
35
|
+
check_field_exists(actual, *field) &&
|
36
36
|
check_field_error_types(field, actual) &&
|
37
37
|
check_field_error_messages(field, actual)
|
38
38
|
end
|
@@ -40,24 +40,45 @@ module Salestation
|
|
40
40
|
|
41
41
|
private
|
42
42
|
|
43
|
-
def check_field_exists(field,
|
44
|
-
actual[:error_details].key?(field)
|
43
|
+
def check_field_exists(actual, field, *nested_fields)
|
44
|
+
actual[:error_details].key?(field) &&
|
45
|
+
(
|
46
|
+
nested_fields.empty? ||
|
47
|
+
actual[:error_details][field].any? do |nested_hash|
|
48
|
+
check_field_exists(nested_hash, *nested_fields)
|
49
|
+
end
|
50
|
+
)
|
45
51
|
end
|
46
52
|
|
47
53
|
def check_field_error_types(field, actual)
|
48
|
-
return true unless @field_error_types[field]
|
54
|
+
return true unless @field_error_types[field_to_key(field)]
|
49
55
|
|
50
|
-
actual_error_types = actual
|
51
|
-
|
52
|
-
(@field_error_types[field] - actual_error_types).empty?
|
56
|
+
actual_error_types = fetch_field_attribute_nested(actual, :type, *field)
|
57
|
+
(@field_error_types[field_to_key(field)] - actual_error_types).empty?
|
53
58
|
end
|
54
59
|
|
55
60
|
def check_field_error_messages(field, actual)
|
56
|
-
return true unless @field_error_messages[field]
|
61
|
+
return true unless @field_error_messages[field_to_key(field)]
|
62
|
+
|
63
|
+
actual_error_messages = fetch_field_attribute_nested(actual, :message, *field)
|
64
|
+
(@field_error_messages[field_to_key(field)] - actual_error_messages).empty?
|
65
|
+
end
|
57
66
|
|
58
|
-
actual_error_messages = actual[:error_details].fetch(field).map { |f| f.fetch(:message) }
|
59
67
|
|
60
|
-
|
68
|
+
def fetch_field_attribute_nested(actual, attribute, field, *nested_fields)
|
69
|
+
if nested_fields.empty?
|
70
|
+
actual[:error_details].fetch(field).map { |f| f.fetch(attribute) }
|
71
|
+
else
|
72
|
+
actual[:error_details][field]
|
73
|
+
.lazy
|
74
|
+
.map { |error_hash| fetch_field_attribute_nested(error_hash, attribute, *nested_fields) }
|
75
|
+
.reject(&:nil?)
|
76
|
+
.first
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def field_to_key(fields)
|
81
|
+
fields.join('->').to_sym
|
61
82
|
end
|
62
83
|
end
|
63
84
|
end
|
data/lib/salestation/rspec.rb
CHANGED
@@ -44,6 +44,23 @@ module Salestation
|
|
44
44
|
# .on(:phone_number).with_type(Glia::Errors::INVALID_FORMAT_ERROR)
|
45
45
|
# )
|
46
46
|
#
|
47
|
+
# also has support for nested errors:
|
48
|
+
# nesting can be represented by calling `on` method with multiple arguments, for example when
|
49
|
+
# you have a hash like
|
50
|
+
# {
|
51
|
+
# nested: {
|
52
|
+
# name: ''
|
53
|
+
# }
|
54
|
+
# }
|
55
|
+
# Then you can call it like glia_input_validation_error.on(:nested, :name)
|
56
|
+
#
|
57
|
+
# expect(result).to be_failure
|
58
|
+
# .with_invalid_input
|
59
|
+
# .containing(
|
60
|
+
# glia_input_validation_error
|
61
|
+
# .on(:nested, :name).with_type(Glia::Errors::INVALID_VALUE_ERROR)
|
62
|
+
# )
|
63
|
+
#
|
47
64
|
# Everything after be_failure is optional. You could also use `.containing`
|
48
65
|
# multiple times like this:
|
49
66
|
#
|
data/salestation.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: salestation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.0
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Glia TechMovers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|