|
| 1 | +require File.dirname(__FILE__) + "/../spec_helper" |
| 2 | + |
| 3 | +describe IceCube::Schedule, "to_s" do |
| 4 | + before :each do |
| 5 | + I18n.locale = :id |
| 6 | + end |
| 7 | + |
| 8 | + after :all do |
| 9 | + I18n.locale = :en |
| 10 | + end |
| 11 | + |
| 12 | + it "should represent its start time by default" do |
| 13 | + t0 = Time.local(2013, 2, 14) |
| 14 | + expect(IceCube::Schedule.new(t0).to_s).to eq("14 Februari 2013") |
| 15 | + end |
| 16 | + |
| 17 | + it "should have a useful base to_s representation for a secondly rule" do |
| 18 | + expect(IceCube::Rule.secondly.to_s).to eq("Setiap detik") |
| 19 | + expect(IceCube::Rule.secondly(2).to_s).to eq("Setiap 2 detik") |
| 20 | + end |
| 21 | + |
| 22 | + it "should have a useful base to_s representation for a minutely rule" do |
| 23 | + expect(IceCube::Rule.minutely.to_s).to eq("Setiap menit") |
| 24 | + expect(IceCube::Rule.minutely(2).to_s).to eq("Setiap 2 menit") |
| 25 | + end |
| 26 | + |
| 27 | + it "should have a useful base to_s representation for a hourly rule" do |
| 28 | + expect(IceCube::Rule.hourly.to_s).to eq("Setiap jam") |
| 29 | + expect(IceCube::Rule.hourly(2).to_s).to eq("Setiap 2 jam") |
| 30 | + end |
| 31 | + |
| 32 | + it "should have a useful base to_s representation for a daily rule" do |
| 33 | + expect(IceCube::Rule.daily.to_s).to eq("Setiap hari") |
| 34 | + expect(IceCube::Rule.daily(2).to_s).to eq("Setiap 2 hari") |
| 35 | + end |
| 36 | + |
| 37 | + it "should have a useful base to_s representation for a weekly rule" do |
| 38 | + expect(IceCube::Rule.weekly.to_s).to eq("Setiap minggu") |
| 39 | + expect(IceCube::Rule.weekly(2).to_s).to eq("Setiap 2 minggu") |
| 40 | + end |
| 41 | + |
| 42 | + it "should have a useful base to_s representation for a monthly rule" do |
| 43 | + expect(IceCube::Rule.monthly.to_s).to eq("Setiap bulan") |
| 44 | + expect(IceCube::Rule.monthly(2).to_s).to eq("Setiap 2 bulan") |
| 45 | + end |
| 46 | + |
| 47 | + it "should have a useful base to_s representation for a yearly rule" do |
| 48 | + expect(IceCube::Rule.yearly.to_s).to eq("Setiap tahun") |
| 49 | + expect(IceCube::Rule.yearly(2).to_s).to eq("Setiap 2 tahun") |
| 50 | + end |
| 51 | + |
| 52 | + it "should work with various sentence types properly" do |
| 53 | + expect(IceCube::Rule.weekly.to_s).to eq("Setiap minggu") |
| 54 | + expect(IceCube::Rule.weekly.day(:monday).to_s).to eq("Setiap minggu pada Hari senin") |
| 55 | + expect(IceCube::Rule.weekly.day(:monday, :tuesday).to_s).to eq("Setiap minggu pada Hari senin dan Hari selasa") |
| 56 | + expect(IceCube::Rule.weekly.day(:monday, :tuesday, :wednesday).to_s).to eq("Setiap minggu pada Hari senin, Hari selasa dan Hari rabu") |
| 57 | + end |
| 58 | + |
| 59 | + it "should show saturday and sunday as weekends" do |
| 60 | + expect(IceCube::Rule.weekly.day(:saturday, :sunday).to_s).to eq("Setiap minggu pada akhir pekan") |
| 61 | + end |
| 62 | + |
| 63 | + it "should not show saturday and sunday as weekends when other days are present also" do |
| 64 | + expect(IceCube::Rule.weekly.day(:sunday, :monday, :saturday).to_s).to eq( |
| 65 | + "Setiap minggu pada Hari minggu, Hari senin dan Hari sabtu" |
| 66 | + ) |
| 67 | + end |
| 68 | + |
| 69 | + it "should reorganize days to be in order" do |
| 70 | + expect(IceCube::Rule.weekly.day(:tuesday, :monday).to_s).to eq( |
| 71 | + "Setiap minggu pada Hari senin dan Hari selasa" |
| 72 | + ) |
| 73 | + end |
| 74 | + |
| 75 | + it "should show weekdays as such" do |
| 76 | + expect(IceCube::Rule.weekly.day( |
| 77 | + :monday, :tuesday, :wednesday, |
| 78 | + :thursday, :friday |
| 79 | + ).to_s).to eq("Setiap minggu pada hari kerja") |
| 80 | + end |
| 81 | + |
| 82 | + it "should not show weekdays as such when a weekend day is present" do |
| 83 | + expect(IceCube::Rule.weekly.day( |
| 84 | + :sunday, :monday, :tuesday, :wednesday, |
| 85 | + :thursday, :friday |
| 86 | + ).to_s).to eq("Setiap minggu pada Hari minggu, Hari senin, Hari selasa, Hari rabu, Hari kamis dan Hari jumat") |
| 87 | + end |
| 88 | + |
| 89 | + it "should show start time for an empty schedule" do |
| 90 | + schedule = IceCube::Schedule.new Time.local(2010, 3, 20) |
| 91 | + expect(schedule.to_s).to eq("20 Maret 2010") |
| 92 | + end |
| 93 | + |
| 94 | + it "should work with a single date" do |
| 95 | + schedule = IceCube::Schedule.new Time.local(2010, 3, 20) |
| 96 | + schedule.add_recurrence_time Time.local(2010, 3, 20) |
| 97 | + expect(schedule.to_s).to eq("20 Maret 2010") |
| 98 | + end |
| 99 | + |
| 100 | + it "should work with additional dates" do |
| 101 | + schedule = IceCube::Schedule.new Time.local(2010, 3, 20) |
| 102 | + schedule.add_recurrence_time Time.local(2010, 3, 20) |
| 103 | + schedule.add_recurrence_time Time.local(2010, 3, 21) |
| 104 | + expect(schedule.to_s).to eq("20 Maret 2010 / 21 Maret 2010") |
| 105 | + end |
| 106 | + |
| 107 | + it "should order dates that are out of order" do |
| 108 | + schedule = IceCube::Schedule.new Time.local(2010, 3, 20) |
| 109 | + schedule.add_recurrence_time Time.local(2010, 3, 19) |
| 110 | + expect(schedule.to_s).to eq("19 Maret 2010 / 20 Maret 2010") |
| 111 | + end |
| 112 | + |
| 113 | + it "should remove duplicated start time" do |
| 114 | + schedule = IceCube::Schedule.new t0 = Time.local(2010, 3, 20) |
| 115 | + schedule.add_recurrence_time t0 |
| 116 | + expect(schedule.to_s).to eq("20 Maret 2010") |
| 117 | + end |
| 118 | + |
| 119 | + it "should remove duplicate rtimes" do |
| 120 | + schedule = IceCube::Schedule.new Time.local(2010, 3, 19) |
| 121 | + schedule.add_recurrence_time Time.local(2010, 3, 20) |
| 122 | + schedule.add_recurrence_time Time.local(2010, 3, 20) |
| 123 | + expect(schedule.to_s).to eq("19 Maret 2010 / 20 Maret 2010") |
| 124 | + end |
| 125 | + |
| 126 | + it "should work with rules and dates" do |
| 127 | + schedule = IceCube::Schedule.new Time.local(2010, 3, 19) |
| 128 | + schedule.add_recurrence_time Time.local(2010, 3, 20) |
| 129 | + schedule.add_recurrence_rule IceCube::Rule.weekly |
| 130 | + expect(schedule.to_s).to eq("20 Maret 2010 / Setiap minggu") |
| 131 | + end |
| 132 | + |
| 133 | + it "should work with rules and times and exception times" do |
| 134 | + schedule = IceCube::Schedule.new Time.local(2010, 3, 20) |
| 135 | + schedule.add_recurrence_rule IceCube::Rule.weekly |
| 136 | + schedule.add_recurrence_time Time.local(2010, 3, 20) |
| 137 | + schedule.add_exception_time Time.local(2010, 3, 20) # ignored |
| 138 | + schedule.add_exception_time Time.local(2010, 3, 21) |
| 139 | + expect(schedule.to_s).to eq("Setiap minggu / kecuali 20 Maret 2010 / kecuali 21 Maret 2010") |
| 140 | + end |
| 141 | + |
| 142 | + it "should work with a single rule" do |
| 143 | + schedule = IceCube::Schedule.new Time.local(2010, 3, 20) |
| 144 | + schedule.add_recurrence_rule IceCube::Rule.weekly.day_of_week(monday: [1]) |
| 145 | + expect(schedule.to_s).to eq(schedule.rrules[0].to_s) |
| 146 | + end |
| 147 | + |
| 148 | + it "should be able to say the last Thursday of the month" do |
| 149 | + rule_str = IceCube::Rule.monthly.day_of_week(thursday: [-1]).to_s |
| 150 | + expect(rule_str).to eq("Setiap bulan pada terakhir Kamis") |
| 151 | + end |
| 152 | + |
| 153 | + it "should be able to say what months of the year something happens" do |
| 154 | + rule_str = IceCube::Rule.yearly.month_of_year(:june, :july).to_s |
| 155 | + expect(rule_str).to eq("Setiap tahun pada Juni dan Juli") |
| 156 | + end |
| 157 | + |
| 158 | + it "should be able to say the second to last monday of the month" do |
| 159 | + rule_str = IceCube::Rule.monthly.day_of_week(thursday: [-2]).to_s |
| 160 | + expect(rule_str).to eq("Setiap bulan pada kedua sampai terakhir Kamis") |
| 161 | + end |
| 162 | + |
| 163 | + it "should join the first and last weekdays of the month" do |
| 164 | + rule_str = IceCube::Rule.monthly.day_of_week(thursday: [1, -1]).to_s |
| 165 | + expect(rule_str).to eq("Setiap bulan pada pertama Kamis dan terakhir Kamis") |
| 166 | + end |
| 167 | + |
| 168 | + it "should be able to say the days of the month something happens" do |
| 169 | + rule_str = IceCube::Rule.monthly.day_of_month(1, 15, 30).to_s |
| 170 | + expect(rule_str).to eq("Setiap bulan pada hari ke pertama, 15 dan 30 dalam satu bulan") |
| 171 | + end |
| 172 | + |
| 173 | + it "should be able to say what day of the year something happens" do |
| 174 | + rule_str = IceCube::Rule.yearly.day_of_year(30).to_s |
| 175 | + expect(rule_str).to eq("Setiap tahun pada hari ke 30 dalam satu tahun") |
| 176 | + end |
| 177 | + |
| 178 | + it "should be able to say what hour of the day something happens" do |
| 179 | + rule_str = IceCube::Rule.daily.hour_of_day(6, 12).to_s |
| 180 | + expect(rule_str).to eq("Setiap hari pada jam 6 dan 12 dalam satu hari") |
| 181 | + end |
| 182 | + |
| 183 | + it "should be able to say what minute of an hour something happens - with special suffix minutes" do |
| 184 | + rule_str = IceCube::Rule.hourly.minute_of_hour(10, 11, 12, 13, 14, 15).to_s |
| 185 | + expect(rule_str).to eq("Setiap jam pada menit ke 10, 11, 12, 13, 14 dan 15 dalam satu jam") |
| 186 | + end |
| 187 | + |
| 188 | + it "should be able to say what seconds of the minute something happens" do |
| 189 | + rule_str = IceCube::Rule.minutely.second_of_minute(10, 11).to_s |
| 190 | + expect(rule_str).to eq("Setiap menit pada detik ke 10 dan 11 dalam satu menit") |
| 191 | + end |
| 192 | + |
| 193 | + it "should be able to reflect until dates" do |
| 194 | + schedule = IceCube::Schedule.new(Time.now) |
| 195 | + schedule.rrule IceCube::Rule.weekly.until(Time.local(2012, 2, 3)) |
| 196 | + expect(schedule.to_s).to eq("Setiap minggu sampai 3 Februari 2012") |
| 197 | + end |
| 198 | + |
| 199 | + it "should be able to reflect count" do |
| 200 | + schedule = IceCube::Schedule.new(Time.now) |
| 201 | + schedule.add_recurrence_rule IceCube::Rule.weekly.count(1) |
| 202 | + expect(schedule.to_s).to eq("Setiap minggu 1 kali") |
| 203 | + end |
| 204 | + |
| 205 | + it "should be able to reflect count (proper pluralization)" do |
| 206 | + schedule = IceCube::Schedule.new(Time.now) |
| 207 | + schedule.add_recurrence_rule IceCube::Rule.weekly.count(2) |
| 208 | + expect(schedule.to_s).to eq("Setiap minggu 2 kali") |
| 209 | + end |
| 210 | +end |
0 commit comments