]> git.openstreetmap.org Git - rails.git/blob - test/helpers/application_helper_test.rb
Merge pull request #6394 from openstreetmap/dependabot/github_actions/ruby/setup...
[rails.git] / test / helpers / application_helper_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 class ApplicationHelperTest < ActionView::TestCase
6   attr_accessor :current_user
7
8   def test_linkify
9     %w[http://example.com/test ftp://example.com/test https://example.com/test].each do |link|
10       text = "Test #{link} is <b>made</b> into a link"
11
12       html = linkify(text)
13       assert_predicate html, :html_safe?
14       assert_dom_equal "Test <a href=\"#{link}\" rel=\"nofollow\" dir=\"auto\">#{link}</a> is &lt;b&gt;made&lt;/b&gt; into a link", html
15
16       html = linkify(text.html_safe)
17       assert_predicate html, :html_safe?
18       assert_dom_equal "Test <a href=\"#{link}\" rel=\"nofollow\" dir=\"auto\">#{link}</a> is <b>made</b> into a link", html
19     end
20
21     %w[test@example.com mailto:test@example.com].each do |link|
22       text = "Test #{link} is not <b>made</b> into a link"
23
24       html = linkify(text)
25       assert_predicate html, :html_safe?
26       assert_dom_equal "Test #{link} is not &lt;b&gt;made&lt;/b&gt; into a link", html
27
28       html = linkify(text.html_safe)
29       assert_predicate html, :html_safe?
30       assert_dom_equal "Test #{link} is not <b>made</b> into a link", html
31     end
32   end
33
34   def test_rss_link_to
35     link = rss_link_to(:controller => :diary_entries, :action => :rss)
36     assert_dom_equal "<a href=\"/diary/rss\"><img height=\"16\" src=\"/images/RSS.png\" width=\"16\" class=\"align-text-bottom\" /></a>", link
37   end
38
39   def test_atom_link_to
40     link = atom_link_to(:controller => :changesets, :action => :feed)
41     assert_dom_equal "<a href=\"/history/feed\"><img height=\"16\" src=\"/images/RSS.png\" width=\"16\" class=\"align-text-bottom\" /></a>", link
42   end
43
44   def test_dir
45     assert_equal "ltr", dir
46
47     params[:dir] = "rtl"
48     assert_equal "rtl", dir
49     params.delete(:dir)
50
51     I18n.with_locale "he" do
52       assert_equal "rtl", dir
53
54       params[:dir] = "ltr"
55       assert_equal "ltr", dir
56       params.delete(:dir)
57     end
58   end
59
60   def test_friendly_date
61     date = friendly_date(Time.utc(2014, 3, 5, 18, 58, 23))
62     assert_match %r{^<time title=" *5 March 2014 at 18:58" datetime="2014-03-05T18:58:23Z">.*</time>$}, date
63
64     date = friendly_date(Time.now.utc - 1.hour)
65     assert_match %r{^<time title=".*">about 1 hour</time>$}, date
66
67     date = friendly_date(Time.now.utc - 2.days)
68     assert_match %r{^<time title=".*">2 days</time>$}, date
69
70     date = friendly_date(Time.now.utc - 3.weeks)
71     assert_match %r{^<time title=".*">21 days</time>$}, date
72
73     date = friendly_date(Time.now.utc - 4.months)
74     assert_match %r{^<time title=".*">4 months</time>$}, date
75   end
76
77   def test_friendly_date_ago
78     date = friendly_date_ago(Time.utc(2014, 3, 5, 18, 58, 23))
79     assert_match %r{^<time title=" *5 March 2014 at 18:58" datetime="2014-03-05T18:58:23Z">.*</time>$}, date
80
81     date = friendly_date_ago(Time.now.utc - 1.hour)
82     assert_match %r{^<time title=".*">about 1 hour ago</time>$}, date
83
84     date = friendly_date_ago(Time.now.utc - 2.days)
85     assert_match %r{^<time title=".*">2 days ago</time>$}, date
86
87     date = friendly_date_ago(Time.now.utc - 3.weeks)
88     assert_match %r{^<time title=".*">21 days ago</time>$}, date
89
90     date = friendly_date_ago(Time.now.utc - 4.months)
91     assert_match %r{^<time title=".*">4 months ago</time>$}, date
92   end
93 end