hiccup 0.2.0 → 0.2.1
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.
- data/.gitignore +1 -0
- data/.simplecov +2 -0
- data/hiccup.gemspec +1 -0
- data/lib/hiccup.rb +9 -3
- data/lib/hiccup/core_ext/duration.rb +1 -1
- data/lib/hiccup/enumerable.rb +4 -4
- data/lib/hiccup/humanizable.rb +6 -6
- data/lib/hiccup/schedule.rb +10 -8
- data/lib/hiccup/serializers/ical.rb +5 -5
- data/lib/hiccup/validatable.rb +13 -16
- data/lib/hiccup/version.rb +1 -1
- data/test/duration_ext_test.rb +28 -0
- data/test/enumerable_test.rb +10 -10
- data/test/humanizable_test.rb +12 -12
- data/test/ical_serializable_test.rb +5 -5
- data/test/test_helper.rb +1 -0
- data/test/validatable_test.rb +10 -10
- metadata +16 -2
data/.gitignore
CHANGED
data/.simplecov
ADDED
data/hiccup.gemspec
CHANGED
|
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
|
|
|
18
18
|
s.add_development_dependency "ri_cal"
|
|
19
19
|
s.add_development_dependency "rails"
|
|
20
20
|
s.add_development_dependency "turn"
|
|
21
|
+
s.add_development_dependency "simplecov"
|
|
21
22
|
|
|
22
23
|
s.files = `git ls-files`.split("\n")
|
|
23
24
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/lib/hiccup.rb
CHANGED
|
@@ -16,23 +16,29 @@ require "hiccup/version"
|
|
|
16
16
|
# ever ends
|
|
17
17
|
# * end_date - The date when the recurrence pattern ends
|
|
18
18
|
# * skip - The number of instances to skip # <== change this to :interval
|
|
19
|
-
# *
|
|
19
|
+
# * weekly_pattern - An array of recurrence rules for a
|
|
20
|
+
# weekly recurrence
|
|
21
|
+
# * monthly_pattern - An array of recurrence rules for a
|
|
22
|
+
# monthly recurrence
|
|
20
23
|
#
|
|
21
24
|
# Examples:
|
|
22
25
|
#
|
|
23
26
|
# Every other Monday
|
|
24
|
-
# :kind => :weekly, :
|
|
27
|
+
# :kind => :weekly, :weekly_pattern => ["Monday"]
|
|
25
28
|
#
|
|
26
29
|
# Every year on June 21 (starting in 1999)
|
|
27
30
|
# :kind => :yearly, :start_date => Date.new(1999, 6, 21)
|
|
28
31
|
#
|
|
29
32
|
# The second and fourth Sundays of the month
|
|
30
|
-
# :kind => :monthly, :
|
|
33
|
+
# :kind => :monthly, :monthly_pattern => [[2, "Sunday"], [4, "Sunday"]]
|
|
31
34
|
#
|
|
32
35
|
#
|
|
33
36
|
module Hiccup
|
|
34
37
|
|
|
35
38
|
|
|
39
|
+
Kinds = [:never, :weekly, :monthly, :annually]
|
|
40
|
+
|
|
41
|
+
|
|
36
42
|
def hiccup(*modules)
|
|
37
43
|
options = modules.extract_options!
|
|
38
44
|
add_hiccup_modules(modules)
|
data/lib/hiccup/enumerable.rb
CHANGED
|
@@ -44,7 +44,7 @@ module Hiccup
|
|
|
44
44
|
|
|
45
45
|
when :weekly
|
|
46
46
|
wday = date.wday
|
|
47
|
-
|
|
47
|
+
weekly_pattern.each do |weekday|
|
|
48
48
|
wd = Date::DAYNAMES.index(weekday)
|
|
49
49
|
wd = wd + 7 if wd < wday
|
|
50
50
|
days_in_the_future = wd - wday
|
|
@@ -57,7 +57,7 @@ module Hiccup
|
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
when :monthly
|
|
60
|
-
|
|
60
|
+
monthly_pattern.each do |occurrence|
|
|
61
61
|
temp = nil
|
|
62
62
|
(0...30).each do |i| # If an occurrence doesn't occur this month, try up to 30 months in the future
|
|
63
63
|
temp = monthly_occurrence_to_date(occurrence, i.months.after(date))
|
|
@@ -113,7 +113,7 @@ module Hiccup
|
|
|
113
113
|
|
|
114
114
|
when :weekly
|
|
115
115
|
wday = date.wday
|
|
116
|
-
|
|
116
|
+
weekly_pattern.each do |weekday|
|
|
117
117
|
wd = Date::DAYNAMES.index(weekday)
|
|
118
118
|
wd = wd - 7 if wd > wday
|
|
119
119
|
days_in_the_past = wday - wd
|
|
@@ -126,7 +126,7 @@ module Hiccup
|
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
when :monthly
|
|
129
|
-
|
|
129
|
+
monthly_pattern.each do |occurrence|
|
|
130
130
|
temp = nil
|
|
131
131
|
(0...30).each do |i| # If an occurrence doesn't occur this month, try up to 30 months in the past
|
|
132
132
|
temp = monthly_occurrence_to_date(occurrence, i.months.before(date))
|
data/lib/hiccup/humanizable.rb
CHANGED
|
@@ -25,21 +25,21 @@ module Hiccup
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
def weekly_humanize
|
|
28
|
-
|
|
29
|
-
if skip == 1 ||
|
|
30
|
-
sentence("Every", ordinal,
|
|
28
|
+
weekdays_sentece = weekly_pattern.map(&:humanize).to_sentence
|
|
29
|
+
if skip == 1 || weekly_pattern.length == 1
|
|
30
|
+
sentence("Every", ordinal, weekdays_sentece)
|
|
31
31
|
else
|
|
32
|
-
sentence(
|
|
32
|
+
sentence(weekdays_sentece, "of every", ordinal, "week")
|
|
33
33
|
end
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def monthly_humanize
|
|
37
|
-
monthly_occurrences =
|
|
37
|
+
monthly_occurrences = monthly_pattern.map(&method(:monthly_occurrence_to_s)).to_sentence
|
|
38
38
|
sentence("The", monthly_occurrences, "of every", ordinal, "month")
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def yearly_humanize
|
|
42
|
-
sentence("Every", ordinal, "year on", self.start_date.strftime('%
|
|
42
|
+
sentence("Every", ordinal, "year on", self.start_date.strftime('%B %d'))
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
|
data/lib/hiccup/schedule.rb
CHANGED
|
@@ -15,16 +15,17 @@ module Hiccup
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
def initialize(options={})
|
|
18
|
-
@kind
|
|
19
|
-
@start_date
|
|
20
|
-
@ends
|
|
21
|
-
@end_date
|
|
22
|
-
@skip
|
|
23
|
-
@
|
|
18
|
+
@kind =(options[:kind] || :never).to_sym
|
|
19
|
+
@start_date =(options[:start_date] || Date.today).to_date
|
|
20
|
+
@ends = options.key?(:ends) ? options[:ends] : false
|
|
21
|
+
@end_date = options[:end_date] ? options[:end_date].to_date : nil
|
|
22
|
+
@skip =(options[:skip] || options[:interval] || 1).to_i
|
|
23
|
+
@weekly_pattern = options[:weekly_pattern] || []
|
|
24
|
+
@monthly_pattern = options[:monthly_pattern] || []
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
|
|
27
|
-
attr_accessor :kind, :start_date, :ends, :end_date, :skip, :
|
|
28
|
+
attr_accessor :kind, :start_date, :ends, :end_date, :skip, :weekly_pattern, :monthly_pattern
|
|
28
29
|
|
|
29
30
|
|
|
30
31
|
def to_hash
|
|
@@ -33,7 +34,8 @@ module Hiccup
|
|
|
33
34
|
:start_date => start_date,
|
|
34
35
|
:ends => ends,
|
|
35
36
|
:end_date => end_date,
|
|
36
|
-
:
|
|
37
|
+
:weekly_pattern => weekly_pattern,
|
|
38
|
+
:monthly_pattern => monthly_pattern
|
|
37
39
|
}
|
|
38
40
|
end
|
|
39
41
|
|
|
@@ -56,7 +56,7 @@ module Hiccup
|
|
|
56
56
|
|
|
57
57
|
|
|
58
58
|
def add_weekly_rule
|
|
59
|
-
add_rule("WEEKLY", :byday => abbreviate_weekdays(@obj.
|
|
59
|
+
add_rule("WEEKLY", :byday => abbreviate_weekdays(@obj.weekly_pattern))
|
|
60
60
|
end
|
|
61
61
|
|
|
62
62
|
|
|
@@ -64,7 +64,7 @@ module Hiccup
|
|
|
64
64
|
def add_monthly_rule
|
|
65
65
|
byday = []
|
|
66
66
|
bymonthday = []
|
|
67
|
-
@obj.
|
|
67
|
+
@obj.monthly_pattern.each do |occurrence|
|
|
68
68
|
if occurrence.is_a?(Array)
|
|
69
69
|
i, weekday = occurrence
|
|
70
70
|
byday << "#{i}#{abbreviate_weekday(weekday)}"
|
|
@@ -107,7 +107,7 @@ module Hiccup
|
|
|
107
107
|
|
|
108
108
|
def parse_weekly_rule(rule)
|
|
109
109
|
@obj.kind = :weekly
|
|
110
|
-
@obj.
|
|
110
|
+
@obj.weekly_pattern = backmap_weekdays(rule.by_list[:byday])
|
|
111
111
|
parse_rule(rule)
|
|
112
112
|
end
|
|
113
113
|
|
|
@@ -122,13 +122,13 @@ module Hiccup
|
|
|
122
122
|
|
|
123
123
|
def parse_monthly_bymonthyday(bymonthday)
|
|
124
124
|
(bymonthday || []).each do |bymonthday|
|
|
125
|
-
@obj.
|
|
125
|
+
@obj.monthly_pattern = @obj.monthly_pattern + [bymonthday.ordinal]
|
|
126
126
|
end
|
|
127
127
|
end
|
|
128
128
|
|
|
129
129
|
def parse_monthly_byday(byday)
|
|
130
130
|
(byday || []).each do |byday|
|
|
131
|
-
@obj.
|
|
131
|
+
@obj.monthly_pattern = @obj.monthly_pattern + [[byday.index, backmap_weekday(byday)]]
|
|
132
132
|
end
|
|
133
133
|
end
|
|
134
134
|
|
data/lib/hiccup/validatable.rb
CHANGED
|
@@ -8,9 +8,6 @@ module Hiccup
|
|
|
8
8
|
extend ActiveSupport::Concern
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
Kinds = [:never, :weekly, :monthly, :annually]
|
|
12
|
-
|
|
13
|
-
|
|
14
11
|
# !todo: use ActiveModel:Validation rather than a custom method
|
|
15
12
|
included do
|
|
16
13
|
validate :validate_recurrence
|
|
@@ -43,23 +40,23 @@ module Hiccup
|
|
|
43
40
|
|
|
44
41
|
|
|
45
42
|
def validate_weekly_recurrence
|
|
46
|
-
if !
|
|
47
|
-
errors.add(:
|
|
48
|
-
elsif
|
|
49
|
-
errors.add(:
|
|
50
|
-
elsif (invalid_names =
|
|
51
|
-
errors.add(:
|
|
43
|
+
if !weekly_pattern.is_a?(Array)
|
|
44
|
+
errors.add(:weekly_pattern, "is a #{weekly_pattern.class}. It should be an array")
|
|
45
|
+
elsif weekly_pattern.empty?
|
|
46
|
+
errors.add(:weekly_pattern, "is empty. It should contain a list of weekdays")
|
|
47
|
+
elsif (invalid_names = weekly_pattern - Date::DAYNAMES).any?
|
|
48
|
+
errors.add(:weekly_pattern, "should contain only weekdays. (#{invalid_names.to_sentence} are invalid)")
|
|
52
49
|
end
|
|
53
50
|
end
|
|
54
51
|
|
|
55
52
|
|
|
56
53
|
def validate_monthly_recurrence
|
|
57
|
-
if !
|
|
58
|
-
errors.add(:
|
|
59
|
-
elsif
|
|
60
|
-
errors.add(:
|
|
61
|
-
elsif
|
|
62
|
-
errors.add(:
|
|
54
|
+
if !monthly_pattern.is_a?(Array)
|
|
55
|
+
errors.add(:monthly_pattern, "is a #{monthly_pattern.class}. It should be an array")
|
|
56
|
+
elsif monthly_pattern.empty?
|
|
57
|
+
errors.add(:monthly_pattern, "is empty. It should contain a list of monthly occurrences")
|
|
58
|
+
elsif monthly_pattern.select(&method(:invalid_occurrence?)).any?
|
|
59
|
+
errors.add(:monthly_pattern, "contains invalid monthly occurrences")
|
|
63
60
|
end
|
|
64
61
|
end
|
|
65
62
|
|
|
@@ -80,7 +77,7 @@ module Hiccup
|
|
|
80
77
|
|
|
81
78
|
|
|
82
79
|
def invalid_kind!
|
|
83
|
-
errors.add(:kind, "is not recognized. It must be one of #{Kinds.collect{|kind| "
|
|
80
|
+
errors.add(:kind, "#{kind.inspect} is not recognized. It must be one of #{Kinds.collect{|kind| ":#{kind}"}.to_sentence(:two_words_connector => " or ", :last_word_connector => ", or ")}.")
|
|
84
81
|
end
|
|
85
82
|
|
|
86
83
|
|
data/lib/hiccup/version.rb
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require "test_helper"
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class DurationExtTest < ActiveSupport::TestCase
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_active_support_duration_is_working
|
|
8
|
+
assert 1.day.is_a?(ActiveSupport::Duration), "I ran into a problem where the Ruby gem 'god' also added :day to Fixnum and broke ActiveSupport."
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def test_after_alias
|
|
13
|
+
t = 17.weeks.ago
|
|
14
|
+
[:day, :week, :month, :year].each do |period|
|
|
15
|
+
assert_equal 1.send(period).since(t), 1.send(period).after(t)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_before_alias
|
|
21
|
+
t = 17.weeks.ago
|
|
22
|
+
[:day, :week, :month, :year].each do |period|
|
|
23
|
+
assert_equal 1.send(period).ago(t), 1.send(period).before(t)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
end
|
data/test/enumerable_test.rb
CHANGED
|
@@ -21,7 +21,7 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
|
21
21
|
def test_occurs_on_weekly
|
|
22
22
|
schedule = Schedule.new({
|
|
23
23
|
:kind => :weekly,
|
|
24
|
-
:
|
|
24
|
+
:weekly_pattern => %w{Monday Wednesday Friday},
|
|
25
25
|
:start_date => Date.new(2009,3,15)})
|
|
26
26
|
assert schedule.occurs_on(Date.new(2009,5,1)), "MWF schedule starting 3/15/09 should occur on 5/1/2009"
|
|
27
27
|
assert schedule.occurs_on(Date.new(2009,5,11)), "MWF schedule starting 3/15/09 should occur on 5/11/2009"
|
|
@@ -44,7 +44,7 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
|
44
44
|
def test_weekly_occurrences_during_month
|
|
45
45
|
schedule = Schedule.new({
|
|
46
46
|
:kind => :weekly,
|
|
47
|
-
:
|
|
47
|
+
:weekly_pattern => %w{Monday Wednesday Friday},
|
|
48
48
|
:start_date => Date.new(2009,3,15),
|
|
49
49
|
:ends => true,
|
|
50
50
|
:end_date => Date.new(2009,11,30)})
|
|
@@ -58,7 +58,7 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
|
58
58
|
|
|
59
59
|
schedule = Schedule.new({
|
|
60
60
|
:kind => :weekly,
|
|
61
|
-
:
|
|
61
|
+
:weekly_pattern => %w{Monday},
|
|
62
62
|
:start_date => Date.new(2010,6,14),
|
|
63
63
|
:ends => true,
|
|
64
64
|
:end_date => Date.new(2010,6,21)})
|
|
@@ -72,7 +72,7 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
|
72
72
|
def test_monthly_occurrences_during_month
|
|
73
73
|
schedule = Schedule.new({
|
|
74
74
|
:kind => :monthly,
|
|
75
|
-
:
|
|
75
|
+
:monthly_pattern => [[2, "Sunday"], [4, "Sunday"]],
|
|
76
76
|
:start_date => Date.new(2004,3,15)})
|
|
77
77
|
dates = schedule.occurrences_during_month(2009,12).map {|date| date.day}
|
|
78
78
|
expected_dates = [13,27]
|
|
@@ -113,7 +113,7 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
|
113
113
|
occurrence = [1, "Wednesday"]
|
|
114
114
|
schedule = Schedule.new({
|
|
115
115
|
:kind => :monthly,
|
|
116
|
-
:
|
|
116
|
+
:monthly_pattern => [occurrence],
|
|
117
117
|
:start_date => Date.new(2011,1,1)})
|
|
118
118
|
expected_dates = [[1,5], [2,2], [3,2], [4,6], [5,4], [6,1], [7,6], [8,3], [9,7], [10,5], [11,2], [12,7]]
|
|
119
119
|
expected_dates.map! {|pair| Date.new(2011, *pair)}
|
|
@@ -130,7 +130,7 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
|
130
130
|
def test_weekly_recurrence_and_skip
|
|
131
131
|
schedule = Schedule.new({
|
|
132
132
|
:kind => :weekly,
|
|
133
|
-
:
|
|
133
|
+
:weekly_pattern => %w{Monday},
|
|
134
134
|
:skip => 3,
|
|
135
135
|
:start_date => Date.new(2011,1,1)})
|
|
136
136
|
expected_dates = [[1,3], [1,24], [2,14], [3,7], [3,28]]
|
|
@@ -148,7 +148,7 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
|
148
148
|
def test_monthly_recurrence_and_skip
|
|
149
149
|
schedule = Schedule.new({
|
|
150
150
|
:kind => :monthly,
|
|
151
|
-
:
|
|
151
|
+
:monthly_pattern => [[1, "Wednesday"]],
|
|
152
152
|
:skip => 2,
|
|
153
153
|
:start_date => Date.new(2011,1,1)})
|
|
154
154
|
expected_dates = [[1,5], [3,2], [5,4], [7,6], [9,7], [11,2]]
|
|
@@ -192,7 +192,7 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
|
192
192
|
start = Date.new(2010,6,1)
|
|
193
193
|
schedule = Schedule.new({
|
|
194
194
|
:kind => :monthly,
|
|
195
|
-
:
|
|
195
|
+
:monthly_pattern => [[5, "Monday"]],
|
|
196
196
|
:start_date => start})
|
|
197
197
|
assert_equal "The fifth Monday of every month", schedule.humanize
|
|
198
198
|
|
|
@@ -211,7 +211,7 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
|
211
211
|
fifth_sunday = Date.new(2010, 8, 29)
|
|
212
212
|
schedule = Schedule.new({
|
|
213
213
|
:kind => :monthly,
|
|
214
|
-
:
|
|
214
|
+
:monthly_pattern => [[5, "Sunday"]],
|
|
215
215
|
:start_date => fifth_sunday})
|
|
216
216
|
assert_equal "The fifth Sunday of every month", schedule.humanize
|
|
217
217
|
|
|
@@ -235,7 +235,7 @@ class EnumerableTest < ActiveSupport::TestCase
|
|
|
235
235
|
def test_recurs_on31st
|
|
236
236
|
schedule = Schedule.new({
|
|
237
237
|
:kind => :monthly,
|
|
238
|
-
:
|
|
238
|
+
:monthly_pattern => [31],
|
|
239
239
|
:start_date => Date.new(2008, 2, 29)
|
|
240
240
|
});
|
|
241
241
|
|
data/test/humanizable_test.rb
CHANGED
|
@@ -19,50 +19,50 @@ class HumanizableTest < ActiveSupport::TestCase
|
|
|
19
19
|
|
|
20
20
|
test_humanize(
|
|
21
21
|
"Every Sunday",
|
|
22
|
-
{:kind => :weekly, :
|
|
22
|
+
{:kind => :weekly, :weekly_pattern => %w[Sunday]})
|
|
23
23
|
|
|
24
24
|
test_humanize(
|
|
25
25
|
"Every other Sunday",
|
|
26
|
-
{:kind => :weekly, :
|
|
26
|
+
{:kind => :weekly, :weekly_pattern => %w[Sunday], :skip => 2})
|
|
27
27
|
|
|
28
28
|
test_humanize(
|
|
29
29
|
"Every Sunday and Monday",
|
|
30
|
-
{:kind => :weekly, :
|
|
30
|
+
{:kind => :weekly, :weekly_pattern => %w[Sunday Monday]})
|
|
31
31
|
|
|
32
32
|
test_humanize(
|
|
33
33
|
"Monday, Wednesday, and Friday of every third week",
|
|
34
|
-
{:kind => :weekly, :
|
|
34
|
+
{:kind => :weekly, :weekly_pattern => %w[Monday Wednesday Friday], :skip => 3})
|
|
35
35
|
|
|
36
36
|
test_humanize(
|
|
37
37
|
"The 4th of every month",
|
|
38
|
-
{:kind => :monthly, :
|
|
38
|
+
{:kind => :monthly, :monthly_pattern => [4]})
|
|
39
39
|
|
|
40
40
|
test_humanize(
|
|
41
41
|
"The 4th and 5th of every month",
|
|
42
|
-
{:kind => :monthly, :
|
|
42
|
+
{:kind => :monthly, :monthly_pattern => [4,5]})
|
|
43
43
|
|
|
44
44
|
test_humanize(
|
|
45
45
|
"The first Monday of every month",
|
|
46
|
-
{:kind => :monthly, :
|
|
46
|
+
{:kind => :monthly, :monthly_pattern => [[1, "Monday"]]})
|
|
47
47
|
|
|
48
48
|
test_humanize(
|
|
49
49
|
"The last Tuesday of every month",
|
|
50
|
-
{:kind => :monthly, :
|
|
50
|
+
{:kind => :monthly, :monthly_pattern => [[-1, "Tuesday"]]})
|
|
51
51
|
|
|
52
52
|
test_humanize(
|
|
53
53
|
"The first Monday and third Monday of every other month",
|
|
54
|
-
{:kind => :monthly, :
|
|
54
|
+
{:kind => :monthly, :monthly_pattern => [[1, "Monday"], [3, "Monday"]], :skip => 2})
|
|
55
55
|
|
|
56
56
|
test_humanize(
|
|
57
|
-
"Every year on #{Date.today.strftime('%
|
|
57
|
+
"Every year on #{Date.today.strftime('%B %d')}",
|
|
58
58
|
{:kind => :annually})
|
|
59
59
|
|
|
60
60
|
test_humanize(
|
|
61
|
-
"Every other year on #{Date.today.strftime('%
|
|
61
|
+
"Every other year on #{Date.today.strftime('%B %d')}",
|
|
62
62
|
{:kind => :annually, :skip => 2})
|
|
63
63
|
|
|
64
64
|
test_humanize(
|
|
65
|
-
"Every fourth year on #{Date.today.strftime('%
|
|
65
|
+
"Every fourth year on #{Date.today.strftime('%B %d')}",
|
|
66
66
|
{:kind => :annually, :skip => 4})
|
|
67
67
|
|
|
68
68
|
|
|
@@ -21,7 +21,7 @@ class IcalSerializableTest < ActiveSupport::TestCase
|
|
|
21
21
|
"Simple weekly recurrence",
|
|
22
22
|
"DTSTART;VALUE=DATE-TIME:20090101T000000Z\nRRULE:FREQ=WEEKLY;BYDAY=SU\n",
|
|
23
23
|
{ :kind => :weekly,
|
|
24
|
-
:
|
|
24
|
+
:weekly_pattern => %w{Sunday},
|
|
25
25
|
:start_date => DateTime.new(2009, 1, 1)
|
|
26
26
|
})
|
|
27
27
|
|
|
@@ -30,7 +30,7 @@ class IcalSerializableTest < ActiveSupport::TestCase
|
|
|
30
30
|
"Complex weekly recurrence (with an interval)",
|
|
31
31
|
"DTSTART;VALUE=DATE-TIME:20090101T000000Z\nRRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,TH\n",
|
|
32
32
|
{ :kind => :weekly,
|
|
33
|
-
:
|
|
33
|
+
:weekly_pattern => %w{Tuesday Thursday},
|
|
34
34
|
:start_date => DateTime.new(2009, 1, 1),
|
|
35
35
|
:skip => 2
|
|
36
36
|
})
|
|
@@ -57,7 +57,7 @@ class IcalSerializableTest < ActiveSupport::TestCase
|
|
|
57
57
|
"Simple monthly recurrence",
|
|
58
58
|
"DTSTART;VALUE=DATE-TIME:20090315T000000Z\nRRULE:FREQ=MONTHLY;BYMONTHDAY=4\n",
|
|
59
59
|
{ :kind => :monthly,
|
|
60
|
-
:
|
|
60
|
+
:monthly_pattern => [4],
|
|
61
61
|
:start_date => DateTime.new(2009, 3, 15)
|
|
62
62
|
})
|
|
63
63
|
|
|
@@ -66,7 +66,7 @@ class IcalSerializableTest < ActiveSupport::TestCase
|
|
|
66
66
|
"Monthly recurrence on the last Tuesday of the month",
|
|
67
67
|
"DTSTART;VALUE=DATE-TIME:20090315T000000Z\nRRULE:FREQ=MONTHLY;BYDAY=-1TU\n",
|
|
68
68
|
{ :kind => :monthly,
|
|
69
|
-
:
|
|
69
|
+
:monthly_pattern => [[-1, "Tuesday"]],
|
|
70
70
|
:start_date => DateTime.new(2009, 3, 15)
|
|
71
71
|
})
|
|
72
72
|
|
|
@@ -75,7 +75,7 @@ class IcalSerializableTest < ActiveSupport::TestCase
|
|
|
75
75
|
"Complex monthly recurrence",
|
|
76
76
|
"DTSTART;VALUE=DATE-TIME:20090315T000000Z\nRRULE:FREQ=MONTHLY;BYDAY=2SU,4SU\n",
|
|
77
77
|
{ :kind => :monthly,
|
|
78
|
-
:
|
|
78
|
+
:monthly_pattern => [[2, "Sunday"], [4, "Sunday"]],
|
|
79
79
|
:start_date => DateTime.new(2009, 3, 15)
|
|
80
80
|
})
|
|
81
81
|
|
data/test/test_helper.rb
CHANGED
data/test/validatable_test.rb
CHANGED
|
@@ -9,18 +9,18 @@ class ValidatableTest < ActiveSupport::TestCase
|
|
|
9
9
|
def test_invalid_recurrence
|
|
10
10
|
# Test nil weekly recurrence
|
|
11
11
|
r = Schedule.new(:kind => :weekly)
|
|
12
|
-
assert !r.valid?, "Recurrence should be invalid:
|
|
13
|
-
assert r.errors[:
|
|
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
14
|
|
|
15
15
|
# Test nil monthly recurrence
|
|
16
16
|
r = Schedule.new(:kind => :monthly)
|
|
17
|
-
assert !r.valid?, "Recurrence should be invalid:
|
|
18
|
-
assert r.errors[:
|
|
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
19
|
|
|
20
20
|
# Test invalid monthly recurrence
|
|
21
|
-
r = Schedule.new(:kind => :monthly, :
|
|
22
|
-
assert !r.valid?, "Recurrence should be invalid:
|
|
23
|
-
assert r.errors[:
|
|
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
24
|
end
|
|
25
25
|
|
|
26
26
|
|
|
@@ -45,17 +45,17 @@ class ValidatableTest < ActiveSupport::TestCase
|
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
def test_valid_weekly_recurrence
|
|
48
|
-
recurrence = Schedule.new(:kind => :weekly, :
|
|
48
|
+
recurrence = Schedule.new(:kind => :weekly, :weekly_pattern => %w{Tuesday})
|
|
49
49
|
assert_valid(recurrence)
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
def test_valid_monthly_recurrence
|
|
55
|
-
recurrence = Schedule.new(:kind => :monthly, :
|
|
55
|
+
recurrence = Schedule.new(:kind => :monthly, :monthly_pattern => [2])
|
|
56
56
|
assert_valid(recurrence)
|
|
57
57
|
|
|
58
|
-
recurrence = Schedule.new(:kind => :monthly, :
|
|
58
|
+
recurrence = Schedule.new(:kind => :monthly, :monthly_pattern => [[2, "Thursday"]])
|
|
59
59
|
assert_valid(recurrence)
|
|
60
60
|
end
|
|
61
61
|
|
metadata
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: hiccup
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease:
|
|
5
|
-
version: 0.2.
|
|
5
|
+
version: 0.2.1
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- Bob Lail
|
|
@@ -10,7 +10,7 @@ autorequire:
|
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
12
|
|
|
13
|
-
date: 2011-
|
|
13
|
+
date: 2011-09-18 00:00:00 -05:00
|
|
14
14
|
default_executable:
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|
|
@@ -57,6 +57,17 @@ dependencies:
|
|
|
57
57
|
version: "0"
|
|
58
58
|
type: :development
|
|
59
59
|
version_requirements: *id004
|
|
60
|
+
- !ruby/object:Gem::Dependency
|
|
61
|
+
name: simplecov
|
|
62
|
+
prerelease: false
|
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
|
64
|
+
none: false
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: "0"
|
|
69
|
+
type: :development
|
|
70
|
+
version_requirements: *id005
|
|
60
71
|
description: Recurrence features a-la-cart
|
|
61
72
|
email:
|
|
62
73
|
- bob.lailfamily@gmail.com
|
|
@@ -68,6 +79,7 @@ extra_rdoc_files: []
|
|
|
68
79
|
|
|
69
80
|
files:
|
|
70
81
|
- .gitignore
|
|
82
|
+
- .simplecov
|
|
71
83
|
- Gemfile
|
|
72
84
|
- Rakefile
|
|
73
85
|
- hiccup.gemspec
|
|
@@ -83,6 +95,7 @@ files:
|
|
|
83
95
|
- lib/hiccup/serializers/ical.rb
|
|
84
96
|
- lib/hiccup/validatable.rb
|
|
85
97
|
- lib/hiccup/version.rb
|
|
98
|
+
- test/duration_ext_test.rb
|
|
86
99
|
- test/enumerable_test.rb
|
|
87
100
|
- test/humanizable_test.rb
|
|
88
101
|
- test/ical_serializable_test.rb
|
|
@@ -117,6 +130,7 @@ signing_key:
|
|
|
117
130
|
specification_version: 3
|
|
118
131
|
summary: Recurrence features a-la-cart
|
|
119
132
|
test_files:
|
|
133
|
+
- test/duration_ext_test.rb
|
|
120
134
|
- test/enumerable_test.rb
|
|
121
135
|
- test/humanizable_test.rb
|
|
122
136
|
- test/ical_serializable_test.rb
|