|
| 1 | +# encoding: utf-8 |
| 2 | +require File.dirname(__FILE__) + '/../spec_helper' |
| 3 | + |
| 4 | +describe IceCube::Schedule, 'to_s' do |
| 5 | + before :each do |
| 6 | + I18n.locale = :es |
| 7 | + end |
| 8 | + |
| 9 | + after :all do |
| 10 | + I18n.locale = :en |
| 11 | + end |
| 12 | + |
| 13 | + it 'should represent its start time by default' do |
| 14 | + t0 = Time.local(2013, 2, 14) |
| 15 | + IceCube::Schedule.new(t0).to_s.should == '14/02/2013' |
| 16 | + end |
| 17 | + |
| 18 | + it 'should have a useful base to_s representation for a secondly rule' do |
| 19 | + IceCube::Rule.secondly.to_s.should == 'cada segundo' |
| 20 | + IceCube::Rule.secondly(2).to_s.should == 'cada 2 segundos' |
| 21 | + end |
| 22 | + |
| 23 | + it 'should have a useful base to_s representation for a minutely rule' do |
| 24 | + IceCube::Rule.minutely.to_s.should == 'cada minuto' |
| 25 | + IceCube::Rule.minutely(2).to_s.should == 'cada 2 minutos' |
| 26 | + end |
| 27 | + |
| 28 | + it 'should have a useful base to_s representation for a hourly rule' do |
| 29 | + IceCube::Rule.hourly.to_s.should == 'cada hora' |
| 30 | + IceCube::Rule.hourly(2).to_s.should == 'cada 2 horas' |
| 31 | + end |
| 32 | + |
| 33 | + it 'should have a useful base to_s representation for a daily rule' do |
| 34 | + IceCube::Rule.daily.to_s.should == 'diariamente' |
| 35 | + IceCube::Rule.daily(2).to_s.should == 'cada 2 días' |
| 36 | + end |
| 37 | + |
| 38 | + it 'should have a useful base to_s representation for a weekly rule' do |
| 39 | + IceCube::Rule.weekly.to_s.should == 'semanalmente' |
| 40 | + IceCube::Rule.weekly(2).to_s.should == 'cada 2 semanas' |
| 41 | + end |
| 42 | + |
| 43 | + it 'should have a useful base to_s representation for a monthly rule' do |
| 44 | + IceCube::Rule.monthly.to_s.should == 'mensualmente' |
| 45 | + IceCube::Rule.monthly(2).to_s.should == 'cada 2 meses' |
| 46 | + end |
| 47 | + |
| 48 | + it 'should have a useful base to_s representation for a yearly rule' do |
| 49 | + IceCube::Rule.yearly.to_s.should == 'anualmente' |
| 50 | + IceCube::Rule.yearly(2).to_s.should == 'cada 2 años' |
| 51 | + end |
| 52 | + |
| 53 | + it 'should work with various sentence types properly' do |
| 54 | + IceCube::Rule.weekly.to_s.should == 'semanalmente' |
| 55 | + IceCube::Rule.weekly.day(:monday).to_s.should == 'semanalmente el Lunes' |
| 56 | + IceCube::Rule.weekly.day(:monday, :tuesday).to_s.should == 'semanalmente el Lunes y el Martes' |
| 57 | + IceCube::Rule.weekly.day(:monday, :tuesday, :wednesday).to_s.should == 'semanalmente el Lunes, el Martes y el Miércoles' |
| 58 | + end |
| 59 | + |
| 60 | + it 'should show saturday and sunday as weekends' do |
| 61 | + IceCube::Rule.weekly.day(:saturday, :sunday).to_s.should == 'semanalmente el fin de semana' |
| 62 | + end |
| 63 | + |
| 64 | + it 'should not show saturday and sunday as weekends when other days are present also' do |
| 65 | + IceCube::Rule.weekly.day(:sunday, :monday, :saturday).to_s.should == |
| 66 | + 'semanalmente el Domingo, el Lunes y el Sábado' |
| 67 | + end |
| 68 | + |
| 69 | + it 'should reorganize days to be in order' do |
| 70 | + IceCube::Rule.weekly.day(:tuesday, :monday).to_s.should == |
| 71 | + 'semanalmente el Lunes y el Martes' |
| 72 | + end |
| 73 | + |
| 74 | + it 'should show weekdays as such' do |
| 75 | + IceCube::Rule.weekly.day( |
| 76 | + :monday, :tuesday, :wednesday, |
| 77 | + :thursday, :friday |
| 78 | + ).to_s.should == 'semanalmente en días laborables' |
| 79 | + end |
| 80 | + |
| 81 | + it 'should not show weekdays as such when a weekend day is present' do |
| 82 | + IceCube::Rule.weekly.day( |
| 83 | + :sunday, :monday, :tuesday, :wednesday, |
| 84 | + :thursday, :friday |
| 85 | + ).to_s.should == 'semanalmente el Lunes, el Martes, el Miércoles, el Jueves, el Viernes y el Domingo' |
| 86 | + end |
| 87 | + |
| 88 | + it 'should work with a single date' do |
| 89 | + schedule = IceCube::Schedule.new Time.local(2010, 3, 20) |
| 90 | + schedule.add_recurrence_time Time.local(2010, 3, 20) |
| 91 | + schedule.to_s.should == "20 de Marzo 2010" |
| 92 | + end |
| 93 | + |
| 94 | + it 'should work with additional dates' do |
| 95 | + schedule = IceCube::Schedule.new Time.local(2010, 3, 20) |
| 96 | + schedule.add_recurrence_time Time.local(2010, 3, 20) |
| 97 | + schedule.add_recurrence_time Time.local(2010, 3, 21) |
| 98 | + schedule.to_s.should == '20 de Marzo 2010, 21 de Marzo 2010' |
| 99 | + end |
| 100 | + |
| 101 | + it 'should order dates that are out of order' do |
| 102 | + schedule = IceCube::Schedule.new Time.now |
| 103 | + schedule.add_recurrence_time Time.local(2010, 3, 20) |
| 104 | + schedule.add_recurrence_time Time.local(2010, 3, 19) |
| 105 | + schedule.to_s.should == '19 de Marzo 2010, 20 de Marzo 2010' |
| 106 | + end |
| 107 | + |
| 108 | + it 'should remove duplicate rdates' do |
| 109 | + schedule = IceCube::Schedule.new Time.now |
| 110 | + schedule.add_recurrence_time Time.local(2010, 3, 20) |
| 111 | + schedule.add_recurrence_time Time.local(2010, 3, 20) |
| 112 | + schedule.to_s.should == '20 de Marzo 2010' |
| 113 | + end |
| 114 | + |
| 115 | + it 'should work with rules and dates' do |
| 116 | + schedule = IceCube::Schedule.new Time.local(2010, 3, 20) |
| 117 | + schedule.add_recurrence_time Time.local(2010, 3, 20) |
| 118 | + schedule.add_recurrence_rule IceCube::Rule.weekly |
| 119 | + schedule.to_s.should == '20 de Marzo 2010, semanalmente' |
| 120 | + end |
| 121 | + |
| 122 | + it 'should work with rules and dates and exdates' do |
| 123 | + schedule = IceCube::Schedule.new Time.local(2010, 3, 20) |
| 124 | + schedule.add_recurrence_rule IceCube::Rule.weekly |
| 125 | + schedule.add_recurrence_time Time.local(2010, 3, 20) |
| 126 | + schedule.add_exception_date Time.local(2010, 3, 20) # ignored |
| 127 | + schedule.add_exception_date Time.local(2010, 3, 21) |
| 128 | + schedule.to_s.should == 'semanalmente, excepto el 20 de Marzo 2010 y 21 de Marzo 2010' |
| 129 | + end |
| 130 | + |
| 131 | + it 'should work with a single rrule' do |
| 132 | + pending 'remove dependency' |
| 133 | + schedule = IceCube::Schedule.new Time.local(2010, 3, 20) |
| 134 | + schedule.add_recurrence_rule IceCube::Rule.weekly.day_of_week(:monday => [1]) |
| 135 | + schedule.to_s.should == schedule.rrules[0].to_s |
| 136 | + end |
| 137 | + |
| 138 | + it 'should be able to say the last monday of the month' do |
| 139 | + rule_str = IceCube::Rule.monthly.day_of_week(:thursday => [-1]).to_s |
| 140 | + rule_str.should == 'mensualmente en el último Jueves' |
| 141 | + end |
| 142 | + |
| 143 | + it 'should be able to say what months of the year something happens' do |
| 144 | + rule_str = IceCube::Rule.yearly.month_of_year(:june, :july).to_s |
| 145 | + rule_str.should == 'anualmente en Junio y Julio' |
| 146 | + end |
| 147 | + |
| 148 | + it 'should be able to say the second to last monday of the month' do |
| 149 | + pending 'penultimo' |
| 150 | + rule_str = IceCube::Rule.monthly.day_of_week(:thursday => [-2]).to_s |
| 151 | + rule_str.should == 'mensualmente del segundo al último Jueves del mes' |
| 152 | + end |
| 153 | + |
| 154 | + it 'should be able to say the days of the month something happens' do |
| 155 | + rule_str = IceCube::Rule.monthly.day_of_month(1, 15, 30).to_s |
| 156 | + rule_str.should == 'mensualmente en los días 1, 15 y 30 del mes' |
| 157 | + end |
| 158 | + |
| 159 | + it 'should be able to say what day of the year something happens' do |
| 160 | + rule_str = IceCube::Rule.yearly.day_of_year(30).to_s |
| 161 | + rule_str.should == 'anualmente en el día 30' |
| 162 | + end |
| 163 | + |
| 164 | + it 'should be able to say what hour of the day something happens' do |
| 165 | + rule_str = IceCube::Rule.daily.hour_of_day(6, 12).to_s |
| 166 | + rule_str.should == 'diariamente en las horas 6 y 12' |
| 167 | + end |
| 168 | + |
| 169 | + it 'should be able to say what minute of an hour something happens - with special suffix minutes' do |
| 170 | + rule_str = IceCube::Rule.hourly.minute_of_hour(10, 11, 12, 13, 14, 15).to_s |
| 171 | + rule_str.should == 'cada hora en los minutos 10, 11, 12, 13, 14 y 15' |
| 172 | + end |
| 173 | + |
| 174 | + it 'should be able to say what seconds of the minute something happens' do |
| 175 | + rule_str = IceCube::Rule.minutely.second_of_minute(10, 11).to_s |
| 176 | + rule_str.should == 'cada minuto en los segundos 10 y 11' |
| 177 | + end |
| 178 | + |
| 179 | + it 'should be able to reflect until dates' do |
| 180 | + schedule = IceCube::Schedule.new(Time.now) |
| 181 | + schedule.rrule IceCube::Rule.weekly.until(Time.local(2012, 2, 3)) |
| 182 | + schedule.to_s.should == 'semanalmente hasta el 3 de Febrero 2012' |
| 183 | + end |
| 184 | + |
| 185 | + it 'should be able to reflect count' do |
| 186 | + schedule = IceCube::Schedule.new(Time.now) |
| 187 | + schedule.add_recurrence_rule IceCube::Rule.weekly.count(1) |
| 188 | + schedule.to_s.should == 'semanalmente 1 vez' |
| 189 | + end |
| 190 | + |
| 191 | + it 'should be able to reflect count (proper pluralization)' do |
| 192 | + schedule = IceCube::Schedule.new(Time.now) |
| 193 | + schedule.add_recurrence_rule IceCube::Rule.weekly.count(2) |
| 194 | + schedule.to_s.should == 'semanalmente 2 veces' |
| 195 | + end |
| 196 | + |
| 197 | + it 'should work when an end_time is set' do |
| 198 | + schedule = IceCube::Schedule.new(Time.local(2012, 8, 31), :end_time => Time.local(2012, 10, 31)) |
| 199 | + schedule.add_recurrence_rule IceCube::Rule.daily.count(2) |
| 200 | + schedule.to_s.should == 'diariamente 2 veces, hasta el 31 de Octubre 2012' |
| 201 | + end |
| 202 | + |
| 203 | +end |
0 commit comments