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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ed1bdf75c9a416f57b7bfbde026eaf31a2b9663386df953ff7ed828ce41b5b6
4
- data.tar.gz: 835d965a9ffc3e2727271a7a2e35b1e936be77d7ae93b12896d0a1693bb52116
3
+ metadata.gz: 380a36633d08fb17e45a86ad9d94c329620487717be29f4ee3cfd4573a2ba1de
4
+ data.tar.gz: 00f2ec575910e8f8c7b8ab563a07b07f8c60e11740ecf10253d45b3f22730ac1
5
5
  SHA512:
6
- metadata.gz: 31a485ee38ce7e938530eb28bbef35b9be11a003b41c3cd12294c4b71bdabc4fc7ddbed461118445ac1ff9d798a79e54d9bce5c3628ef9feb1e5e4033a5ba29a
7
- data.tar.gz: 2f0384c4a8f23d7554df00a1d5300d6c125109f1b334f317ba4105c1af558d1526f0bddd6cd75bd9e0f9590fc745979db497a98612fef70f0f80c155deb1b3c2
6
+ metadata.gz: bf99fdd4024988e87e6b7fd079f17347750aa80ce75cd7d4c9f71857e373abf99958672adb2af49886beddb9221c3f947060cca21bbacddaec9f0488e3e2a7f8
7
+ data.tar.gz: be4f4ed87278de54137fa89661ede7a931160fc50996d7d7e36f90efaef2c6b31ff198929880ab36812e19893834eb67ab40eb923f1300465c09c6b661222f7c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v3.0.1 (2021-08-24)
2
+
3
+ - Fixing model validation when the value is nil (eg: list = `[nil]` model.valid? should be false). (From issue: #9)
4
+
1
5
  ## v3.0.0 (2021-04-13)
2
6
 
3
7
  - Ruby 3 support.
@@ -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)).any?
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
@@ -1,3 +1,3 @@
1
1
  module ActiveModelValidatesIntersectionOf
2
- VERSION = "3.0.0".freeze
2
+ VERSION = "3.0.1".freeze
3
3
  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.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-04-13 00:00:00.000000000 Z
11
+ date: 2021-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel