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