refactored application_helper test to be more robust with wiki pages

pull/1186/head
Philipp Tessenow 12 years ago
parent 86df804f7d
commit 66139c2f95
  1. 49
      test/unit/helpers/application_helper_test.rb

@ -18,6 +18,7 @@ class ApplicationHelperTest < ActionView::TestCase
super super
# @project variable is used by helper # @project variable is used by helper
@project = FactoryGirl.create :valid_project @project = FactoryGirl.create :valid_project
@project.reload # reload references to indirectly created entities (e.g. wiki)
@admin = FactoryGirl.create :admin @admin = FactoryGirl.create :admin
@anonymous = FactoryGirl.create :anonymous @anonymous = FactoryGirl.create :anonymous
@ -386,15 +387,16 @@ RAW
def test_wiki_links def test_wiki_links
User.current = @admin User.current = @admin
wiki = FactoryGirl.create :wiki, :project => @project, :start_page => "CookBook documentation" @project.wiki.start_page = "CookBook documentation"
FactoryGirl.create :wiki_page_with_content, :wiki => wiki, :title => "CookBook_documentation" @project.wiki.save!
FactoryGirl.create :wiki_page_with_content, :wiki => wiki, :title => "Another page" FactoryGirl.create :wiki_page_with_content, :wiki => @project.wiki, :title => "CookBook_documentation"
@project.reload FactoryGirl.create :wiki_page_with_content, :wiki => @project.wiki, :title => "Another page"
project2 = FactoryGirl.create :valid_project, :identifier => 'onlinestore' project2 = FactoryGirl.create :valid_project, :identifier => 'onlinestore'
wiki2 = FactoryGirl.create :wiki, :project => project2, :start_page => "Start page" project2.reload # reload indirectly created references (esp. the wiki)
FactoryGirl.create :wiki_page_with_content, :wiki => wiki2, :title => "Start_page" project2.wiki.start_page = "Start page"
@project.reload project2.wiki.save!
FactoryGirl.create :wiki_page_with_content, :wiki => project2.wiki, :title => "Start_page"
to_test = { to_test = {
'[[CookBook documentation]]' => "<a href=\"/projects/#{@project.identifier}/wiki/CookBook_documentation\" class=\"wiki-page\">CookBook documentation</a>", '[[CookBook documentation]]' => "<a href=\"/projects/#{@project.identifier}/wiki/CookBook_documentation\" class=\"wiki-page\">CookBook documentation</a>",
@ -480,9 +482,9 @@ EXPECTED
end end
def test_pre_content_should_not_parse_wiki_and_redmine_links def test_pre_content_should_not_parse_wiki_and_redmine_links
wiki = FactoryGirl.create :wiki, :project => @project, :start_page => "CookBook documentation" @project.wiki.start_page = "CookBook documentation"
FactoryGirl.create :wiki_page_with_content, :wiki => wiki, :title => "CookBook_documentation" @project.wiki.save!
@project.reload FactoryGirl.create :wiki_page_with_content, :wiki => @project.wiki, :title => "CookBook_documentation"
raw = <<-RAW raw = <<-RAW
[[CookBook documentation]] [[CookBook documentation]]
@ -538,10 +540,10 @@ EXPECTED
end end
def test_wiki_links_in_tables def test_wiki_links_in_tables
wiki = FactoryGirl.create :wiki, :project => @project, :start_page => "Page" @project.wiki.start_page = "Page"
FactoryGirl.create :wiki_page_with_content, :wiki => wiki, :title => "Other page" @project.wiki.save!
FactoryGirl.create :wiki_page_with_content, :wiki => wiki, :title => "Last page" FactoryGirl.create :wiki_page_with_content, :wiki => @project.wiki, :title => "Other page"
@project.reload FactoryGirl.create :wiki_page_with_content, :wiki => @project.wiki, :title => "Last page"
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/#{@project.identifier}/wiki/Page\" class=\"wiki-page new\">Link title</a></td>" + "<tr><td><a href=\"/projects/#{@project.identifier}/wiki/Page\" class=\"wiki-page new\">Link title</a></td>" +
@ -590,10 +592,10 @@ EXPECTED
end end
def test_table_of_content def test_table_of_content
wiki = FactoryGirl.create :wiki, :project => @project, :start_page => "Wiki" @project.wiki.start_page = "Wiki"
FactoryGirl.create :wiki_page_with_content, :wiki => wiki, :title => "Wiki" @project.wiki.save!
FactoryGirl.create :wiki_page_with_content, :wiki => wiki, :title => "another Wiki" FactoryGirl.create :wiki_page_with_content, :wiki => @project.wiki, :title => "Wiki"
@project.reload FactoryGirl.create :wiki_page_with_content, :wiki => @project.wiki, :title => "another Wiki"
raw = <<-RAW raw = <<-RAW
{{toc}} {{toc}}
@ -652,13 +654,12 @@ RAW
end end
def test_table_of_content_should_contain_included_page_headings def test_table_of_content_should_contain_included_page_headings
wiki = FactoryGirl.create :wiki, :project => @project, :start_page => "Wiki" @project.wiki.start_page = "Wiki"
page = FactoryGirl.create :wiki_page_with_content, :wiki => wiki, :title => "Wiki" @project.save!
child = FactoryGirl.create :wiki_page, :wiki => wiki, :title => "Child_1", :parent => page page = FactoryGirl.create :wiki_page_with_content, :wiki => @project.wiki, :title => "Wiki"
child = FactoryGirl.create :wiki_page, :wiki => @project.wiki, :title => "Child_1", :parent => page
child.content = FactoryGirl.create :wiki_content, :page => child, :text => "h1. Child page 1\n\nThis is a child page" child.content = FactoryGirl.create :wiki_content, :page => child, :text => "h1. Child page 1\n\nThis is a child page"
assert child.save child.save!
@project.wiki = wiki;
assert @project.save
raw = <<-RAW raw = <<-RAW
{{toc}} {{toc}}

Loading…
Cancel
Save