##// END OF EJS Templates
Adds some functional tests....
Jean-Philippe Lang -
r2479:3227b327637f
parent child
Show More
@@ -0,0 +1,78
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'issue_categories_controller'
20
21 # Re-raise errors caught by the controller.
22 class IssueCategoriesController; def rescue_action(e) raise e end; end
23
24 class IssueCategoriesControllerTest < Test::Unit::TestCase
25 fixtures :projects, :users, :members, :roles, :enabled_modules, :issue_categories
26
27 def setup
28 @controller = IssueCategoriesController.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
32 @request.session[:user_id] = 2
33 end
34
35 def test_post_edit
36 assert_no_difference 'IssueCategory.count' do
37 post :edit, :id => 2, :category => { :name => 'Testing' }
38 end
39 assert_redirected_to '/projects/ecookbook/settings/categories'
40 assert_equal 'Testing', IssueCategory.find(2).name
41 end
42
43 def test_edit_not_found
44 post :edit, :id => 97, :category => { :name => 'Testing' }
45 assert_response 404
46 end
47
48 def test_destroy_category_not_in_use
49 post :destroy, :id => 2
50 assert_redirected_to '/projects/ecookbook/settings/categories'
51 assert_nil IssueCategory.find_by_id(2)
52 end
53
54 def test_destroy_category_in_use
55 post :destroy, :id => 1
56 assert_response :success
57 assert_template 'destroy'
58 assert_not_nil IssueCategory.find_by_id(1)
59 end
60
61 def test_destroy_category_in_use_with_reassignment
62 issue = Issue.find(:first, :conditions => {:category_id => 1})
63 post :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2
64 assert_redirected_to '/projects/ecookbook/settings/categories'
65 assert_nil IssueCategory.find_by_id(1)
66 # check that the issue was reassign
67 assert_equal 2, issue.reload.category_id
68 end
69
70 def test_destroy_category_in_use_without_reassignment
71 issue = Issue.find(:first, :conditions => {:category_id => 1})
72 post :destroy, :id => 1, :todo => 'nullify'
73 assert_redirected_to '/projects/ecookbook/settings/categories'
74 assert_nil IssueCategory.find_by_id(1)
75 # check that the issue category was nullified
76 assert_nil issue.reload.category_id
77 end
78 end
@@ -1,5 +1,5
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
@@ -46,6 +46,20 class BoardsControllerTest < Test::Unit::TestCase
46 46 assert_not_nil assigns(:project)
47 47 end
48 48
49 def test_index_not_found
50 get :index, :project_id => 97
51 assert_response 404
52 end
53
54 def test_index_should_show_messages_if_only_one_board
55 Project.find(1).boards.slice(1..-1).each(&:destroy)
56
57 get :index, :project_id => 1
58 assert_response :success
59 assert_template 'show'
60 assert_not_nil assigns(:topics)
61 end
62
49 63 def test_new_routing
50 64 assert_routing(
51 65 {:method => :get, :path => '/projects/world_domination/boards/new'},
@@ -57,6 +71,14 class BoardsControllerTest < Test::Unit::TestCase
57 71 )
58 72 end
59 73
74 def test_post_new
75 @request.session[:user_id] = 2
76 assert_difference 'Board.count' do
77 post :new, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
78 end
79 assert_redirected_to '/projects/ecookbook/settings/boards'
80 end
81
60 82 def test_show_routing
61 83 assert_routing(
62 84 {:method => :get, :path => '/projects/world_domination/boards/44'},
@@ -84,10 +106,28 class BoardsControllerTest < Test::Unit::TestCase
84 106 )
85 107 end
86 108
109 def test_post_edit
110 @request.session[:user_id] = 2
111 assert_no_difference 'Board.count' do
112 post :edit, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'}
113 end
114 assert_redirected_to '/projects/ecookbook/settings/boards'
115 assert_equal 'Testing', Board.find(2).name
116 end
117
87 118 def test_destroy_routing
88 119 assert_routing(#TODO: use DELETE method to board_path, modify form accoringly
89 120 {:method => :post, :path => '/projects/world_domination/boards/44/destroy'},
90 121 :controller => 'boards', :action => 'destroy', :id => '44', :project_id => 'world_domination'
91 122 )
92 123 end
124
125 def test_post_destroy
126 @request.session[:user_id] = 2
127 assert_difference 'Board.count', -1 do
128 post :destroy, :project_id => 1, :id => 2
129 end
130 assert_redirected_to '/projects/ecookbook/settings/boards'
131 assert_nil Board.find_by_id(2)
132 end
93 133 end
General Comments 0
You need to be logged in to leave comments. Login now