active_model_validates_intersection_of 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/active_model_validates_intersection_of/validator.rb +1 -1
- data/lib/active_model_validates_intersection_of/version.rb +1 -1
- data/spec/lib/intersection_validator_spec.rb +32 -0
- data/spec/lib/validates_intersection_of_alias_spec.rb +16 -0
- 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: 380a36633d08fb17e45a86ad9d94c329620487717be29f4ee3cfd4573a2ba1de
|
4
|
+
data.tar.gz: 00f2ec575910e8f8c7b8ab563a07b07f8c60e11740ecf10253d45b3f22730ac1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf99fdd4024988e87e6b7fd079f17347750aa80ce75cd7d4c9f71857e373abf99958672adb2af49886beddb9221c3f947060cca21bbacddaec9f0488e3e2a7f8
|
7
|
+
data.tar.gz: be4f4ed87278de54137fa89661ede7a931160fc50996d7d7e36f90efaef2c6b31ff198929880ab36812e19893834eb67ab40eb923f1300465c09c6b661222f7c
|
data/CHANGELOG.md
CHANGED
@@ -12,7 +12,7 @@ module ActiveModelValidatesIntersectionOf
|
|
12
12
|
def validate_each(record, attribute, value)
|
13
13
|
raise ArgumentError, "value must be an array" unless value.is_a?(Array)
|
14
14
|
|
15
|
-
if (value - members(record)).
|
15
|
+
if (value - members(record)).size > 0
|
16
16
|
record.errors.add(attribute, :inclusion, **options.except(:in, :within).merge!(value: value))
|
17
17
|
end
|
18
18
|
end
|
@@ -37,6 +37,22 @@ RSpec.describe IntersectionValidator do
|
|
37
37
|
describe "with an invalid list" do
|
38
38
|
it_behaves_like "invalid object"
|
39
39
|
end
|
40
|
+
|
41
|
+
context "when the model value is an array with nil value" do
|
42
|
+
class ListTest
|
43
|
+
VALID_ARRAY = ["z", "x", 5 , 6]
|
44
|
+
include ActiveModel::Validations
|
45
|
+
attr_accessor :list
|
46
|
+
validates_intersection_of :list, within: VALID_ARRAY, message: "not valid"
|
47
|
+
end
|
48
|
+
|
49
|
+
subject { ListTest.new }
|
50
|
+
|
51
|
+
it "should return as invalid" do
|
52
|
+
subject.list = [nil]
|
53
|
+
expect(subject.valid?).to eq(false)
|
54
|
+
end
|
55
|
+
end
|
40
56
|
end
|
41
57
|
|
42
58
|
context "with :within option" do
|
@@ -61,6 +77,22 @@ RSpec.describe IntersectionValidator do
|
|
61
77
|
it_behaves_like "invalid object"
|
62
78
|
end
|
63
79
|
end
|
80
|
+
|
81
|
+
context "when the model value is an array with nil value" do
|
82
|
+
class ListTest
|
83
|
+
VALID_ARRAY = ["z", "x", 5 , 6]
|
84
|
+
include ActiveModel::Validations
|
85
|
+
attr_accessor :list
|
86
|
+
validates_intersection_of :list, within: VALID_ARRAY, message: "not valid"
|
87
|
+
end
|
88
|
+
|
89
|
+
subject { ListTest.new }
|
90
|
+
|
91
|
+
it "should return as invalid" do
|
92
|
+
subject.list = [nil]
|
93
|
+
expect(subject.valid?).to eq(false)
|
94
|
+
end
|
95
|
+
end
|
64
96
|
end
|
65
97
|
|
66
98
|
context "validate with lambda" do
|
@@ -65,5 +65,21 @@ RSpec.describe ActiveModel::Validations::HelperMethods do
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
end
|
68
|
+
|
69
|
+
context "when the model value is an array with nil value" do
|
70
|
+
class ListTest
|
71
|
+
VALID_ARRAY = ["z", "x", 5 , 6]
|
72
|
+
include ActiveModel::Validations
|
73
|
+
attr_accessor :list
|
74
|
+
validates_intersection_of :list, within: VALID_ARRAY, message: "not valid"
|
75
|
+
end
|
76
|
+
|
77
|
+
subject { ListTest.new }
|
78
|
+
|
79
|
+
it "should return as invalid" do
|
80
|
+
subject.list = [nil]
|
81
|
+
expect(subject.valid?).to eq(false)
|
82
|
+
end
|
83
|
+
end
|
68
84
|
end
|
69
85
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_model_validates_intersection_of
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael Biriba
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|