comparison .svn/pristine/76/7627b3e96063b3b2d9ab37b36a7671517dc19460.svn-base @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents
children
comparison
equal deleted inserted replaced
1294:3e4c3460b6ca 1295:622f24f53b42
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 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.expand_path('../../test_helper', __FILE__)
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 < ActionController::TestCase
25 fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, :issue_categories,
26 :issues
27
28 def setup
29 @controller = IssueCategoriesController.new
30 @request = ActionController::TestRequest.new
31 @response = ActionController::TestResponse.new
32 User.current = nil
33 @request.session[:user_id] = 2
34 end
35
36 def test_new
37 @request.session[:user_id] = 2 # manager
38 get :new, :project_id => '1'
39 assert_response :success
40 assert_template 'new'
41 assert_select 'input[name=?]', 'issue_category[name]'
42 end
43
44 def test_new_from_issue_form
45 @request.session[:user_id] = 2 # manager
46 xhr :get, :new, :project_id => '1'
47
48 assert_response :success
49 assert_template 'new'
50 assert_equal 'text/javascript', response.content_type
51 end
52
53 def test_create
54 @request.session[:user_id] = 2 # manager
55 assert_difference 'IssueCategory.count' do
56 post :create, :project_id => '1', :issue_category => {:name => 'New category'}
57 end
58 assert_redirected_to '/projects/ecookbook/settings/categories'
59 category = IssueCategory.find_by_name('New category')
60 assert_not_nil category
61 assert_equal 1, category.project_id
62 end
63
64 def test_create_failure
65 @request.session[:user_id] = 2
66 post :create, :project_id => '1', :issue_category => {:name => ''}
67 assert_response :success
68 assert_template 'new'
69 end
70
71 def test_create_from_issue_form
72 @request.session[:user_id] = 2 # manager
73 assert_difference 'IssueCategory.count' do
74 xhr :post, :create, :project_id => '1', :issue_category => {:name => 'New category'}
75 end
76 category = IssueCategory.first(:order => 'id DESC')
77 assert_equal 'New category', category.name
78
79 assert_response :success
80 assert_template 'create'
81 assert_equal 'text/javascript', response.content_type
82 end
83
84 def test_create_from_issue_form_with_failure
85 @request.session[:user_id] = 2 # manager
86 assert_no_difference 'IssueCategory.count' do
87 xhr :post, :create, :project_id => '1', :issue_category => {:name => ''}
88 end
89
90 assert_response :success
91 assert_template 'new'
92 assert_equal 'text/javascript', response.content_type
93 end
94
95 def test_edit
96 @request.session[:user_id] = 2
97 get :edit, :id => 2
98 assert_response :success
99 assert_template 'edit'
100 assert_select 'input[name=?][value=?]', 'issue_category[name]', 'Recipes'
101 end
102
103 def test_update
104 assert_no_difference 'IssueCategory.count' do
105 put :update, :id => 2, :issue_category => { :name => 'Testing' }
106 end
107 assert_redirected_to '/projects/ecookbook/settings/categories'
108 assert_equal 'Testing', IssueCategory.find(2).name
109 end
110
111 def test_update_failure
112 put :update, :id => 2, :issue_category => { :name => '' }
113 assert_response :success
114 assert_template 'edit'
115 end
116
117 def test_update_not_found
118 put :update, :id => 97, :issue_category => { :name => 'Testing' }
119 assert_response 404
120 end
121
122 def test_destroy_category_not_in_use
123 delete :destroy, :id => 2
124 assert_redirected_to '/projects/ecookbook/settings/categories'
125 assert_nil IssueCategory.find_by_id(2)
126 end
127
128 def test_destroy_category_in_use
129 delete :destroy, :id => 1
130 assert_response :success
131 assert_template 'destroy'
132 assert_not_nil IssueCategory.find_by_id(1)
133 end
134
135 def test_destroy_category_in_use_with_reassignment
136 issue = Issue.find(:first, :conditions => {:category_id => 1})
137 delete :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2
138 assert_redirected_to '/projects/ecookbook/settings/categories'
139 assert_nil IssueCategory.find_by_id(1)
140 # check that the issue was reassign
141 assert_equal 2, issue.reload.category_id
142 end
143
144 def test_destroy_category_in_use_without_reassignment
145 issue = Issue.find(:first, :conditions => {:category_id => 1})
146 delete :destroy, :id => 1, :todo => 'nullify'
147 assert_redirected_to '/projects/ecookbook/settings/categories'
148 assert_nil IssueCategory.find_by_id(1)
149 # check that the issue category was nullified
150 assert_nil issue.reload.category_id
151 end
152 end