##// END OF EJS Templates
Refactor: convert WikiController#destroy to use HTTP DELETE...
Refactor: convert WikiController#destroy to use HTTP DELETE git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4295 e93f8b46-1217-0410-a6f0-8f06a7374b81

File last commit:

r4181:70bf0706b2f7
r4181:70bf0706b2f7
Show More
wiki_controller_test.rb
365 lines | 14.1 KiB | text/x-ruby | RubyLexer
/ test / functional / wiki_controller_test.rb
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 # redMine - project management software
# Copyright (C) 2006-2007 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require File.dirname(__FILE__) + '/../test_helper'
require 'wiki_controller'
# Re-raise errors caught by the controller.
class WikiController; def rescue_action(e) raise e end; end
Eric Davis
Upgraded to Rails 2.3.4 (#3597)...
r2773 class WikiControllerTest < ActionController::TestCase
Jean-Philippe Lang
Allows multiple roles on the same project (#706). Prerequisite for user groups feature....
r2627 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :wikis, :wiki_pages, :wiki_contents, :wiki_content_versions, :attachments
Jean-Philippe Lang
Added some functional tests (wiki)....
r986
def setup
@controller = WikiController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
User.current = nil
end
def test_show_start_page
Eric Davis
Refactor: rename WikiController#index to #show, it's a single resource action...
r4152 get :show, :project_id => 'ecookbook'
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 assert_response :success
assert_template 'show'
assert_tag :tag => 'h1', :content => /CookBook documentation/
Jean-Philippe Lang
Adds child_pages macro for wiki pages (#528)....
r1690
# child_pages macro
assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
:child => { :tag => 'li',
Eric Davis
Converted routing and urls to follow the Rails REST convention....
r2315 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
Jean-Philippe Lang
Adds child_pages macro for wiki pages (#528)....
r1690 :content => 'Page with an inline image' } }
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 end
def test_show_page_with_name
Eric Davis
Refactor: rename WikiController#index to #show, it's a single resource action...
r4152 get :show, :project_id => 1, :page => 'Another_page'
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 assert_response :success
assert_template 'show'
assert_tag :tag => 'h1', :content => /Another page/
Jean-Philippe Lang
Fixed: inline image not displayed when including a wiki page (closes #1001)....
r1312 # Included page with an inline image
assert_tag :tag => 'p', :content => /This is an inline image/
Jean-Philippe Lang
Inline images alt attribute set to the attachment description....
r1313 assert_tag :tag => 'img', :attributes => { :src => '/attachments/download/3',
:alt => 'This is a logo' }
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 end
Jean-Philippe Lang
Makes the wiki sidebar editable (#5208)....
r3518 def test_show_with_sidebar
page = Project.find(1).wiki.pages.new(:title => 'Sidebar')
page.content = WikiContent.new(:text => 'Side bar content for test_show_with_sidebar')
page.save!
Eric Davis
Refactor: rename WikiController#index to #show, it's a single resource action...
r4152 get :show, :project_id => 1, :page => 'Another_page'
Jean-Philippe Lang
Makes the wiki sidebar editable (#5208)....
r3518 assert_response :success
assert_tag :tag => 'div', :attributes => {:id => 'sidebar'},
:content => /Side bar content for test_show_with_sidebar/
end
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 def test_show_unexistent_page_without_edit_right
Eric Davis
Refactor: rename WikiController#index to #show, it's a single resource action...
r4152 get :show, :project_id => 1, :page => 'Unexistent page'
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 assert_response 404
end
def test_show_unexistent_page_with_edit_right
@request.session[:user_id] = 2
Eric Davis
Refactor: rename WikiController#index to #show, it's a single resource action...
r4152 get :show, :project_id => 1, :page => 'Unexistent page'
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 assert_response :success
assert_template 'edit'
end
def test_create_page
@request.session[:user_id] = 2
Eric Davis
Refactor: split WikiController#edit into #update...
r4158 post :update, :project_id => 1,
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 :page => 'New page',
:content => {:comments => 'Created the page',
:text => "h1. New page\n\nThis is a new page",
:version => 0}
Eric Davis
Refactor: rename WikiController#index to #show, it's a single resource action...
r4152 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :page => 'New_page'
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 page = Project.find(1).wiki.find_page('New page')
assert !page.new_record?
assert_not_nil page.content
assert_equal 'Created the page', page.content.comments
end
Jean-Philippe Lang
Adds attachments upload on wiki edit form (#1223)....
r3386 def test_create_page_with_attachments
@request.session[:user_id] = 2
assert_difference 'WikiPage.count' do
assert_difference 'Attachment.count' do
Eric Davis
Refactor: split WikiController#edit into #update...
r4158 post :update, :project_id => 1,
Jean-Philippe Lang
Adds attachments upload on wiki edit form (#1223)....
r3386 :page => 'New page',
:content => {:comments => 'Created the page',
:text => "h1. New page\n\nThis is a new page",
:version => 0},
:attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
end
end
page = Project.find(1).wiki.find_page('New page')
assert_equal 1, page.attachments.count
assert_equal 'testfile.txt', page.attachments.first.filename
end
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 def test_preview
@request.session[:user_id] = 2
Eric Davis
Refactor: change :id on WikiController to use :project_id...
r4151 xhr :post, :preview, :project_id => 1, :page => 'CookBook_documentation',
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 :content => { :comments => '',
:text => 'this is a *previewed text*',
:version => 3 }
assert_response :success
assert_template 'common/_preview'
assert_tag :tag => 'strong', :content => /previewed text/
end
Jean-Philippe Lang
Fixed: error when previewing a new wiki page (#1292) introduced in r1415....
r1431 def test_preview_new_page
@request.session[:user_id] = 2
Eric Davis
Refactor: change :id on WikiController to use :project_id...
r4151 xhr :post, :preview, :project_id => 1, :page => 'New page',
Jean-Philippe Lang
Fixed: error when previewing a new wiki page (#1292) introduced in r1415....
r1431 :content => { :text => 'h1. New page',
:comments => '',
:version => 0 }
assert_response :success
assert_template 'common/_preview'
assert_tag :tag => 'h1', :content => /New page/
end
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 def test_history
Eric Davis
Refactor: change :id on WikiController to use :project_id...
r4151 get :history, :project_id => 1, :page => 'CookBook_documentation'
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 assert_response :success
assert_template 'history'
assert_not_nil assigns(:versions)
assert_equal 3, assigns(:versions).size
Eric Davis
Hiding the View Differences button when a wiki page's history only has one version....
r1748 assert_select "input[type=submit][name=commit]"
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 end
Eric Davis
Hiding the View Differences button when a wiki page's history only has one version....
r1748
def test_history_with_one_version
Eric Davis
Refactor: change :id on WikiController to use :project_id...
r4151 get :history, :project_id => 1, :page => 'Another_page'
Eric Davis
Hiding the View Differences button when a wiki page's history only has one version....
r1748 assert_response :success
assert_template 'history'
assert_not_nil assigns(:versions)
assert_equal 1, assigns(:versions).size
assert_select "input[type=submit][name=commit]", false
end
Eric Davis
Converted routing and urls to follow the Rails REST convention....
r2315
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 def test_diff
Eric Davis
Refactor: change :id on WikiController to use :project_id...
r4151 get :diff, :project_id => 1, :page => 'CookBook_documentation', :version => 2, :version_from => 1
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 assert_response :success
assert_template 'diff'
assert_tag :tag => 'span', :attributes => { :class => 'diff_in'},
:content => /updated/
end
Jean-Philippe Lang
Added wiki annotate view. It's accessible for each version from the page history view. ...
r1007 def test_annotate
Eric Davis
Refactor: change :id on WikiController to use :project_id...
r4151 get :annotate, :project_id => 1, :page => 'CookBook_documentation', :version => 2
Jean-Philippe Lang
Added wiki annotate view. It's accessible for each version from the page history view. ...
r1007 assert_response :success
assert_template 'annotate'
# Line 1
assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '1' },
:child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /John Smith/ },
:child => { :tag => 'td', :content => /h1\. CookBook documentation/ }
# Line 2
assert_tag :tag => 'tr', :child => { :tag => 'th', :attributes => {:class => 'line-num'}, :content => '2' },
:child => { :tag => 'td', :attributes => {:class => 'author'}, :content => /redMine Admin/ },
:child => { :tag => 'td', :content => /Some updated \[\[documentation\]\] here/ }
end
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 def test_rename_with_redirect
@request.session[:user_id] = 2
Eric Davis
Refactor: change :id on WikiController to use :project_id...
r4151 post :rename, :project_id => 1, :page => 'Another_page',
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 :wiki_page => { :title => 'Another renamed page',
:redirect_existing_links => 1 }
Eric Davis
Refactor: rename WikiController#index to #show, it's a single resource action...
r4152 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :page => 'Another_renamed_page'
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 wiki = Project.find(1).wiki
# Check redirects
assert_not_nil wiki.find_page('Another page')
assert_nil wiki.find_page('Another page', :with_redirect => false)
end
def test_rename_without_redirect
@request.session[:user_id] = 2
Eric Davis
Refactor: change :id on WikiController to use :project_id...
r4151 post :rename, :project_id => 1, :page => 'Another_page',
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 :wiki_page => { :title => 'Another renamed page',
:redirect_existing_links => "0" }
Eric Davis
Refactor: rename WikiController#index to #show, it's a single resource action...
r4152 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :page => 'Another_renamed_page'
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 wiki = Project.find(1).wiki
# Check that there's no redirects
assert_nil wiki.find_page('Another page')
end
Jean-Philippe Lang
Ask user what to do with child pages when deleting a parent wiki page (#3202)....
r2584 def test_destroy_child
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 @request.session[:user_id] = 2
Eric Davis
Refactor: convert WikiController#destroy to use HTTP DELETE...
r4181 delete :destroy, :project_id => 1, :page => 'Child_1'
Eric Davis
Refactor: Rename WikiController#page_index to #index...
r4176 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
Eric Davis
Converted routing and urls to follow the Rails REST convention....
r2315 end
Jean-Philippe Lang
Ask user what to do with child pages when deleting a parent wiki page (#3202)....
r2584 def test_destroy_parent
@request.session[:user_id] = 2
assert_no_difference('WikiPage.count') do
Eric Davis
Refactor: convert WikiController#destroy to use HTTP DELETE...
r4181 delete :destroy, :project_id => 1, :page => 'Another_page'
Jean-Philippe Lang
Ask user what to do with child pages when deleting a parent wiki page (#3202)....
r2584 end
assert_response :success
assert_template 'destroy'
end
def test_destroy_parent_with_nullify
@request.session[:user_id] = 2
assert_difference('WikiPage.count', -1) do
Eric Davis
Refactor: convert WikiController#destroy to use HTTP DELETE...
r4181 delete :destroy, :project_id => 1, :page => 'Another_page', :todo => 'nullify'
Jean-Philippe Lang
Ask user what to do with child pages when deleting a parent wiki page (#3202)....
r2584 end
Eric Davis
Refactor: Rename WikiController#page_index to #index...
r4176 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
Jean-Philippe Lang
Ask user what to do with child pages when deleting a parent wiki page (#3202)....
r2584 assert_nil WikiPage.find_by_id(2)
end
def test_destroy_parent_with_cascade
@request.session[:user_id] = 2
assert_difference('WikiPage.count', -3) do
Eric Davis
Refactor: convert WikiController#destroy to use HTTP DELETE...
r4181 delete :destroy, :project_id => 1, :page => 'Another_page', :todo => 'destroy'
Jean-Philippe Lang
Ask user what to do with child pages when deleting a parent wiki page (#3202)....
r2584 end
Eric Davis
Refactor: Rename WikiController#page_index to #index...
r4176 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
Jean-Philippe Lang
Ask user what to do with child pages when deleting a parent wiki page (#3202)....
r2584 assert_nil WikiPage.find_by_id(2)
assert_nil WikiPage.find_by_id(5)
end
def test_destroy_parent_with_reassign
@request.session[:user_id] = 2
assert_difference('WikiPage.count', -1) do
Eric Davis
Refactor: convert WikiController#destroy to use HTTP DELETE...
r4181 delete :destroy, :project_id => 1, :page => 'Another_page', :todo => 'reassign', :reassign_to_id => 1
Jean-Philippe Lang
Ask user what to do with child pages when deleting a parent wiki page (#3202)....
r2584 end
Eric Davis
Refactor: Rename WikiController#page_index to #index...
r4176 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
Jean-Philippe Lang
Ask user what to do with child pages when deleting a parent wiki page (#3202)....
r2584 assert_nil WikiPage.find_by_id(2)
assert_equal WikiPage.find(1), WikiPage.find_by_id(5).parent
end
Eric Davis
Refactor: Rename WikiController#page_index to #index...
r4176 def test_index
get :index, :project_id => 'ecookbook'
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 assert_response :success
Eric Davis
Refactor: Rename WikiController#page_index to #index...
r4176 assert_template 'index'
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 pages = assigns(:pages)
assert_not_nil pages
Jean-Philippe Lang
Fixed: inline image not displayed when including a wiki page (closes #1001)....
r1312 assert_equal Project.find(1).wiki.pages.size, pages.size
Jean-Philippe Lang
Wiki page hierarchy (#528). Parent page can be assigned on Rename screen....
r1689
assert_tag :ul, :attributes => { :class => 'pages-hierarchy' },
Eric Davis
Converted routing and urls to follow the Rails REST convention....
r2315 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/CookBook_documentation' },
Jean-Philippe Lang
Wiki page hierarchy (#528). Parent page can be assigned on Rename screen....
r1689 :content => 'CookBook documentation' },
:child => { :tag => 'ul',
:child => { :tag => 'li',
Eric Davis
Converted routing and urls to follow the Rails REST convention....
r2315 :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Page_with_an_inline_image' },
Jean-Philippe Lang
Wiki page hierarchy (#528). Parent page can be assigned on Rename screen....
r1689 :content => 'Page with an inline image' } } } },
Eric Davis
Converted routing and urls to follow the Rails REST convention....
r2315 :child => { :tag => 'li', :child => { :tag => 'a', :attributes => { :href => '/projects/ecookbook/wiki/Another_page' },
Jean-Philippe Lang
Wiki page hierarchy (#528). Parent page can be assigned on Rename screen....
r1689 :content => 'Another page' } }
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 end
Eric Davis
Refactor: extract method in WikiController#special to create a new #export method...
r4137
context "GET :export" do
context "with an authorized user to export the wiki" do
setup do
@request.session[:user_id] = 2
Eric Davis
Refactor: change :id on WikiController to use :project_id...
r4151 get :export, :project_id => 'ecookbook'
Eric Davis
Refactor: extract method in WikiController#special to create a new #export method...
r4137 end
should_respond_with :success
should_assign_to :pages
should_respond_with_content_type "text/html"
should "export all of the wiki pages to a single html file" do
assert_select "a[name=?]", "CookBook_documentation"
assert_select "a[name=?]", "Another_page"
assert_select "a[name=?]", "Page_with_an_inline_image"
end
end
context "with an unauthorized user" do
setup do
Eric Davis
Refactor: change :id on WikiController to use :project_id...
r4151 get :export, :project_id => 'ecookbook'
Eric Davis
Refactor: extract method in WikiController#special to create a new #export method...
r4137
should_respond_with :redirect
Eric Davis
Refactor: rename WikiController#index to #show, it's a single resource action...
r4152 should_redirect_to('wiki index') { {:action => 'show', :project_id => @project, :page => nil} }
Eric Davis
Refactor: extract method in WikiController#special to create a new #export method...
r4137 end
end
end
Eric Davis
Refactor: extract method from WikiController#special...
r4147
context "GET :date_index" do
setup do
Eric Davis
Refactor: change :id on WikiController to use :project_id...
r4151 get :date_index, :project_id => 'ecookbook'
Eric Davis
Refactor: extract method from WikiController#special...
r4147 end
should_respond_with :success
should_assign_to :pages
should_assign_to :pages_by_date
should_render_template 'wiki/date_index'
end
Jean-Philippe Lang
Added some functional tests (wiki)....
r986
def test_not_found
Eric Davis
Refactor: rename WikiController#index to #show, it's a single resource action...
r4152 get :show, :project_id => 999
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 assert_response 404
end
Jean-Philippe Lang
Wiki page protection (#851, patch #1146 by Mateo Murphy with slight changes)....
r1400
def test_protect_page
page = WikiPage.find_by_wiki_id_and_title(1, 'Another_page')
assert !page.protected?
@request.session[:user_id] = 2
Eric Davis
Refactor: change :id on WikiController to use :project_id...
r4151 post :protect, :project_id => 1, :page => page.title, :protected => '1'
Eric Davis
Refactor: rename WikiController#index to #show, it's a single resource action...
r4152 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :page => 'Another_page'
Jean-Philippe Lang
Wiki page protection (#851, patch #1146 by Mateo Murphy with slight changes)....
r1400 assert page.reload.protected?
end
def test_unprotect_page
page = WikiPage.find_by_wiki_id_and_title(1, 'CookBook_documentation')
assert page.protected?
@request.session[:user_id] = 2
Eric Davis
Refactor: change :id on WikiController to use :project_id...
r4151 post :protect, :project_id => 1, :page => page.title, :protected => '0'
Eric Davis
Refactor: rename WikiController#index to #show, it's a single resource action...
r4152 assert_redirected_to :action => 'show', :project_id => 'ecookbook', :page => 'CookBook_documentation'
Jean-Philippe Lang
Wiki page protection (#851, patch #1146 by Mateo Murphy with slight changes)....
r1400 assert !page.reload.protected?
end
def test_show_page_with_edit_link
@request.session[:user_id] = 2
Eric Davis
Refactor: rename WikiController#index to #show, it's a single resource action...
r4152 get :show, :project_id => 1
Jean-Philippe Lang
Wiki page protection (#851, patch #1146 by Mateo Murphy with slight changes)....
r1400 assert_response :success
assert_template 'show'
Eric Davis
Converted routing and urls to follow the Rails REST convention....
r2315 assert_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
Jean-Philippe Lang
Wiki page protection (#851, patch #1146 by Mateo Murphy with slight changes)....
r1400 end
def test_show_page_without_edit_link
@request.session[:user_id] = 4
Eric Davis
Refactor: rename WikiController#index to #show, it's a single resource action...
r4152 get :show, :project_id => 1
Jean-Philippe Lang
Wiki page protection (#851, patch #1146 by Mateo Murphy with slight changes)....
r1400 assert_response :success
assert_template 'show'
Eric Davis
Converted routing and urls to follow the Rails REST convention....
r2315 assert_no_tag :tag => 'a', :attributes => { :href => '/projects/1/wiki/CookBook_documentation/edit' }
Jean-Philippe Lang
Wiki page protection (#851, patch #1146 by Mateo Murphy with slight changes)....
r1400 end
def test_edit_unprotected_page
# Non members can edit unprotected wiki pages
@request.session[:user_id] = 4
Eric Davis
Refactor: change :id on WikiController to use :project_id...
r4151 get :edit, :project_id => 1, :page => 'Another_page'
Jean-Philippe Lang
Wiki page protection (#851, patch #1146 by Mateo Murphy with slight changes)....
r1400 assert_response :success
assert_template 'edit'
end
def test_edit_protected_page_by_nonmember
# Non members can't edit protected wiki pages
@request.session[:user_id] = 4
Eric Davis
Refactor: change :id on WikiController to use :project_id...
r4151 get :edit, :project_id => 1, :page => 'CookBook_documentation'
Jean-Philippe Lang
Wiki page protection (#851, patch #1146 by Mateo Murphy with slight changes)....
r1400 assert_response 403
end
def test_edit_protected_page_by_member
@request.session[:user_id] = 2
Eric Davis
Refactor: change :id on WikiController to use :project_id...
r4151 get :edit, :project_id => 1, :page => 'CookBook_documentation'
Jean-Philippe Lang
Wiki page protection (#851, patch #1146 by Mateo Murphy with slight changes)....
r1400 assert_response :success
assert_template 'edit'
end
Jean-Philippe Lang
Check that wiki page exists before processing (#2360)....
r2143
def test_history_of_non_existing_page_should_return_404
Eric Davis
Refactor: change :id on WikiController to use :project_id...
r4151 get :history, :project_id => 1, :page => 'Unknown_page'
Jean-Philippe Lang
Check that wiki page exists before processing (#2360)....
r2143 assert_response 404
end
Jean-Philippe Lang
Added some functional tests (wiki)....
r986 end