Chris@1296: # Redmine - project management software Chris@1296: # Copyright (C) 2006-2012 Jean-Philippe Lang Chris@1296: # Chris@1296: # This program is free software; you can redistribute it and/or Chris@1296: # modify it under the terms of the GNU General Public License Chris@1296: # as published by the Free Software Foundation; either version 2 Chris@1296: # of the License, or (at your option) any later version. Chris@1296: # Chris@1296: # This program is distributed in the hope that it will be useful, Chris@1296: # but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@1296: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@1296: # GNU General Public License for more details. Chris@1296: # Chris@1296: # You should have received a copy of the GNU General Public License Chris@1296: # along with this program; if not, write to the Free Software Chris@1296: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Chris@1296: Chris@1296: require File.expand_path('../../test_helper', __FILE__) Chris@1296: require 'wikis_controller' Chris@1296: Chris@1296: # Re-raise errors caught by the controller. Chris@1296: class WikisController; def rescue_action(e) raise e end; end Chris@1296: Chris@1296: class WikisControllerTest < ActionController::TestCase Chris@1296: fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, :wikis Chris@1296: Chris@1296: def setup Chris@1296: @controller = WikisController.new Chris@1296: @request = ActionController::TestRequest.new Chris@1296: @response = ActionController::TestResponse.new Chris@1296: User.current = nil Chris@1296: end Chris@1296: Chris@1296: def test_create Chris@1296: @request.session[:user_id] = 1 Chris@1296: assert_nil Project.find(3).wiki Chris@1296: Chris@1296: assert_difference 'Wiki.count' do Chris@1296: xhr :post, :edit, :id => 3, :wiki => { :start_page => 'Start page' } Chris@1296: assert_response :success Chris@1296: assert_template 'edit' Chris@1296: assert_equal 'text/javascript', response.content_type Chris@1296: end Chris@1296: Chris@1296: wiki = Project.find(3).wiki Chris@1296: assert_not_nil wiki Chris@1296: assert_equal 'Start page', wiki.start_page Chris@1296: end Chris@1296: Chris@1296: def test_create_with_failure Chris@1296: @request.session[:user_id] = 1 Chris@1296: Chris@1296: assert_no_difference 'Wiki.count' do Chris@1296: xhr :post, :edit, :id => 3, :wiki => { :start_page => '' } Chris@1296: assert_response :success Chris@1296: assert_template 'edit' Chris@1296: assert_equal 'text/javascript', response.content_type Chris@1296: end Chris@1296: Chris@1296: assert_include 'errorExplanation', response.body Chris@1296: assert_include 'Start page can't be blank', response.body Chris@1296: end Chris@1296: Chris@1296: def test_update Chris@1296: @request.session[:user_id] = 1 Chris@1296: Chris@1296: assert_no_difference 'Wiki.count' do Chris@1296: xhr :post, :edit, :id => 1, :wiki => { :start_page => 'Other start page' } Chris@1296: assert_response :success Chris@1296: assert_template 'edit' Chris@1296: assert_equal 'text/javascript', response.content_type Chris@1296: end Chris@1296: Chris@1296: wiki = Project.find(1).wiki Chris@1296: assert_equal 'Other start page', wiki.start_page Chris@1296: end Chris@1296: Chris@1296: def test_destroy Chris@1296: @request.session[:user_id] = 1 Chris@1296: post :destroy, :id => 1, :confirm => 1 Chris@1296: assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'ecookbook', :tab => 'wiki' Chris@1296: assert_nil Project.find(1).wiki Chris@1296: end Chris@1296: Chris@1296: def test_not_found Chris@1296: @request.session[:user_id] = 1 Chris@1296: post :destroy, :id => 999, :confirm => 1 Chris@1296: assert_response 404 Chris@1296: end Chris@1296: end