hiccup 0.5.16 → 0.5.17
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/lib/hiccup/validatable.rb +1 -1
- data/lib/hiccup/version.rb +1 -1
- data/test/validatable_test.rb +126 -117
- 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: 604218739c9eacb3fe347bb5ce9aaec11b9043c1
|
4
|
+
data.tar.gz: 8dfd6a12f48cdaec2dc78a6b2388e4153ea94a60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbb02a81c4a2fbc22d62d859208030166cebb5d5fcc558b2b8026cd003fef3294e1aae837bf4ad8a0f8a5730499720d09d03323bd58685bf309a24f9fa729ba5
|
7
|
+
data.tar.gz: 708ade0f9f4f66c75bb3834767a9cae0840d8906831a56cb22a4d6755f218f643079b2f7779c851ae2d3ca92c49cb78fb8670c511696b02ca0a8e6f022d1b585
|
data/lib/hiccup/validatable.rb
CHANGED
data/lib/hiccup/version.rb
CHANGED
data/test/validatable_test.rb
CHANGED
@@ -1,118 +1,127 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
|
4
|
-
class ValidatableTest < ActiveSupport::TestCase
|
5
|
-
include Hiccup
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def test_invalid_recurrence
|
10
|
-
# Test nil weekly recurrence
|
11
|
-
r = Schedule.new(:kind => :weekly)
|
12
|
-
assert !r.valid?, "Recurrence should be invalid: weekly_pattern is empty"
|
13
|
-
assert r.errors[:weekly_pattern].any?, "weekly_pattern should be invalid if empty and kind is 'weekly'"
|
14
|
-
|
15
|
-
# Test nil monthly recurrence
|
16
|
-
r = Schedule.new(:kind => :monthly)
|
17
|
-
assert !r.valid?, "Recurrence should be invalid: monthly_pattern is empty"
|
18
|
-
assert r.errors[:monthly_pattern].any?, "monthly_pattern should be invalid if empty and kind is 'monthly'"
|
19
|
-
|
20
|
-
# Test invalid monthly recurrence
|
21
|
-
r = Schedule.new(:kind => :monthly, :monthly_pattern => [[2, "holiday"]])
|
22
|
-
assert !r.valid?, "Recurrence should be invalid: monthly_pattern is invalid"
|
23
|
-
assert r.errors[:monthly_pattern].any?, "monthly_pattern should be invalid: 'holiday' is not a valid MonthlyOccurrenceType"
|
24
|
-
end
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
def test_temporal_paradoxes
|
29
|
-
recurrence = Schedule.new({
|
30
|
-
:kind => :annually,
|
31
|
-
:ends => true,
|
32
|
-
:start_date => Date.today,
|
33
|
-
:end_date => 5.years.since(Date.today).to_date
|
34
|
-
})
|
35
|
-
assert_valid(recurrence)
|
36
|
-
recurrence = Schedule.new({
|
37
|
-
:kind => :annually,
|
38
|
-
:ends => true,
|
39
|
-
:start_date => Date.today,
|
40
|
-
:end_date => -5.years.since(Date.today).to_date
|
41
|
-
})
|
42
|
-
assert !recurrence.valid?, "Recurrence should be invalid: its recurrence ends before it starts"
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
def test_valid_weekly_recurrence
|
48
|
-
recurrence = Schedule.new(:kind => :weekly, :weekly_pattern => %w{Tuesday})
|
49
|
-
assert_valid(recurrence)
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
schedule.
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
schedule.
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
schedule
|
99
|
-
schedule.
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
|
4
|
+
class ValidatableTest < ActiveSupport::TestCase
|
5
|
+
include Hiccup
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
def test_invalid_recurrence
|
10
|
+
# Test nil weekly recurrence
|
11
|
+
r = Schedule.new(:kind => :weekly)
|
12
|
+
assert !r.valid?, "Recurrence should be invalid: weekly_pattern is empty"
|
13
|
+
assert r.errors[:weekly_pattern].any?, "weekly_pattern should be invalid if empty and kind is 'weekly'"
|
14
|
+
|
15
|
+
# Test nil monthly recurrence
|
16
|
+
r = Schedule.new(:kind => :monthly)
|
17
|
+
assert !r.valid?, "Recurrence should be invalid: monthly_pattern is empty"
|
18
|
+
assert r.errors[:monthly_pattern].any?, "monthly_pattern should be invalid if empty and kind is 'monthly'"
|
19
|
+
|
20
|
+
# Test invalid monthly recurrence
|
21
|
+
r = Schedule.new(:kind => :monthly, :monthly_pattern => [[2, "holiday"]])
|
22
|
+
assert !r.valid?, "Recurrence should be invalid: monthly_pattern is invalid"
|
23
|
+
assert r.errors[:monthly_pattern].any?, "monthly_pattern should be invalid: 'holiday' is not a valid MonthlyOccurrenceType"
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
def test_temporal_paradoxes
|
29
|
+
recurrence = Schedule.new({
|
30
|
+
:kind => :annually,
|
31
|
+
:ends => true,
|
32
|
+
:start_date => Date.today,
|
33
|
+
:end_date => 5.years.since(Date.today).to_date
|
34
|
+
})
|
35
|
+
assert_valid(recurrence)
|
36
|
+
recurrence = Schedule.new({
|
37
|
+
:kind => :annually,
|
38
|
+
:ends => true,
|
39
|
+
:start_date => Date.today,
|
40
|
+
:end_date => -5.years.since(Date.today).to_date
|
41
|
+
})
|
42
|
+
assert !recurrence.valid?, "Recurrence should be invalid: its recurrence ends before it starts"
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
def test_valid_weekly_recurrence
|
48
|
+
recurrence = Schedule.new(:kind => :weekly, :weekly_pattern => %w{Tuesday})
|
49
|
+
assert_valid(recurrence)
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
context "monthly_pattern" do
|
55
|
+
should "be valid when it's an array of week index, day name" do
|
56
|
+
recurrence = Schedule.new(:kind => :monthly, :monthly_pattern => [[2, "Thursday"]])
|
57
|
+
assert_valid(recurrence)
|
58
|
+
end
|
59
|
+
|
60
|
+
should "be valid when it's a positive integer between 1-31" do
|
61
|
+
recurrence = Schedule.new(:kind => :monthly, :monthly_pattern => [2])
|
62
|
+
assert_valid(recurrence)
|
63
|
+
end
|
64
|
+
|
65
|
+
should "be valid when it's a -1 (last day of the month)" do
|
66
|
+
recurrence = Schedule.new(:kind => :monthly, :monthly_pattern => [-1])
|
67
|
+
assert_valid(recurrence)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
def test_valid_annual_recurrence
|
74
|
+
recurrence = Schedule.new(:kind => :annually)
|
75
|
+
assert_valid(recurrence)
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
context "skip" do
|
81
|
+
should "be positive" do
|
82
|
+
schedule = Schedule.new
|
83
|
+
schedule.skip = -5
|
84
|
+
schedule.valid?
|
85
|
+
assert schedule.errors[:skip].any?, "Expected skip to be invalid"
|
86
|
+
end
|
87
|
+
|
88
|
+
should "be present" do
|
89
|
+
schedule = Schedule.new
|
90
|
+
schedule.skip = nil
|
91
|
+
schedule.valid?
|
92
|
+
assert schedule.errors[:skip].any?, "Expected skip to be invalid"
|
93
|
+
end
|
94
|
+
|
95
|
+
should "be nonzero" do
|
96
|
+
schedule = Schedule.new
|
97
|
+
schedule.skip = 0
|
98
|
+
schedule.valid?
|
99
|
+
assert schedule.errors[:skip].any?, "Expected skip to be invalid"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
context "When an end_date is supplied but not a start_date, it" do
|
106
|
+
should "record an error for the start_date but not for end_date" do
|
107
|
+
schedule = Schedule.new(kind: :weekly, ends: true, end_date: Date.today)
|
108
|
+
schedule.start_date = nil
|
109
|
+
refute schedule.valid?
|
110
|
+
assert schedule.errors[:start_date].any?
|
111
|
+
refute schedule.errors[:end_date].any?
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
def assert_valid(record)
|
122
|
+
assert record.valid?, record.errors.inspect
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
|
118
127
|
end
|