3 class ApplicationHelperTest < ActionView::TestCase
4 fixtures :users, :user_roles
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"
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
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
27 %w(test@example.com mailto:test@example.com).each do |link|
28 text = "Test #{link} is not made into a link"
31 assert_equal false, html.html_safe?
32 assert_dom_equal text, html
34 html = linkify(text.html_safe)
35 assert_equal true, html.html_safe?
36 assert_dom_equal text, html
41 link = rss_link_to(:controller => :diary_entry, :action => :rss)
42 assert_dom_equal "<a class=\"rsssmall\" href=\"/diary/rss\"><img alt=\"Rss\" border=\"0\" height=\"16\" src=\"/images/RSS.png\" width=\"16\" /></a>", link
46 link = atom_link_to(:controller => :changeset, :action => :feed)
47 assert_dom_equal "<a class=\"rsssmall\" href=\"/history/feed\"><img alt=\"Rss\" border=\"0\" height=\"16\" src=\"/images/RSS.png\" width=\"16\" /></a>", link
54 assert_match /\.hidden /, css
55 assert_match /\.hide_unless_logged_in /, css
56 assert_no_match /\.hide_if_logged_in /, css
57 assert_no_match /\.hide_if_user_/, css
58 assert_no_match /\.show_if_user_/, css
59 assert_match /\.hide_unless_administrator /, css
60 assert_match /\.hide_unless_moderator /, css
62 @user = users(:normal_user)
65 assert_match /\.hidden /, css
66 assert_no_match /\.hide_unless_logged_in /, css
67 assert_match /\.hide_if_logged_in /, css
68 assert_match /\.hide_if_user_1 /, css
69 assert_match /\.show_if_user_1 /, css
70 assert_match /\.hide_unless_administrator /, css
71 assert_match /\.hide_unless_moderator /, css
73 @user = users(:moderator_user)
76 assert_match /\.hidden /, css
77 assert_no_match /\.hide_unless_logged_in /, css
78 assert_match /\.hide_if_logged_in /, css
79 assert_match /\.hide_if_user_5 /, css
80 assert_match /\.show_if_user_5 /, css
81 assert_match /\.hide_unless_administrator /, css
82 assert_no_match /\.hide_unless_moderator /, css
84 @user = users(:administrator_user)
87 assert_match /\.hidden /, css
88 assert_no_match /\.hide_unless_logged_in /, css
89 assert_match /\.hide_if_logged_in /, css
90 assert_match /\.hide_if_user_6 /, css
91 assert_match /\.show_if_user_6 /, css
92 assert_no_match /\.hide_unless_administrator /, css
93 assert_match /\.hide_unless_moderator /, css
97 html = if_logged_in { "Test 1" }
98 assert_dom_equal "<div class=\"hide_unless_logged_in\">Test 1</div>", html
100 html = if_logged_in(:span) { "Test 2" }
101 assert_dom_equal "<span class=\"hide_unless_logged_in\">Test 2</span>", html
104 def test_if_not_logged_in
105 html = if_not_logged_in { "Test 1" }
106 assert_dom_equal "<div class=\"hide_if_logged_in\">Test 1</div>", html
108 html = if_not_logged_in(:span) { "Test 2" }
109 assert_dom_equal "<span class=\"hide_if_logged_in\">Test 2</span>", html
113 html = if_user(users(:normal_user)) { "Test 1" }
114 assert_dom_equal "<div class=\"hidden show_if_user_1\">Test 1</div>", html
116 html = if_user(users(:normal_user), :span) { "Test 2" }
117 assert_dom_equal "<span class=\"hidden show_if_user_1\">Test 2</span>", html
119 html = if_user(nil) { "Test 3" }
122 html = if_user(nil, :span) { "Test 4" }
127 html = unless_user(users(:normal_user)) { "Test 1" }
128 assert_dom_equal "<div class=\"hide_if_user_1\">Test 1</div>", html
130 html = unless_user(users(:normal_user), :span) { "Test 2" }
131 assert_dom_equal "<span class=\"hide_if_user_1\">Test 2</span>", html
133 html = unless_user(nil) { "Test 3" }
134 assert_dom_equal "<div>Test 3</div>", html
136 html = unless_user(nil, :span) { "Test 4" }
137 assert_dom_equal "<span>Test 4</span>", html
140 def test_if_administrator
141 html = if_administrator { "Test 1" }
142 assert_dom_equal "<div class=\"hide_unless_administrator\">Test 1</div>", html
144 html = if_administrator(:span) { "Test 2" }
145 assert_dom_equal "<span class=\"hide_unless_administrator\">Test 2</span>", html
148 def test_richtext_area
149 html = richtext_area(:message, :body, :cols => 40, :rows => 20)
154 assert_equal "ltr", dir
157 assert_equal "rtl", dir
162 assert_equal "rtl", dir
165 assert_equal "ltr", dir
169 def test_friendly_date
170 date = friendly_date(Time.new(2014, 3, 5, 18, 58, 23))
171 assert_match %r{^<span title=" *5 March 2014 at 18:58">.*</span>$}, date
173 date = friendly_date(Time.now - 1.hour)
174 assert_match %r{^<span title=".*">about 1 hour</span>$}, date
176 date = friendly_date(Time.now - 2.days)
177 assert_match %r{^<span title=".*">2 days</span>$}, date
179 date = friendly_date(Time.now - 3.weeks)
180 assert_match %r{^<span title=".*">21 days</span>$}, date
182 date = friendly_date(Time.now - 4.months)
183 assert_match %r{^<span title=".*">4 months</span>$}, date
186 def test_body_class; end
188 def test_current_page_class; end