summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/wiki_controller_test.rb33
-rw-r--r--test/unit/wiki_page_test.rb20
-rw-r--r--test/unit/wiki_redirect_test.rb37
-rw-r--r--test/unit/wiki_test.rb14
4 files changed, 97 insertions, 7 deletions
diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb
index d16a1559c..ebebf343d 100644
--- a/test/functional/wiki_controller_test.rb
+++ b/test/functional/wiki_controller_test.rb
@@ -660,6 +660,39 @@ class WikiControllerTest < ActionController::TestCase
assert_nil WikiPage.find_by_title('Child_1').parent
end
+ def test_get_rename_should_show_target_projects_list
+ @request.session[:user_id] = 2
+ project = Project.find(5)
+ project.enable_module! :wiki
+
+ get :rename, :project_id => 1, :id => 'Another_page'
+ assert_response :success
+ assert_template 'rename'
+
+ assert_select 'select[name=?]', 'wiki_page[wiki_id]' do
+ assert_select 'option', 2
+ assert_select 'option[value=?][selected=selected]', '1', :text => /eCookbook/
+ assert_select 'option[value=?]', project.wiki.id.to_s, :text => /#{project.name}/
+ end
+ end
+
+ def test_rename_with_move
+ @request.session[:user_id] = 2
+ project = Project.find(5)
+ project.enable_module! :wiki
+
+ post :rename, :project_id => 1, :id => 'Another_page',
+ :wiki_page => {
+ :wiki_id => project.wiki.id.to_s,
+ :title => 'Another renamed page',
+ :redirect_existing_links => 1
+ }
+ assert_redirected_to '/projects/private-child/wiki/Another_renamed_page'
+
+ page = WikiPage.find(2)
+ assert_equal project.wiki.id, page.wiki_id
+ end
+
def test_destroy_a_page_without_children_should_not_ask_confirmation
@request.session[:user_id] = 2
delete :destroy, :project_id => 1, :id => 'Child_2'
diff --git a/test/unit/wiki_page_test.rb b/test/unit/wiki_page_test.rb
index a8c56678d..d3453583c 100644
--- a/test/unit/wiki_page_test.rb
+++ b/test/unit/wiki_page_test.rb
@@ -101,6 +101,26 @@ class WikiPageTest < ActiveSupport::TestCase
assert page.save
end
+ def test_move_child_should_clear_parent
+ parent = WikiPage.create!(:wiki_id => 1, :title => 'Parent')
+ child = WikiPage.create!(:wiki_id => 1, :title => 'Child', :parent => parent)
+
+ child.wiki_id = 2
+ child.save!
+ assert_equal nil, child.reload.parent_id
+ end
+
+ def test_move_parent_should_move_child_page
+ parent = WikiPage.create!(:wiki_id => 1, :title => 'Parent')
+ child = WikiPage.create!(:wiki_id => 1, :title => 'Child', :parent => parent)
+ parent.reload
+
+ parent.wiki_id = 2
+ parent.save!
+ assert_equal 2, child.reload.wiki_id
+ assert_equal parent, child.parent
+ end
+
def test_destroy
page = WikiPage.find(1)
page.destroy
diff --git a/test/unit/wiki_redirect_test.rb b/test/unit/wiki_redirect_test.rb
index 3873da600..f8fffbbd7 100644
--- a/test/unit/wiki_redirect_test.rb
+++ b/test/unit/wiki_redirect_test.rb
@@ -25,15 +25,38 @@ class WikiRedirectTest < ActiveSupport::TestCase
@original = WikiPage.create(:wiki => @wiki, :title => 'Original title')
end
- def test_create_redirect
+ def test_create_redirect_on_rename
@original.title = 'New title'
- assert @original.save
- @original.reload
+ @original.save!
- assert_equal 'New_title', @original.title
- assert @wiki.redirects.find_by_title('Original_title')
- assert @wiki.find_page('Original title')
- assert @wiki.find_page('ORIGINAL title')
+ redirect = @wiki.redirects.find_by_title('Original_title')
+ assert_not_nil redirect
+ assert_equal 1, redirect.redirects_to_wiki_id
+ assert_equal 'New_title', redirect.redirects_to
+ assert_equal @original, redirect.target_page
+ end
+
+ def test_create_redirect_on_move
+ @original.wiki_id = 2
+ @original.save!
+
+ redirect = @wiki.redirects.find_by_title('Original_title')
+ assert_not_nil redirect
+ assert_equal 2, redirect.redirects_to_wiki_id
+ assert_equal 'Original_title', redirect.redirects_to
+ assert_equal @original, redirect.target_page
+ end
+
+ def test_create_redirect_on_rename_and_move
+ @original.title = 'New title'
+ @original.wiki_id = 2
+ @original.save!
+
+ redirect = @wiki.redirects.find_by_title('Original_title')
+ assert_not_nil redirect
+ assert_equal 2, redirect.redirects_to_wiki_id
+ assert_equal 'New_title', redirect.redirects_to
+ assert_equal @original, redirect.target_page
end
def test_update_redirect
diff --git a/test/unit/wiki_test.rb b/test/unit/wiki_test.rb
index a852b2393..22573221b 100644
--- a/test/unit/wiki_test.rb
+++ b/test/unit/wiki_test.rb
@@ -97,4 +97,18 @@ class WikiTest < ActiveSupport::TestCase
assert_kind_of WikiPage, @wiki.sidebar
assert_equal 'Sidebar', @wiki.sidebar.title
end
+
+ def test_destroy_should_remove_redirects_from_the_wiki
+ WikiRedirect.create!(:wiki_id => 1, :title => 'Foo', :redirects_to_wiki_id => 2, :redirects_to => 'Bar')
+
+ Wiki.find(1).destroy
+ assert_equal 0, WikiRedirect.where(:wiki_id => 1).count
+ end
+
+ def test_destroy_should_remove_redirects_to_the_wiki
+ WikiRedirect.create!(:wiki_id => 2, :title => 'Foo', :redirects_to_wiki_id => 1, :redirects_to => 'Bar')
+
+ Wiki.find(1).destroy
+ assert_equal 0, WikiRedirect.where(:redirects_to_wiki_id => 1).count
+ end
end