]> git.openstreetmap.org Git - rails.git/blob - test/helpers/application_helper_test.rb
Return the "large" image from the user details API call
[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 setup
7     I18n.locale = "en"
8   end
9
10   def teardown
11     I18n.locale = "en"
12   end
13
14   def test_linkify
15     %w[http://example.com/test ftp://example.com/test https://example.com/test].each do |link|
16       text = "Test #{link} is made into a link"
17
18       html = linkify(text)
19       assert_equal false, html.html_safe?
20       assert_dom_equal "Test <a href=\"#{link}\" rel=\"nofollow\">#{link}</a> is made into a link", html
21
22       html = linkify(text.html_safe)
23       assert_equal true, html.html_safe?
24       assert_dom_equal "Test <a href=\"#{link}\" rel=\"nofollow\">#{link}</a> is made into a link", html
25     end
26
27     %w[test@example.com mailto:test@example.com].each do |link|
28       text = "Test #{link} is not made into a link"
29
30       html = linkify(text)
31       assert_equal false, html.html_safe?
32       assert_dom_equal text, html
33
34       html = linkify(text.html_safe)
35       assert_equal true, html.html_safe?
36       assert_dom_equal text, html
37     end
38   end
39
40   def test_rss_link_to
41     link = rss_link_to(:controller => :diary_entry, :action => :rss)
42     assert_dom_equal "<a class=\"rsssmall\" href=\"/diary/rss\"><img border=\"0\" height=\"16\" src=\"/images/RSS.png\" width=\"16\" /></a>", link
43   end
44
45   def test_atom_link_to
46     link = atom_link_to(:controller => :changeset, :action => :feed)
47     assert_dom_equal "<a class=\"rsssmall\" href=\"/history/feed\"><img border=\"0\" height=\"16\" src=\"/images/RSS.png\" width=\"16\" /></a>", link
48   end
49
50   def test_richtext_area
51     html = richtext_area(:message, :body, :cols => 40, :rows => 20)
52     assert_not_nil html
53   end
54
55   def test_dir
56     assert_equal "ltr", dir
57
58     params[:dir] = "rtl"
59     assert_equal "rtl", dir
60     params.delete(:dir)
61
62     I18n.locale = "he"
63
64     assert_equal "rtl", dir
65
66     params[:dir] = "ltr"
67     assert_equal "ltr", dir
68     params.delete(:dir)
69   end
70
71   def test_friendly_date
72     date = friendly_date(Time.new(2014, 3, 5, 18, 58, 23))
73     assert_match %r{^<span title=" *5 March 2014 at 18:58">.*</span>$}, date
74
75     date = friendly_date(Time.now - 1.hour)
76     assert_match %r{^<span title=".*">about 1 hour</span>$}, date
77
78     date = friendly_date(Time.now - 2.days)
79     assert_match %r{^<span title=".*">2 days</span>$}, date
80
81     date = friendly_date(Time.now - 3.weeks)
82     assert_match %r{^<span title=".*">21 days</span>$}, date
83
84     date = friendly_date(Time.now - 4.months)
85     assert_match %r{^<span title=".*">4 months</span>$}, date
86   end
87
88   def test_body_class; end
89
90   def test_current_page_class; end
91 end