3 class ApplicationHelperTest < ActionView::TestCase
4 fixtures :users, :user_roles
11 %w(http://example.com/test ftp://example.com/test https://example.com/test).each do |link|
12 text = "Test #{link} is made into a link"
15 assert_equal false, html.html_safe?
16 assert_equal "Test <a href=\"#{link}\" rel=\"nofollow\">#{link}</a> is made into a link", html
18 html = linkify(text.html_safe)
19 assert_equal true, html.html_safe?
20 assert_equal "Test <a href=\"#{link}\" rel=\"nofollow\">#{link}</a> is made into a link", html
23 %w(test@example.com mailto:test@example.com).each do |link|
24 text = "Test #{link} is not made into a link"
27 assert_equal false, html.html_safe?
28 assert_equal text, html
30 html = linkify(text.html_safe)
31 assert_equal true, html.html_safe?
32 assert_equal text, html
37 link = rss_link_to(:controller => :diary_entry, :action => :rss)
38 assert_equal "<a class=\"rsssmall\" href=\"/diary/rss\"><img alt=\"Rss\" border=\"0\" height=\"16\" src=\"/images/RSS.png\" width=\"16\" /></a>", link
42 link = atom_link_to(:controller => :changeset, :action => :feed)
43 assert_equal "<a class=\"rsssmall\" href=\"/history/feed\"><img alt=\"Rss\" border=\"0\" height=\"16\" src=\"/images/RSS.png\" width=\"16\" /></a>", link
50 assert_match /\.hidden /, css
51 assert_match /\.hide_unless_logged_in /, css
52 assert_no_match /\.hide_if_logged_in /, css
53 assert_no_match /\.hide_if_user_/, css
54 assert_no_match /\.show_if_user_/, css
55 assert_match /\.hide_unless_administrator /, css
56 assert_match /\.hide_unless_moderator /, css
58 @user = users(:normal_user)
61 assert_match /\.hidden /, css
62 assert_no_match /\.hide_unless_logged_in /, css
63 assert_match /\.hide_if_logged_in /, css
64 assert_match /\.hide_if_user_1 /, css
65 assert_match /\.show_if_user_1 /, css
66 assert_match /\.hide_unless_administrator /, css
67 assert_match /\.hide_unless_moderator /, css
69 @user = users(:moderator_user)
72 assert_match /\.hidden /, css
73 assert_no_match /\.hide_unless_logged_in /, css
74 assert_match /\.hide_if_logged_in /, css
75 assert_match /\.hide_if_user_5 /, css
76 assert_match /\.show_if_user_5 /, css
77 assert_match /\.hide_unless_administrator /, css
78 assert_no_match /\.hide_unless_moderator /, css
80 @user = users(:administrator_user)
83 assert_match /\.hidden /, css
84 assert_no_match /\.hide_unless_logged_in /, css
85 assert_match /\.hide_if_logged_in /, css
86 assert_match /\.hide_if_user_6 /, css
87 assert_match /\.show_if_user_6 /, css
88 assert_no_match /\.hide_unless_administrator /, css
89 assert_match /\.hide_unless_moderator /, css
93 html = if_logged_in { "Test 1" }
94 assert_equal "<div class=\"hide_unless_logged_in\">Test 1</div>", html
96 html = if_logged_in(:span) { "Test 2" }
97 assert_equal "<span class=\"hide_unless_logged_in\">Test 2</span>", html
100 def test_if_not_logged_in
101 html = if_not_logged_in { "Test 1" }
102 assert_equal "<div class=\"hide_if_logged_in\">Test 1</div>", html
104 html = if_not_logged_in(:span) { "Test 2" }
105 assert_equal "<span class=\"hide_if_logged_in\">Test 2</span>", html
109 html = if_user(users(:normal_user)) { "Test 1" }
110 assert_equal "<div class=\"hidden show_if_user_1\">Test 1</div>", html
112 html = if_user(users(:normal_user), :span) { "Test 2" }
113 assert_equal "<span class=\"hidden show_if_user_1\">Test 2</span>", html
115 html = if_user(nil) { "Test 3" }
118 html = if_user(nil, :span) { "Test 4" }
123 html = unless_user(users(:normal_user)) { "Test 1" }
124 assert_equal "<div class=\"hide_if_user_1\">Test 1</div>", html
126 html = unless_user(users(:normal_user), :span) { "Test 2" }
127 assert_equal "<span class=\"hide_if_user_1\">Test 2</span>", html
129 html = unless_user(nil) { "Test 3" }
130 assert_equal "<div>Test 3</div>", html
132 html = unless_user(nil, :span) { "Test 4" }
133 assert_equal "<span>Test 4</span>", html
136 def test_if_administrator
137 html = if_administrator { "Test 1" }
138 assert_equal "<div class=\"hide_unless_administrator\">Test 1</div>", html
140 html = if_administrator(:span) { "Test 2" }
141 assert_equal "<span class=\"hide_unless_administrator\">Test 2</span>", html
144 def test_richtext_area
145 html = richtext_area(:message, :body, :cols => 40, :rows => 20)
150 assert_equal "ltr", dir
153 assert_equal "rtl", dir
158 assert_equal "rtl", dir
161 assert_equal "ltr", dir
165 def test_friendly_date
166 date = friendly_date(Time.new(2014, 3, 5, 18, 58, 23))
167 assert_match /^<span title=" *5 March 2014 at 18:58">.*<\/span>$/, date
169 date = friendly_date(Time.now - 1.hour)
170 assert_match /^<span title=".*">about 1 hour<\/span>$/, date
172 date = friendly_date(Time.now - 2.days)
173 assert_match /^<span title=".*">2 days<\/span>$/, date
175 date = friendly_date(Time.now - 3.weeks)
176 assert_match /^<span title=".*">21 days<\/span>$/, date
178 date = friendly_date(Time.now - 4.months)
179 assert_match /^<span title=".*">4 months<\/span>$/, date
185 def test_current_page_class