##// 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,93 +1,133
1 # redMine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'boards_controller'
19 require 'boards_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class BoardsController; def rescue_action(e) raise e end; end
22 class BoardsController; def rescue_action(e) raise e end; end
23
23
24 class BoardsControllerTest < Test::Unit::TestCase
24 class BoardsControllerTest < Test::Unit::TestCase
25 fixtures :projects, :users, :members, :roles, :boards, :messages, :enabled_modules
25 fixtures :projects, :users, :members, :roles, :boards, :messages, :enabled_modules
26
26
27 def setup
27 def setup
28 @controller = BoardsController.new
28 @controller = BoardsController.new
29 @request = ActionController::TestRequest.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
31 User.current = nil
32 end
32 end
33
33
34 def test_index_routing
34 def test_index_routing
35 assert_routing(
35 assert_routing(
36 {:method => :get, :path => '/projects/world_domination/boards'},
36 {:method => :get, :path => '/projects/world_domination/boards'},
37 :controller => 'boards', :action => 'index', :project_id => 'world_domination'
37 :controller => 'boards', :action => 'index', :project_id => 'world_domination'
38 )
38 )
39 end
39 end
40
40
41 def test_index
41 def test_index
42 get :index, :project_id => 1
42 get :index, :project_id => 1
43 assert_response :success
43 assert_response :success
44 assert_template 'index'
44 assert_template 'index'
45 assert_not_nil assigns(:boards)
45 assert_not_nil assigns(:boards)
46 assert_not_nil assigns(:project)
46 assert_not_nil assigns(:project)
47 end
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 def test_new_routing
63 def test_new_routing
50 assert_routing(
64 assert_routing(
51 {:method => :get, :path => '/projects/world_domination/boards/new'},
65 {:method => :get, :path => '/projects/world_domination/boards/new'},
52 :controller => 'boards', :action => 'new', :project_id => 'world_domination'
66 :controller => 'boards', :action => 'new', :project_id => 'world_domination'
53 )
67 )
54 assert_recognizes(
68 assert_recognizes(
55 {:controller => 'boards', :action => 'new', :project_id => 'world_domination'},
69 {:controller => 'boards', :action => 'new', :project_id => 'world_domination'},
56 {:method => :post, :path => '/projects/world_domination/boards'}
70 {:method => :post, :path => '/projects/world_domination/boards'}
57 )
71 )
58 end
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 def test_show_routing
82 def test_show_routing
61 assert_routing(
83 assert_routing(
62 {:method => :get, :path => '/projects/world_domination/boards/44'},
84 {:method => :get, :path => '/projects/world_domination/boards/44'},
63 :controller => 'boards', :action => 'show', :id => '44', :project_id => 'world_domination'
85 :controller => 'boards', :action => 'show', :id => '44', :project_id => 'world_domination'
64 )
86 )
65 end
87 end
66
88
67 def test_show
89 def test_show
68 get :show, :project_id => 1, :id => 1
90 get :show, :project_id => 1, :id => 1
69 assert_response :success
91 assert_response :success
70 assert_template 'show'
92 assert_template 'show'
71 assert_not_nil assigns(:board)
93 assert_not_nil assigns(:board)
72 assert_not_nil assigns(:project)
94 assert_not_nil assigns(:project)
73 assert_not_nil assigns(:topics)
95 assert_not_nil assigns(:topics)
74 end
96 end
75
97
76 def test_edit_routing
98 def test_edit_routing
77 assert_routing(
99 assert_routing(
78 {:method => :get, :path => '/projects/world_domination/boards/44/edit'},
100 {:method => :get, :path => '/projects/world_domination/boards/44/edit'},
79 :controller => 'boards', :action => 'edit', :id => '44', :project_id => 'world_domination'
101 :controller => 'boards', :action => 'edit', :id => '44', :project_id => 'world_domination'
80 )
102 )
81 assert_recognizes(#TODO: use PUT method to board_path, modify form accordingly
103 assert_recognizes(#TODO: use PUT method to board_path, modify form accordingly
82 {:controller => 'boards', :action => 'edit', :id => '44', :project_id => 'world_domination'},
104 {:controller => 'boards', :action => 'edit', :id => '44', :project_id => 'world_domination'},
83 {:method => :post, :path => '/projects/world_domination/boards/44/edit'}
105 {:method => :post, :path => '/projects/world_domination/boards/44/edit'}
84 )
106 )
85 end
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 def test_destroy_routing
118 def test_destroy_routing
88 assert_routing(#TODO: use DELETE method to board_path, modify form accoringly
119 assert_routing(#TODO: use DELETE method to board_path, modify form accoringly
89 {:method => :post, :path => '/projects/world_domination/boards/44/destroy'},
120 {:method => :post, :path => '/projects/world_domination/boards/44/destroy'},
90 :controller => 'boards', :action => 'destroy', :id => '44', :project_id => 'world_domination'
121 :controller => 'boards', :action => 'destroy', :id => '44', :project_id => 'world_domination'
91 )
122 )
92 end
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 end
133 end
General Comments 0
You need to be logged in to leave comments. Login now