validates_overlap 0.8.2 → 0.8.4
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/README.md +3 -2
- data/VERSION +1 -1
- data/lib/validates_overlap/overlap_validator.rb +7 -1
- data/spec/dummy/spec/overlap_validator_spec.rb +10 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9dae06e643adf4f4a6eb421256e6d6e48d920c9
|
4
|
+
data.tar.gz: 917874d97876ac62d2ee48a0f18e2b031d086782
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2928b3fca519e208347d21b015348cceb3cfda570085b7234dd5c32b43d589e04c2a91f13888fceff780dad2e8b7d91c2b223f81d04b01362fe44365ec7a4c0
|
7
|
+
data.tar.gz: 6a7704bef1db53645010e021d880ebe9add11b8ebe17153b43b8f487134c5f3214120b3f5b009eb8c553aad5f3d1f48b0956a72859aa226359cdaadc2b1aecd3
|
data/README.md
CHANGED
@@ -31,7 +31,7 @@ validates :starts_at, :ends_at, :overlap => true
|
|
31
31
|
validates :starts_at, :ends_at, :overlap => {:scope => "user_id"}
|
32
32
|
```
|
33
33
|
|
34
|
-
#### exclude
|
34
|
+
#### exclude edge(s)
|
35
35
|
|
36
36
|
```ruby
|
37
37
|
validates :starts_at, :ends_at, :overlap => {:exclude_edges => "starts_at"}
|
@@ -44,10 +44,11 @@ validates :starts_at, :ends_at, :overlap => {:exclude_edges => ["starts_at", "en
|
|
44
44
|
validates :starts_at, :ends_at, :overlap => {:start_shift => -1.day, :end_shift => 1.day}
|
45
45
|
```
|
46
46
|
|
47
|
-
#### define custom validation key and message
|
47
|
+
#### define custom validation key(s) and message
|
48
48
|
|
49
49
|
```ruby
|
50
50
|
validates :starts_at, :ends_at, :overlap => {:message_title => "Some validation title", :message_content => "Some validation message"}
|
51
|
+
validates :starts_at, :ends_at, :overlap => {:message_title => [:start_at, :end_at], :message_content => "Some validation message"}
|
51
52
|
```
|
52
53
|
|
53
54
|
#### with complicated relations
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.4
|
@@ -24,7 +24,13 @@ class OverlapValidator < ActiveModel::EachValidator
|
|
24
24
|
end
|
25
25
|
|
26
26
|
if record.respond_to? attributes.first
|
27
|
-
|
27
|
+
if options[:message_title].is_a?(Array)
|
28
|
+
options[:message_title].each do |key|
|
29
|
+
record.errors.add(key, options[:message_content] || :overlap)
|
30
|
+
end
|
31
|
+
else
|
32
|
+
record.errors.add(options[:message_title] || attributes.first, options[:message_content] || :overlap)
|
33
|
+
end
|
28
34
|
else
|
29
35
|
record.errors.add(options[:message_title] || :base, options[:message_content] || :overlap)
|
30
36
|
end
|
@@ -18,5 +18,15 @@ describe OverlapValidator do
|
|
18
18
|
subject.validate(meeting)
|
19
19
|
expect(meeting.errors[:optional_key]).to eq ['Message content']
|
20
20
|
end
|
21
|
+
|
22
|
+
it 'should be possible to configure multiple keys for message' do
|
23
|
+
subject = OverlapValidator.new(attributes: [:starts_at, :ends_at])
|
24
|
+
meeting = Meeting.new
|
25
|
+
expect(subject).to receive(:overlapped_exists?) { true }
|
26
|
+
allow(subject).to receive(:options) { { message_title: [:optional_key_1, 'optional_key_2'], message_content: 'Message content' } }
|
27
|
+
subject.validate(meeting)
|
28
|
+
expect(meeting.errors[:optional_key_1]).to eq ['Message content']
|
29
|
+
expect(meeting.errors[:optional_key_2]).to eq ['Message content']
|
30
|
+
end
|
21
31
|
end
|
22
32
|
end
|