remove trailing white-spaces excluding here-documents from unit application helper test.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5833 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA 2011-05-18 02:46:50 +00:00
parent c42fdcd26a
commit 944829861d

View File

@ -1,16 +1,16 @@
# Redmine - project management software # Redmine - project management software
# Copyright (C) 2006-2010 Jean-Philippe Lang # Copyright (C) 2006-2011 Jean-Philippe Lang
# #
# This program is free software; you can redistribute it and/or # This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License # modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 # as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. # of the License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
@ -18,9 +18,9 @@
require File.expand_path('../../../test_helper', __FILE__) require File.expand_path('../../../test_helper', __FILE__)
class ApplicationHelperTest < ActionView::TestCase class ApplicationHelperTest < ActionView::TestCase
fixtures :projects, :roles, :enabled_modules, :users, fixtures :projects, :roles, :enabled_modules, :users,
:repositories, :changesets, :repositories, :changesets,
:trackers, :issue_statuses, :issues, :versions, :documents, :trackers, :issue_statuses, :issues, :versions, :documents,
:wikis, :wiki_pages, :wiki_contents, :wikis, :wiki_pages, :wiki_contents,
:boards, :messages, :boards, :messages,
@ -35,11 +35,11 @@ class ApplicationHelperTest < ActionView::TestCase
context "authorized user" do context "authorized user" do
should "be tested" should "be tested"
end end
context "unauthorized user" do context "unauthorized user" do
should "be tested" should "be tested"
end end
should "allow using the :controller and :action for the target link" do should "allow using the :controller and :action for the target link" do
User.current = User.find_by_login('admin') User.current = User.find_by_login('admin')
@ -48,9 +48,9 @@ class ApplicationHelperTest < ActionView::TestCase
{:controller => 'issues', :action => 'edit', :id => Issue.first.id}) {:controller => 'issues', :action => 'edit', :id => Issue.first.id})
assert_match /href/, response assert_match /href/, response
end end
end end
def test_auto_links def test_auto_links
to_test = { to_test = {
'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>', 'http://foo.bar' => '<a class="external" href="http://foo.bar">http://foo.bar</a>',
@ -84,12 +84,12 @@ class ApplicationHelperTest < ActionView::TestCase
} }
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
end end
def test_auto_mailto def test_auto_mailto
assert_equal '<p><a class="email" href="mailto:test@foo.bar">test@foo.bar</a></p>', assert_equal '<p><a class="email" href="mailto:test@foo.bar">test@foo.bar</a></p>',
textilizable('test@foo.bar') textilizable('test@foo.bar')
end end
def test_inline_images def test_inline_images
to_test = { to_test = {
'!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />', '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />',
@ -102,7 +102,7 @@ class ApplicationHelperTest < ActionView::TestCase
} }
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
end end
def test_inline_images_inside_tags def test_inline_images_inside_tags
raw = <<-RAW raw = <<-RAW
h1. !foo.png! Heading h1. !foo.png! Heading
@ -115,7 +115,7 @@ RAW
assert textilizable(raw).include?('<img src="foo.png" alt="" />') assert textilizable(raw).include?('<img src="foo.png" alt="" />')
assert textilizable(raw).include?('<img src="bar.gif" alt="" />') assert textilizable(raw).include?('<img src="bar.gif" alt="" />')
end end
def test_attached_images def test_attached_images
to_test = { to_test = {
'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />', 'Inline image: !logo.gif!' => 'Inline image: <img src="/attachments/download/3" title="This is a logo" alt="This is a logo" />',
@ -128,7 +128,7 @@ RAW
attachments = Attachment.find(:all) attachments = Attachment.find(:all)
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) } to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => attachments) }
end end
def test_textile_external_links def test_textile_external_links
to_test = { to_test = {
'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>', 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>',
@ -149,27 +149,27 @@ RAW
end end
def test_redmine_links def test_redmine_links
issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3}, issue_link = link_to('#3', {:controller => 'issues', :action => 'show', :id => 3},
:class => 'issue status-1 priority-1 overdue', :title => 'Error 281 when updating a recipe (New)') :class => 'issue status-1 priority-1 overdue', :title => 'Error 281 when updating a recipe (New)')
changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1}, changeset_link = link_to('r1', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 1},
:class => 'changeset', :title => 'My very first commit') :class => 'changeset', :title => 'My very first commit')
changeset_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2}, changeset_link2 = link_to('r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
:class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3') :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1}, document_link = link_to('Test document', {:controller => 'documents', :action => 'show', :id => 1},
:class => 'document') :class => 'document')
version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2}, version_link = link_to('1.0', {:controller => 'versions', :action => 'show', :id => 2},
:class => 'version') :class => 'version')
message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4} message_url = {:controller => 'messages', :action => 'show', :board_id => 1, :id => 4}
project_url = {:controller => 'projects', :action => 'show', :id => 'subproject1'} project_url = {:controller => 'projects', :action => 'show', :id => 'subproject1'}
source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']} source_url = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}
source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']} source_url_with_ext = {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file.ext']}
to_test = { to_test = {
# tickets # tickets
'#3, [#3], (#3) and #3.' => "#{issue_link}, [#{issue_link}], (#{issue_link}) and #{issue_link}.", '#3, [#3], (#3) and #3.' => "#{issue_link}, [#{issue_link}], (#{issue_link}) and #{issue_link}.",
@ -224,14 +224,14 @@ RAW
@project = Project.find(1) @project = Project.find(1)
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" } to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text), "#{text} failed" }
end end
def test_cross_project_redmine_links def test_cross_project_redmine_links
source_link = link_to('ecookbook:source:/some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']}, source_link = link_to('ecookbook:source:/some/file', {:controller => 'repositories', :action => 'entry', :id => 'ecookbook', :path => ['some', 'file']},
:class => 'source') :class => 'source')
changeset_link = link_to('ecookbook:r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2}, changeset_link = link_to('ecookbook:r2', {:controller => 'repositories', :action => 'revision', :id => 'ecookbook', :rev => 2},
:class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3') :class => 'changeset', :title => 'This commit fixes #1, #2 and references #1 & #3')
to_test = { to_test = {
# documents # documents
'document:"Test document"' => 'document:"Test document"', 'document:"Test document"' => 'document:"Test document"',
@ -345,7 +345,7 @@ RAW
} }
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => Issue.find(3).attachments), "#{text} failed" } to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text, :attachments => Issue.find(3).attachments), "#{text} failed" }
end end
def test_wiki_links def test_wiki_links
to_test = { to_test = {
'[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>', '[[CookBook documentation]]' => '<a href="/projects/ecookbook/wiki/CookBook_documentation" class="wiki-page">CookBook documentation</a>',
@ -374,7 +374,7 @@ RAW
@project = Project.find(1) @project = Project.find(1)
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
end end
def test_html_tags def test_html_tags
to_test = { to_test = {
"<div>content</div>" => "<p>&lt;div&gt;content&lt;/div&gt;</p>", "<div>content</div>" => "<p>&lt;div&gt;content&lt;/div&gt;</p>",
@ -398,7 +398,7 @@ RAW
} }
to_test.each { |text, result| assert_equal result, textilizable(text) } to_test.each { |text, result| assert_equal result, textilizable(text) }
end end
def test_allowed_html_tags def test_allowed_html_tags
to_test = { to_test = {
"<pre>preformatted text</pre>" => "<pre>preformatted text</pre>", "<pre>preformatted text</pre>" => "<pre>preformatted text</pre>",
@ -407,7 +407,7 @@ RAW
} }
to_test.each { |text, result| assert_equal result, textilizable(text) } to_test.each { |text, result| assert_equal result, textilizable(text) }
end end
def test_pre_tags def test_pre_tags
raw = <<-RAW raw = <<-RAW
Before Before
@ -426,10 +426,10 @@ RAW
</pre> </pre>
<p>After</p> <p>After</p>
EXPECTED EXPECTED
assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
end end
def test_pre_content_should_not_parse_wiki_and_redmine_links def test_pre_content_should_not_parse_wiki_and_redmine_links
raw = <<-RAW raw = <<-RAW
[[CookBook documentation]] [[CookBook documentation]]
@ -452,11 +452,11 @@ RAW
#1 #1
</pre> </pre>
EXPECTED EXPECTED
@project = Project.find(1) @project = Project.find(1)
assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
end end
def test_non_closing_pre_blocks_should_be_closed def test_non_closing_pre_blocks_should_be_closed
raw = <<-RAW raw = <<-RAW
<pre><code> <pre><code>
@ -466,11 +466,11 @@ RAW
<pre><code> <pre><code>
</code></pre> </code></pre>
EXPECTED EXPECTED
@project = Project.find(1) @project = Project.find(1)
assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
end end
def test_syntax_highlight def test_syntax_highlight
raw = <<-RAW raw = <<-RAW
<pre><code class="ruby"> <pre><code class="ruby">
@ -485,7 +485,7 @@ EXPECTED
assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
end end
def test_wiki_links_in_tables def test_wiki_links_in_tables
to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" => to_test = {"|[[Page|Link title]]|[[Other Page|Other title]]|\n|Cell 21|[[Last page]]|" =>
'<tr><td><a href="/projects/ecookbook/wiki/Page" class="wiki-page new">Link title</a></td>' + '<tr><td><a href="/projects/ecookbook/wiki/Page" class="wiki-page new">Link title</a></td>' +
@ -495,7 +495,7 @@ EXPECTED
@project = Project.find(1) @project = Project.find(1)
to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') } to_test.each { |text, result| assert_equal "<table>#{result}</table>", textilizable(text).gsub(/[\t\n]/, '') }
end end
def test_text_formatting def test_text_formatting
to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>', to_test = {'*_+bold, italic and underline+_*' => '<strong><em><ins>bold, italic and underline</ins></em></strong>',
'(_text within parentheses_)' => '(<em>text within parentheses</em>)', '(_text within parentheses_)' => '(<em>text within parentheses</em>)',
@ -505,12 +505,12 @@ EXPECTED
} }
to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) }
end end
def test_wiki_horizontal_rule def test_wiki_horizontal_rule
assert_equal '<hr />', textilizable('---') assert_equal '<hr />', textilizable('---')
assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---') assert_equal '<p>Dashes: ---</p>', textilizable('Dashes: ---')
end end
def test_footnotes def test_footnotes
raw = <<-RAW raw = <<-RAW
This is some text[1]. This is some text[1].
@ -525,14 +525,14 @@ EXPECTED
assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '') assert_equal expected.gsub(%r{[\r\n\t]}, ''), textilizable(raw).gsub(%r{[\r\n\t]}, '')
end end
def test_headings def test_headings
raw = 'h1. Some heading' raw = 'h1. Some heading'
expected = %|<a name="Some-heading"></a>\n<h1 >Some heading<a href="#Some-heading" class="wiki-anchor">&para;</a></h1>| expected = %|<a name="Some-heading"></a>\n<h1 >Some heading<a href="#Some-heading" class="wiki-anchor">&para;</a></h1>|
assert_equal expected, textilizable(raw) assert_equal expected, textilizable(raw)
end end
def test_table_of_content def test_table_of_content
raw = <<-RAW raw = <<-RAW
{{toc}} {{toc}}
@ -566,8 +566,8 @@ RAW
expected = '<ul class="toc">' + expected = '<ul class="toc">' +
'<li><a href="#Title">Title</a>' + '<li><a href="#Title">Title</a>' +
'<ul>' + '<ul>' +
'<li><a href="#Subtitle-with-a-Wiki-link">Subtitle with a Wiki link</a></li>' + '<li><a href="#Subtitle-with-a-Wiki-link">Subtitle with a Wiki link</a></li>' +
'<li><a href="#Subtitle-with-another-Wiki-link">Subtitle with another Wiki link</a></li>' + '<li><a href="#Subtitle-with-another-Wiki-link">Subtitle with another Wiki link</a></li>' +
'<li><a href="#Subtitle-with-red-text">Subtitle with red text</a>' + '<li><a href="#Subtitle-with-red-text">Subtitle with red text</a>' +
'<ul>' + '<ul>' +
'<li><a href="#Subtitle-with-some-modifiers">Subtitle with some modifiers</a></li>' + '<li><a href="#Subtitle-with-some-modifiers">Subtitle with some modifiers</a></li>' +
@ -590,7 +590,7 @@ RAW
@project = Project.find(1) @project = Project.find(1)
assert textilizable(raw).gsub("\n", "").include?(expected), textilizable(raw) assert textilizable(raw).gsub("\n", "").include?(expected), textilizable(raw)
end end
def test_table_of_content_should_contain_included_page_headings def test_table_of_content_should_contain_included_page_headings
raw = <<-RAW raw = <<-RAW
{{toc}} {{toc}}
@ -602,20 +602,20 @@ RAW
expected = '<ul class="toc">' + expected = '<ul class="toc">' +
'<li><a href="#Included">Included</a></li>' + '<li><a href="#Included">Included</a></li>' +
'<li><a href="#Child-page-1">Child page 1</a></li>' + '<li><a href="#Child-page-1">Child page 1</a></li>' +
'</ul>' '</ul>'
@project = Project.find(1) @project = Project.find(1)
assert textilizable(raw).gsub("\n", "").include?(expected) assert textilizable(raw).gsub("\n", "").include?(expected)
end end
def test_default_formatter def test_default_formatter
Setting.text_formatting = 'unknown' Setting.text_formatting = 'unknown'
text = 'a *link*: http://www.example.net/' text = 'a *link*: http://www.example.net/'
assert_equal '<p>a *link*: <a href="http://www.example.net/">http://www.example.net/</a></p>', textilizable(text) assert_equal '<p>a *link*: <a href="http://www.example.net/">http://www.example.net/</a></p>', textilizable(text)
Setting.text_formatting = 'textile' Setting.text_formatting = 'textile'
end end
def test_due_date_distance_in_words def test_due_date_distance_in_words
to_test = { Date.today => 'Due in 0 days', to_test = { Date.today => 'Due in 0 days',
Date.today + 1 => 'Due in 1 day', Date.today + 1 => 'Due in 1 day',
@ -630,7 +630,7 @@ RAW
assert_equal expected, due_date_distance_in_words(date) assert_equal expected, due_date_distance_in_words(date)
end end
end end
def test_avatar def test_avatar
# turn on avatars # turn on avatars
Setting.gravatar_enabled = '1' Setting.gravatar_enabled = '1'
@ -638,25 +638,25 @@ RAW
assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo')) assert avatar('jsmith <jsmith@somenet.foo>').include?(Digest::MD5.hexdigest('jsmith@somenet.foo'))
assert_nil avatar('jsmith') assert_nil avatar('jsmith')
assert_nil avatar(nil) assert_nil avatar(nil)
# turn off avatars # turn off avatars
Setting.gravatar_enabled = '0' Setting.gravatar_enabled = '0'
assert_equal '', avatar(User.find_by_mail('jsmith@somenet.foo')) assert_equal '', avatar(User.find_by_mail('jsmith@somenet.foo'))
end end
def test_link_to_user def test_link_to_user
user = User.find(2) user = User.find(2)
t = link_to_user(user) t = link_to_user(user)
assert_equal "<a href=\"/users/2\">#{ user.name }</a>", t assert_equal "<a href=\"/users/2\">#{ user.name }</a>", t
end end
def test_link_to_user_should_not_link_to_locked_user def test_link_to_user_should_not_link_to_locked_user
user = User.find(5) user = User.find(5)
assert user.locked? assert user.locked?
t = link_to_user(user) t = link_to_user(user)
assert_equal user.name, t assert_equal user.name, t
end end
def test_link_to_user_should_not_link_to_anonymous def test_link_to_user_should_not_link_to_anonymous
user = User.anonymous user = User.anonymous
assert user.anonymous? assert user.anonymous?