3 class ApplicationHelperTest < ActionView::TestCase
13 %w(http://example.com/test ftp://example.com/test https://example.com/test).each do |link|
14 text = "Test #{link} is made into a link"
17 assert_equal false, html.html_safe?
18 assert_dom_equal "Test <a href=\"#{link}\" rel=\"nofollow\">#{link}</a> is made into a link", html
20 html = linkify(text.html_safe)
21 assert_equal true, html.html_safe?
22 assert_dom_equal "Test <a href=\"#{link}\" rel=\"nofollow\">#{link}</a> is made into a link", html
25 %w(test@example.com mailto:test@example.com).each do |link|
26 text = "Test #{link} is not made into a link"
29 assert_equal false, html.html_safe?
30 assert_dom_equal text, html
32 html = linkify(text.html_safe)
33 assert_equal true, html.html_safe?
34 assert_dom_equal text, html
39 link = rss_link_to(:controller => :diary_entry, :action => :rss)
40 assert_dom_equal "<a class=\"rsssmall\" href=\"/diary/rss\"><img alt=\"Rss\" border=\"0\" height=\"16\" src=\"/images/RSS.png\" width=\"16\" /></a>", link
44 link = atom_link_to(:controller => :changeset, :action => :feed)
45 assert_dom_equal "<a class=\"rsssmall\" href=\"/history/feed\"><img alt=\"Rss\" border=\"0\" height=\"16\" src=\"/images/RSS.png\" width=\"16\" /></a>", link
52 assert_match /\.hidden /, css
53 assert_match /\.hide_unless_logged_in /, css
54 assert_no_match /\.hide_if_logged_in /, css
55 assert_no_match /\.hide_if_user_/, css
56 assert_no_match /\.show_if_user_/, css
57 assert_match /\.hide_unless_administrator /, css
58 assert_match /\.hide_unless_moderator /, css
63 assert_match /\.hidden /, css
64 assert_no_match /\.hide_unless_logged_in /, css
65 assert_match /\.hide_if_logged_in /, css
66 assert_match /\.hide_if_user_#{@user.id} /, css
67 assert_match /\.show_if_user_#{@user.id} /, css
68 assert_match /\.hide_unless_administrator /, css
69 assert_match /\.hide_unless_moderator /, css
71 @user = create(:moderator_user)
74 assert_match /\.hidden /, css
75 assert_no_match /\.hide_unless_logged_in /, css
76 assert_match /\.hide_if_logged_in /, css
77 assert_match /\.hide_if_user_#{@user.id} /, css
78 assert_match /\.show_if_user_#{@user.id} /, css
79 assert_match /\.hide_unless_administrator /, css
80 assert_no_match /\.hide_unless_moderator /, css
82 @user = create(:administrator_user)
85 assert_match /\.hidden /, css
86 assert_no_match /\.hide_unless_logged_in /, css
87 assert_match /\.hide_if_logged_in /, css
88 assert_match /\.hide_if_user_#{@user.id} /, css
89 assert_match /\.show_if_user_#{@user.id} /, css
90 assert_no_match /\.hide_unless_administrator /, css
91 assert_match /\.hide_unless_moderator /, css
95 html = if_logged_in { "Test 1" }
96 assert_dom_equal "<div class=\"hide_unless_logged_in\">Test 1</div>", html
98 html = if_logged_in(:span) { "Test 2" }
99 assert_dom_equal "<span class=\"hide_unless_logged_in\">Test 2</span>", html
102 def test_if_not_logged_in
103 html = if_not_logged_in { "Test 1" }
104 assert_dom_equal "<div class=\"hide_if_logged_in\">Test 1</div>", html
106 html = if_not_logged_in(:span) { "Test 2" }
107 assert_dom_equal "<span class=\"hide_if_logged_in\">Test 2</span>", html
113 html = if_user(user) { "Test 1" }
114 assert_dom_equal "<div class=\"hidden show_if_user_#{user.id}\">Test 1</div>", html
116 html = if_user(user, :span) { "Test 2" }
117 assert_dom_equal "<span class=\"hidden show_if_user_#{user.id}\">Test 2</span>", html
119 html = if_user(nil) { "Test 3" }
122 html = if_user(nil, :span) { "Test 4" }
129 html = unless_user(user) { "Test 1" }
130 assert_dom_equal "<div class=\"hide_if_user_#{user.id}\">Test 1</div>", html
132 html = unless_user(user, :span) { "Test 2" }
133 assert_dom_equal "<span class=\"hide_if_user_#{user.id}\">Test 2</span>", html
135 html = unless_user(nil) { "Test 3" }
136 assert_dom_equal "<div>Test 3</div>", html
138 html = unless_user(nil, :span) { "Test 4" }
139 assert_dom_equal "<span>Test 4</span>", html
142 def test_if_administrator
143 html = if_administrator { "Test 1" }
144 assert_dom_equal "<div class=\"hide_unless_administrator\">Test 1</div>", html
146 html = if_administrator(:span) { "Test 2" }
147 assert_dom_equal "<span class=\"hide_unless_administrator\">Test 2</span>", html
150 def test_richtext_area
151 html = richtext_area(:message, :body, :cols => 40, :rows => 20)
156 assert_equal "ltr", dir
159 assert_equal "rtl", dir
164 assert_equal "rtl", dir
167 assert_equal "ltr", dir
171 def test_friendly_date
172 date = friendly_date(Time.new(2014, 3, 5, 18, 58, 23))
173 assert_match %r{^<span title=" *5 March 2014 at 18:58">.*</span>$}, date
175 date = friendly_date(Time.now - 1.hour)
176 assert_match %r{^<span title=".*">about 1 hour</span>$}, date
178 date = friendly_date(Time.now - 2.days)
179 assert_match %r{^<span title=".*">2 days</span>$}, date
181 date = friendly_date(Time.now - 3.weeks)
182 assert_match %r{^<span title=".*">21 days</span>$}, date
184 date = friendly_date(Time.now - 4.months)
185 assert_match %r{^<span title=".*">4 months</span>$}, date
188 def test_body_class; end
190 def test_current_page_class; end