summaryrefslogtreecommitdiff
path: root/test/models/concerns
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-13 23:33:11 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-13 23:33:11 +0200
commit8eab68f2c5a3c126e2fec2ecdfa7ace87ce0937b (patch)
treef446ebc26a7707c7b64a937aa51a155df146c80a /test/models/concerns
parent42714c697273a7117c6b355fab26c8c35e336ad1 (diff)
parentcdf5d9941ca866d437612d2f863eac6eb0b3db12 (diff)
Merge branch 'erdgeist-revive-events'
Diffstat (limited to 'test/models/concerns')
-rw-r--r--test/models/concerns/rrule_humanizer_test.rb99
1 files changed, 99 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..279ff73
--- /dev/null
+++ b/test/models/concerns/rrule_humanizer_test.rb
@@ -0,0 +1,99 @@
1require 'test_helper'
2
3class 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
85 test "wday_abbr returns the correct German abbreviation for each day" do
86 monday = Time.parse("2026-07-06") # confirmed Monday
87 assert_equal "Mo", RruleHumanizer.wday_abbr(monday, :de)
88 assert_equal "Di", RruleHumanizer.wday_abbr(monday + 1.day, :de)
89 assert_equal "Mi", RruleHumanizer.wday_abbr(monday + 2.days, :de)
90 assert_equal "Do", RruleHumanizer.wday_abbr(monday + 3.days, :de)
91 assert_equal "Fr", RruleHumanizer.wday_abbr(monday + 4.days, :de)
92 assert_equal "Sa", RruleHumanizer.wday_abbr(monday + 5.days, :de)
93 assert_equal "So", RruleHumanizer.wday_abbr(monday + 6.days, :de)
94 end
95
96 test "wday_abbr falls back to :de for an unrecognized locale" do
97 assert_equal "Mo", RruleHumanizer.wday_abbr(Time.parse("2026-07-06"), :fr)
98 end
99end