diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/models/concerns/rrule_humanizer_test.rb | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/test/models/concerns/rrule_humanizer_test.rb b/test/models/concerns/rrule_humanizer_test.rb new file mode 100644 index 0000000..500dbc7 --- /dev/null +++ b/test/models/concerns/rrule_humanizer_test.rb | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | require 'test_helper' | ||
| 2 | |||
| 3 | class RruleHumanizerTest < ActiveSupport::TestCase | ||
| 4 | def humanize(rrule, locale = :de) | ||
| 5 | Event.new(rrule: rrule).humanize_rrule(locale) | ||
| 6 | end | ||
| 7 | |||
| 8 | test "weekly single day" do | ||
| 9 | assert_equal "Jeden Dienstag", humanize("FREQ=WEEKLY;BYDAY=TU") | ||
| 10 | assert_equal "Every Tuesday", humanize("FREQ=WEEKLY;BYDAY=TU", :en) | ||
| 11 | end | ||
| 12 | |||
| 13 | test "weekly two days" do | ||
| 14 | assert_equal "Jeden Mittwoch und Freitag", humanize("FREQ=WEEKLY;BYDAY=WE,FR") | ||
| 15 | assert_equal "Every Wednesday and Friday", humanize("FREQ=WEEKLY;BYDAY=WE,FR", :en) | ||
| 16 | end | ||
| 17 | |||
| 18 | test "weekly no byday" do | ||
| 19 | assert_equal "Wöchentlich", humanize("FREQ=WEEKLY") | ||
| 20 | assert_equal "Weekly", humanize("FREQ=WEEKLY", :en) | ||
| 21 | end | ||
| 22 | |||
| 23 | test "biweekly with day" do | ||
| 24 | assert_equal "Alle zwei Wochen donnerstags", humanize("FREQ=WEEKLY;INTERVAL=2;BYDAY=TH") | ||
| 25 | assert_equal "Every other Thursday", humanize("FREQ=WEEKLY;INTERVAL=2;BYDAY=TH", :en) | ||
| 26 | end | ||
| 27 | |||
| 28 | test "biweekly no day" do | ||
| 29 | assert_equal "Alle zwei Wochen", humanize("FREQ=WEEKLY;INTERVAL=2") | ||
| 30 | assert_equal "Every other week", humanize("FREQ=WEEKLY;INTERVAL=2", :en) | ||
| 31 | end | ||
| 32 | |||
| 33 | test "monthly nth weekday" do | ||
| 34 | assert_equal "Jeden ersten Dienstag im Monat", humanize("FREQ=MONTHLY;BYDAY=1TU") | ||
| 35 | assert_equal "Jeden zweiten Freitag im Monat", humanize("FREQ=MONTHLY;BYDAY=2FR") | ||
| 36 | assert_equal "Jeden dritten Sonntag im Monat", humanize("FREQ=MONTHLY;BYDAY=3SU") | ||
| 37 | assert_equal "Jeden letzten Mittwoch im Monat", humanize("FREQ=MONTHLY;BYDAY=-1WE") | ||
| 38 | end | ||
| 39 | |||
| 40 | test "monthly nth weekday english" do | ||
| 41 | assert_equal "Every first Tuesday of the month", humanize("FREQ=MONTHLY;BYDAY=1TU", :en) | ||
| 42 | assert_equal "Every last Wednesday of the month", humanize("FREQ=MONTHLY;BYDAY=-1WE", :en) | ||
| 43 | end | ||
| 44 | |||
| 45 | test "monthly second-to-last" do | ||
| 46 | assert_equal "Jeden vorletzten Donnerstag im Monat", humanize("FREQ=MONTHLY;BYDAY=-2TH") | ||
| 47 | assert_equal "Every second-to-last Thursday of the month", humanize("FREQ=MONTHLY;BYDAY=-2TH", :en) | ||
| 48 | end | ||
| 49 | |||
| 50 | test "monthly no byday" do | ||
| 51 | assert_equal "Monatlich", humanize("FREQ=MONTHLY") | ||
| 52 | assert_equal "Monthly", humanize("FREQ=MONTHLY", :en) | ||
| 53 | end | ||
| 54 | |||
| 55 | test "monthly with single excluded month" do | ||
| 56 | assert_equal "Jeden letzten Donnerstag im Monat, außer im Dezember", | ||
| 57 | humanize("FREQ=MONTHLY;BYDAY=-1TH;BYMONTH=1,2,3,4,5,6,7,8,9,10,11") | ||
| 58 | assert_equal "Every last Thursday of the month, except in December", | ||
| 59 | humanize("FREQ=MONTHLY;BYDAY=-1TH;BYMONTH=1,2,3,4,5,6,7,8,9,10,11", :en) | ||
| 60 | end | ||
| 61 | |||
| 62 | test "monthly excluding january" do | ||
| 63 | assert_equal "Jeden zweiten Mittwoch im Monat, außer im Januar", | ||
| 64 | humanize("FREQ=MONTHLY;BYMONTH=2,3,4,5,6,7,8,9,10,11,12;BYDAY=2WE") | ||
| 65 | end | ||
| 66 | |||
| 67 | test "blank rrule returns nil" do | ||
| 68 | assert_nil humanize(nil) | ||
| 69 | assert_nil humanize("") | ||
| 70 | end | ||
| 71 | |||
| 72 | test "count and until are not guessed at" do | ||
| 73 | assert_nil humanize("FREQ=MONTHLY;BYDAY=1WE;COUNT=36") | ||
| 74 | assert_nil humanize("FREQ=MONTHLY;BYDAY=1WE;UNTIL=20050105T222222Z") | ||
| 75 | end | ||
| 76 | |||
| 77 | test "unrecognized freq returns nil" do | ||
| 78 | assert_nil humanize("FREQ=YEARLY;BYMONTH=12") | ||
| 79 | end | ||
| 80 | |||
| 81 | test "falls back to english for unknown locale" do | ||
| 82 | assert_equal "Every Tuesday", humanize("FREQ=WEEKLY;BYDAY=TU", :fr) | ||
| 83 | end | ||
| 84 | end | ||
