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