hiccup 0.5.16 → 0.5.17

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
  SHA1:
3
- metadata.gz: 5360432a77538aebc70858cfabaa86053f0de7d2
4
- data.tar.gz: f6b1a1605bcb80ab578dda9b44c2dc6d50199c23
3
+ metadata.gz: 604218739c9eacb3fe347bb5ce9aaec11b9043c1
4
+ data.tar.gz: 8dfd6a12f48cdaec2dc78a6b2388e4153ea94a60
5
5
  SHA512:
6
- metadata.gz: 0d1ed6207b1477718f353df54ff3b5bd430d0f4ff223fcf312a7419165decee220cf0b8981ad54c2d768b4528d2a8f101e4104206f2e499fa557e7a05e658829
7
- data.tar.gz: 5b9dd9c74e8b5baf294e5a108a82933bdf179740cb1083d56d7339fc33576ed5defc074af775eb94a999a1ba1d284cff944c0470f949d579b7c555289367d59e
6
+ metadata.gz: dbb02a81c4a2fbc22d62d859208030166cebb5d5fcc558b2b8026cd003fef3294e1aae837bf4ad8a0f8a5730499720d09d03323bd58685bf309a24f9fa729ba5
7
+ data.tar.gz: 708ade0f9f4f66c75bb3834767a9cae0840d8906831a56cb22a4d6755f218f643079b2f7779c851ae2d3ca92c49cb78fb8670c511696b02ca0a8e6f022d1b585
@@ -71,7 +71,7 @@ module Hiccup
71
71
  Date::DAYNAMES.member?(wd) && i.is_a?(Fixnum) && ((i == -1) || (1..6).include?(i))
72
72
  else
73
73
  i = occurrence
74
- i.is_a?(Fixnum) && (1..31).include?(i)
74
+ i.is_a?(Fixnum) && ([-1] + (1..31).to_a).include?(i)
75
75
  end
76
76
  end
77
77
 
@@ -1,3 +1,3 @@
1
1
  module Hiccup
2
- VERSION = "0.5.16"
2
+ VERSION = "0.5.17"
3
3
  end
@@ -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
- def test_valid_monthly_recurrence
55
- recurrence = Schedule.new(:kind => :monthly, :monthly_pattern => [2])
56
- assert_valid(recurrence)
57
-
58
- recurrence = Schedule.new(:kind => :monthly, :monthly_pattern => [[2, "Thursday"]])
59
- assert_valid(recurrence)
60
- end
61
-
62
-
63
-
64
- def test_valid_annual_recurrence
65
- recurrence = Schedule.new(:kind => :annually)
66
- assert_valid(recurrence)
67
- end
68
-
69
-
70
-
71
- context "skip" do
72
- should "be positive" do
73
- schedule = Schedule.new
74
- schedule.skip = -5
75
- schedule.valid?
76
- assert schedule.errors[:skip].any?, "Expected skip to be invalid"
77
- end
78
-
79
- should "be present" do
80
- schedule = Schedule.new
81
- schedule.skip = nil
82
- schedule.valid?
83
- assert schedule.errors[:skip].any?, "Expected skip to be invalid"
84
- end
85
-
86
- should "be nonzero" do
87
- schedule = Schedule.new
88
- schedule.skip = 0
89
- schedule.valid?
90
- assert schedule.errors[:skip].any?, "Expected skip to be invalid"
91
- end
92
- end
93
-
94
-
95
-
96
- context "When an end_date is supplied but not a start_date, it" do
97
- should "record an error for the start_date but not for end_date" do
98
- schedule = Schedule.new(kind: :weekly, ends: true, end_date: Date.today)
99
- schedule.start_date = nil
100
- refute schedule.valid?
101
- assert schedule.errors[:start_date].any?
102
- refute schedule.errors[:end_date].any?
103
- end
104
- end
105
-
106
-
107
-
108
- private
109
-
110
-
111
-
112
- def assert_valid(record)
113
- assert record.valid?, record.errors.inspect
114
- end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiccup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.16
4
+ version: 0.5.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bob Lail