1
+ # encoding: utf-8
2
+ require File . dirname ( __FILE__ ) + '/../spec_helper'
3
+
4
+ describe IceCube ::Schedule , 'to_s' do
5
+
6
+ before :each do
7
+ I18n . locale = :de
8
+ end
9
+
10
+ after :all do
11
+ I18n . locale = :en
12
+ end
13
+
14
+
15
+ it 'should represent its start time by default' do
16
+ t0 = Time . local ( 2013 , 2 , 14 )
17
+ IceCube ::Schedule . new ( t0 ) . to_s . should == '14. Februar 2013'
18
+ end
19
+
20
+ it 'should have a useful base to_s representation for a secondly rule' do
21
+ IceCube ::Rule . secondly . to_s . should == 'Jede Sekunde'
22
+ IceCube ::Rule . secondly ( 2 ) . to_s . should == 'Alle 2 Sekunden'
23
+ end
24
+
25
+ it 'should have a useful base to_s representation for a minutely rule' do
26
+ IceCube ::Rule . minutely . to_s . should == 'Jede Minute'
27
+ IceCube ::Rule . minutely ( 2 ) . to_s . should == 'Alle 2 Minuten'
28
+ end
29
+
30
+ it 'should have a useful base to_s representation for a hourly rule' do
31
+ IceCube ::Rule . hourly . to_s . should == 'Stündlich'
32
+ IceCube ::Rule . hourly ( 2 ) . to_s . should == 'Alle 2 Stunden'
33
+ end
34
+
35
+ it 'should have a useful base to_s representation for a daily rule' do
36
+ IceCube ::Rule . daily . to_s . should == 'Täglich'
37
+ IceCube ::Rule . daily ( 2 ) . to_s . should == 'Alle 2 Tage'
38
+ end
39
+
40
+ it 'should have a useful base to_s representation for a weekly rule' do
41
+ IceCube ::Rule . weekly . to_s . should == 'Wöchentlich'
42
+ IceCube ::Rule . weekly ( 2 ) . to_s . should == 'Alle 2 Wochen'
43
+ end
44
+
45
+ it 'should have a useful base to_s representation for a monthly rule' do
46
+ IceCube ::Rule . monthly . to_s . should == 'Monatlich'
47
+ IceCube ::Rule . monthly ( 2 ) . to_s . should == 'Alle 2 Monate'
48
+ end
49
+
50
+ it 'should have a useful base to_s representation for a yearly rule' do
51
+ IceCube ::Rule . yearly . to_s . should == 'Jährlich'
52
+ IceCube ::Rule . yearly ( 2 ) . to_s . should == 'Alle 2 Jahre'
53
+ end
54
+
55
+ it 'should work with various sentence types properly' do
56
+ IceCube ::Rule . weekly . to_s . should == 'Wöchentlich'
57
+ IceCube ::Rule . weekly . day ( :monday ) . to_s . should == 'Wöchentlich Montags'
58
+ IceCube ::Rule . weekly . day ( :monday , :tuesday ) . to_s . should == 'Wöchentlich Montags und Dienstags'
59
+ IceCube ::Rule . weekly . day ( :monday , :tuesday , :wednesday ) . to_s . should == 'Wöchentlich Montags, Dienstags und Mittwochs'
60
+ end
61
+
62
+ it 'should show saturday and sunday as weekends' do
63
+ IceCube ::Rule . weekly . day ( :saturday , :sunday ) . to_s . should == 'Wöchentlich am Wochenende'
64
+ end
65
+
66
+ it 'should not show saturday and sunday as weekends when other days are present also' do
67
+ IceCube ::Rule . weekly . day ( :sunday , :monday , :saturday ) . to_s . should ==
68
+ 'Wöchentlich Sonntags, Montags und Samstags'
69
+ end
70
+
71
+ it 'should reorganize days to be in order' do
72
+ IceCube ::Rule . weekly . day ( :tuesday , :monday ) . to_s . should ==
73
+ 'Wöchentlich Montags und Dienstags'
74
+ end
75
+
76
+ it 'should show weekdays as such' do
77
+ IceCube ::Rule . weekly . day (
78
+ :monday , :tuesday , :wednesday ,
79
+ :thursday , :friday
80
+ ) . to_s . should == 'Wöchentlich an Wochentagen'
81
+ end
82
+
83
+ it 'should not show weekdays as such when a weekend day is present' do
84
+ IceCube ::Rule . weekly . day (
85
+ :sunday , :monday , :tuesday , :wednesday ,
86
+ :thursday , :friday
87
+ ) . to_s . should == 'Wöchentlich Sonntags, Montags, Dienstags, Mittwochs, Donnerstags und Freitags'
88
+ # 'Weekly on Sundays, Mondays, Tuesdays, Wednesdays, Thursdays, and Fridays'
89
+ end
90
+
91
+ it 'should show start time for an empty schedule' do
92
+ schedule = IceCube ::Schedule . new Time . local ( 2010 , 3 , 20 )
93
+ schedule . to_s . should == "20. März 2010"
94
+ end
95
+
96
+ it 'should work with a single date' do
97
+ schedule = IceCube ::Schedule . new Time . local ( 2010 , 3 , 20 )
98
+ schedule . add_recurrence_time Time . local ( 2010 , 3 , 20 )
99
+ schedule . to_s . should == "20. März 2010"
100
+ end
101
+
102
+ it 'should work with additional dates' do
103
+ schedule = IceCube ::Schedule . new Time . local ( 2010 , 3 , 20 )
104
+ schedule . add_recurrence_time Time . local ( 2010 , 3 , 20 )
105
+ schedule . add_recurrence_time Time . local ( 2010 , 3 , 21 )
106
+ schedule . to_s . should == '20. März 2010 / 21. März 2010'
107
+ end
108
+
109
+ it 'should order dates that are out of order' do
110
+ schedule = IceCube ::Schedule . new Time . local ( 2010 , 3 , 20 )
111
+ schedule . add_recurrence_time Time . local ( 2010 , 3 , 19 )
112
+ schedule . to_s . should == '19. März 2010 / 20. März 2010'
113
+ end
114
+
115
+ it 'should remove duplicated start time' do
116
+ schedule = IceCube ::Schedule . new t0 = Time . local ( 2010 , 3 , 20 )
117
+ schedule . add_recurrence_time t0
118
+ schedule . to_s . should == '20. März 2010'
119
+ end
120
+
121
+ it 'should remove duplicate rtimes' do
122
+ schedule = IceCube ::Schedule . new Time . local ( 2010 , 3 , 19 )
123
+ schedule . add_recurrence_time Time . local ( 2010 , 3 , 20 )
124
+ schedule . add_recurrence_time Time . local ( 2010 , 3 , 20 )
125
+ schedule . to_s . should == '19. März 2010 / 20. März 2010'
126
+ end
127
+
128
+ it 'should work with rules and dates' do
129
+ schedule = IceCube ::Schedule . new Time . local ( 2010 , 3 , 19 )
130
+ schedule . add_recurrence_time Time . local ( 2010 , 3 , 20 )
131
+ schedule . add_recurrence_rule IceCube ::Rule . weekly
132
+ schedule . to_s . should == '20. März 2010 / Wöchentlich'
133
+ end
134
+
135
+ it 'should work with rules and times and exception times' do
136
+ schedule = IceCube ::Schedule . new Time . local ( 2010 , 3 , 20 )
137
+ schedule . add_recurrence_rule IceCube ::Rule . weekly
138
+ schedule . add_recurrence_time Time . local ( 2010 , 3 , 20 )
139
+ schedule . add_exception_time Time . local ( 2010 , 3 , 20 ) # ignored
140
+ schedule . add_exception_time Time . local ( 2010 , 3 , 21 )
141
+ schedule . to_s . should == 'Wöchentlich / außer am 20. März 2010 / außer am 21. März 2010'
142
+ end
143
+
144
+ it 'should work with a single rrule' do
145
+ schedule = IceCube ::Schedule . new Time . local ( 2010 , 3 , 20 )
146
+ schedule . add_recurrence_rule IceCube ::Rule . weekly . day_of_week ( :monday => [ 1 ] )
147
+ schedule . to_s . should == schedule . rrules [ 0 ] . to_s
148
+ end
149
+
150
+ it 'should be able to say the last Thursday of the month' do
151
+ rule_str = IceCube ::Rule . monthly . day_of_week ( :thursday => [ -1 ] ) . to_s
152
+ rule_str . should == 'Monatlich am letzten Donnerstag'
153
+ end
154
+
155
+ it 'should be able to say what months of the year something happens' do
156
+ rule_str = IceCube ::Rule . yearly . month_of_year ( :june , :july ) . to_s
157
+ rule_str . should == 'Jährlich im Juni und Juli'
158
+ end
159
+
160
+ it 'should be able to say the second to last monday of the month' do
161
+ rule_str = IceCube ::Rule . monthly . day_of_week ( :thursday => [ -2 ] ) . to_s
162
+ rule_str . should == 'Monatlich am vorletzten Donnerstag'
163
+ end
164
+
165
+ it 'should join the first and last weekdays of the month' do
166
+ rule_str = IceCube ::Rule . monthly . day_of_week ( :thursday => [ 1 , -1 ] ) . to_s
167
+ rule_str . should == 'Monatlich am 1. Donnerstag und letzten Donnerstag'
168
+ end
169
+
170
+ it 'should be able to say the days of the month something happens' do
171
+ rule_str = IceCube ::Rule . monthly . day_of_month ( 1 , 15 , 30 ) . to_s
172
+ rule_str . should == 'Monatlich am 1., 15. und 30. Tag des Monats'
173
+ end
174
+
175
+ it 'should be able to say what day of the year something happens' do
176
+ rule_str = IceCube ::Rule . yearly . day_of_year ( 30 ) . to_s
177
+ rule_str . should == 'Jährlich am 30. Tag des Jahres'
178
+ end
179
+
180
+ it 'should be able to say what hour of the day something happens' do
181
+ rule_str = IceCube ::Rule . daily . hour_of_day ( 6 , 12 ) . to_s
182
+ rule_str . should == 'Täglich in der 6. und 12. Stunde des Tages'
183
+ end
184
+
185
+ it 'should be able to say what minute of an hour something happens - with special suffix minutes' do
186
+ rule_str = IceCube ::Rule . hourly . minute_of_hour ( 10 , 11 , 12 , 13 , 14 , 15 ) . to_s
187
+ rule_str . should == 'Stündlich in der 10., 11., 12., 13., 14. und 15. Minute der Stunde'
188
+ end
189
+
190
+ it 'should be able to say what seconds of the minute something happens' do
191
+ rule_str = IceCube ::Rule . minutely . second_of_minute ( 10 , 11 ) . to_s
192
+ rule_str . should == 'Jede Minute in der 10. und 11. Sekunde der Minute'
193
+ end
194
+
195
+ it 'should be able to reflect until dates' do
196
+ schedule = IceCube ::Schedule . new ( Time . now )
197
+ schedule . rrule IceCube ::Rule . weekly . until ( Time . local ( 2012 , 2 , 3 ) )
198
+ schedule . to_s . should == 'Wöchentlich bis zum 3. Februar 2012'
199
+ end
200
+
201
+ it 'should be able to reflect count' do
202
+ schedule = IceCube ::Schedule . new ( Time . now )
203
+ schedule . add_recurrence_rule IceCube ::Rule . weekly . count ( 1 )
204
+ schedule . to_s . should == 'Wöchentlich 1 mal'
205
+ end
206
+
207
+ it 'should be able to reflect count (proper pluralization)' do
208
+ schedule = IceCube ::Schedule . new ( Time . now )
209
+ schedule . add_recurrence_rule IceCube ::Rule . weekly . count ( 2 )
210
+ schedule . to_s . should == 'Wöchentlich 2 mal'
211
+ end
212
+
213
+ end
0 commit comments