diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-13 23:33:11 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-13 23:33:11 +0200 |
| commit | 8eab68f2c5a3c126e2fec2ecdfa7ace87ce0937b (patch) | |
| tree | f446ebc26a7707c7b64a937aa51a155df146c80a /test/models/helpers | |
| parent | 42714c697273a7117c6b355fab26c8c35e336ad1 (diff) | |
| parent | cdf5d9941ca866d437612d2f863eac6eb0b3db12 (diff) | |
Merge branch 'erdgeist-revive-events'
Diffstat (limited to 'test/models/helpers')
| -rw-r--r-- | test/models/helpers/admin_helper_test.rb | 10 | ||||
| -rw-r--r-- | test/models/helpers/content_helper_test.rb | 4 | ||||
| -rw-r--r-- | test/models/helpers/datetime_helper_test.rb | 19 | ||||
| -rw-r--r-- | test/models/helpers/events_helper_test.rb | 21 | ||||
| -rw-r--r-- | test/models/helpers/nodes_helper_test.rb | 32 |
5 files changed, 86 insertions, 0 deletions
diff --git a/test/models/helpers/admin_helper_test.rb b/test/models/helpers/admin_helper_test.rb index 23d9f40..94e9861 100644 --- a/test/models/helpers/admin_helper_test.rb +++ b/test/models/helpers/admin_helper_test.rb | |||
| @@ -1,4 +1,14 @@ | |||
| 1 | require 'test_helper' | 1 | require 'test_helper' |
| 2 | 2 | ||
| 3 | class AdminHelperTest < ActionView::TestCase | 3 | class AdminHelperTest < ActionView::TestCase |
| 4 | test "mtime_busted_path appends the file's real mtime as a query param" do | ||
| 5 | path = "/stylesheets/admin.css" | ||
| 6 | expected_mtime = File.mtime(Rails.public_path.join("stylesheets/admin.css")).to_i | ||
| 7 | |||
| 8 | assert_equal "#{path}?v=#{expected_mtime}", mtime_busted_path(path) | ||
| 9 | end | ||
| 10 | |||
| 11 | test "mtime_busted_path raises clearly for a missing file rather than silently omitting the version" do | ||
| 12 | assert_raises(RuntimeError) { mtime_busted_path("/stylesheets/does_not_exist.css") } | ||
| 13 | end | ||
| 4 | end | 14 | end |
diff --git a/test/models/helpers/content_helper_test.rb b/test/models/helpers/content_helper_test.rb index 2da82d7..a7ed478 100644 --- a/test/models/helpers/content_helper_test.rb +++ b/test/models/helpers/content_helper_test.rb | |||
| @@ -1,4 +1,8 @@ | |||
| 1 | require 'test_helper' | 1 | require 'test_helper' |
| 2 | 2 | ||
| 3 | class ContentHelperTest < ActionView::TestCase | 3 | class ContentHelperTest < ActionView::TestCase |
| 4 | test "weekday_abbr delegates through the current I18n locale" do | ||
| 5 | I18n.locale = :de | ||
| 6 | assert_equal "Mo", weekday_abbr(Time.parse("2026-07-06")) | ||
| 7 | end | ||
| 4 | end | 8 | end |
diff --git a/test/models/helpers/datetime_helper_test.rb b/test/models/helpers/datetime_helper_test.rb new file mode 100644 index 0000000..a24e5d3 --- /dev/null +++ b/test/models/helpers/datetime_helper_test.rb | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | require 'test_helper' | ||
| 2 | |||
| 3 | class DatetimeHelperTest < ActionView::TestCase | ||
| 4 | test "relative_time_phrase pluralizes correctly in English and German" do | ||
| 5 | travel_to Time.zone.parse("2026-07-12 12:00:00") do | ||
| 6 | I18n.with_locale(:en) do | ||
| 7 | assert_equal "1 day ago", relative_time_phrase(1.day.ago) | ||
| 8 | assert_equal "3 days ago", relative_time_phrase(3.days.ago) | ||
| 9 | end | ||
| 10 | I18n.with_locale(:de) do | ||
| 11 | assert_equal "vor 1 Tag", relative_time_phrase(1.day.ago) | ||
| 12 | assert_equal "vor 3 Tagen", relative_time_phrase(3.days.ago) | ||
| 13 | assert_equal "vor 1 Monat", relative_time_phrase(30.days.ago) | ||
| 14 | assert_equal "vor 2 Monaten", relative_time_phrase(45.days.ago) | ||
| 15 | assert_equal "vor 2 Jahren", relative_time_phrase(2.years.ago) | ||
| 16 | end | ||
| 17 | end | ||
| 18 | end | ||
| 19 | end | ||
diff --git a/test/models/helpers/events_helper_test.rb b/test/models/helpers/events_helper_test.rb index 2e7567e..0486b3e 100644 --- a/test/models/helpers/events_helper_test.rb +++ b/test/models/helpers/events_helper_test.rb | |||
| @@ -1,4 +1,25 @@ | |||
| 1 | require 'test_helper' | 1 | require 'test_helper' |
| 2 | 2 | ||
| 3 | class EventsHelperTest < ActionView::TestCase | 3 | class EventsHelperTest < ActionView::TestCase |
| 4 | test "rrule_with_break_opportunities inserts a break opportunity after each semicolon" do | ||
| 5 | result = rrule_with_break_opportunities("FREQ=MONTHLY;BYMONTH=1,2,3;BYDAY=-1TH") | ||
| 6 | assert_equal "FREQ=MONTHLY;<wbr>BYMONTH=1,2,3;<wbr>BYDAY=-1TH", result | ||
| 7 | assert result.html_safe? | ||
| 8 | end | ||
| 9 | |||
| 10 | test "rrule_with_break_opportunities escapes HTML-significant characters" do | ||
| 11 | result = rrule_with_break_opportunities("FREQ=WEEKLY;BYDAY=<script>") | ||
| 12 | assert_no_match /<script>/, result | ||
| 13 | assert_match "<script>", result | ||
| 14 | end | ||
| 15 | |||
| 16 | test "rrule_with_break_opportunities returns an empty string for blank input" do | ||
| 17 | assert_equal "", rrule_with_break_opportunities(nil) | ||
| 18 | assert_equal "", rrule_with_break_opportunities("") | ||
| 19 | end | ||
| 20 | |||
| 21 | test "rrule_with_break_opportunities preserves a trailing semicolon" do | ||
| 22 | result = rrule_with_break_opportunities("FREQ=WEEKLY;") | ||
| 23 | assert_equal "FREQ=WEEKLY;<wbr>", result | ||
| 24 | end | ||
| 4 | end | 25 | end |
diff --git a/test/models/helpers/nodes_helper_test.rb b/test/models/helpers/nodes_helper_test.rb index 13011de..5ab924f 100644 --- a/test/models/helpers/nodes_helper_test.rb +++ b/test/models/helpers/nodes_helper_test.rb | |||
| @@ -1,4 +1,36 @@ | |||
| 1 | require 'test_helper' | 1 | require 'test_helper' |
| 2 | 2 | ||
| 3 | class NodesHelperTest < ActionView::TestCase | 3 | class NodesHelperTest < ActionView::TestCase |
| 4 | FakePage = Struct.new(:tag_list) | ||
| 5 | |||
| 6 | test "default_event_tag_mapping matches erfa-detail" do | ||
| 7 | page = FakePage.new(["erfa-detail"]) | ||
| 8 | assert_equal ["erfa-detail", "open-day"], default_event_tag_mapping(page) | ||
| 9 | end | ||
| 10 | |||
| 11 | test "default_event_tag_mapping matches chaostreff-detail" do | ||
| 12 | page = FakePage.new(["chaostreff-detail"]) | ||
| 13 | assert_equal ["chaostreff-detail", "open-day"], default_event_tag_mapping(page) | ||
| 14 | end | ||
| 15 | |||
| 16 | test "default_event_tag_mapping returns nil for unrelated tags" do | ||
| 17 | page = FakePage.new(["update"]) | ||
| 18 | assert_nil default_event_tag_mapping(page) | ||
| 19 | end | ||
| 20 | |||
| 21 | test "default_event_tag_list is nil without a matching tag" do | ||
| 22 | page = FakePage.new([]) | ||
| 23 | assert_nil default_event_tag_list(page) | ||
| 24 | end | ||
| 25 | |||
| 26 | test "sitemap_node_open? is false for a configured collapsed path" do | ||
| 27 | club = Node.root.children.create!(:slug => "club") | ||
| 28 | erfas = club.children.create!(:slug => "erfas") | ||
| 29 | assert_equal false, sitemap_node_open?(erfas) | ||
| 30 | end | ||
| 31 | |||
| 32 | test "sitemap_node_open? is true for anything not configured as collapsed" do | ||
| 33 | node = Node.root.children.create!(:slug => "sitemap_open_test") | ||
| 34 | assert_equal true, sitemap_node_open?(node) | ||
| 35 | end | ||
| 4 | end | 36 | end |
