Chris@0
|
1 # Redmine - project management software
|
Chris@1115
|
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
|
Chris@0
|
3 #
|
Chris@0
|
4 # This program is free software; you can redistribute it and/or
|
Chris@0
|
5 # modify it under the terms of the GNU General Public License
|
Chris@0
|
6 # as published by the Free Software Foundation; either version 2
|
Chris@0
|
7 # of the License, or (at your option) any later version.
|
Chris@909
|
8 #
|
Chris@0
|
9 # This program is distributed in the hope that it will be useful,
|
Chris@0
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
Chris@0
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Chris@0
|
12 # GNU General Public License for more details.
|
Chris@909
|
13 #
|
Chris@0
|
14 # You should have received a copy of the GNU General Public License
|
Chris@0
|
15 # along with this program; if not, write to the Free Software
|
Chris@0
|
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
Chris@0
|
17
|
Chris@119
|
18 require File.expand_path('../../test_helper', __FILE__)
|
Chris@0
|
19 require 'issue_categories_controller'
|
Chris@0
|
20
|
Chris@0
|
21 # Re-raise errors caught by the controller.
|
Chris@0
|
22 class IssueCategoriesController; def rescue_action(e) raise e end; end
|
Chris@0
|
23
|
Chris@0
|
24 class IssueCategoriesControllerTest < ActionController::TestCase
|
Chris@1115
|
25 fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, :issue_categories,
|
Chris@1115
|
26 :issues
|
Chris@909
|
27
|
Chris@0
|
28 def setup
|
Chris@0
|
29 @controller = IssueCategoriesController.new
|
Chris@0
|
30 @request = ActionController::TestRequest.new
|
Chris@0
|
31 @response = ActionController::TestResponse.new
|
Chris@0
|
32 User.current = nil
|
Chris@0
|
33 @request.session[:user_id] = 2
|
Chris@0
|
34 end
|
Chris@909
|
35
|
Chris@909
|
36 def test_new
|
Chris@0
|
37 @request.session[:user_id] = 2 # manager
|
Chris@0
|
38 get :new, :project_id => '1'
|
Chris@0
|
39 assert_response :success
|
Chris@0
|
40 assert_template 'new'
|
Chris@1115
|
41 assert_select 'input[name=?]', 'issue_category[name]'
|
Chris@1115
|
42 end
|
Chris@1115
|
43
|
Chris@1115
|
44 def test_new_from_issue_form
|
Chris@1115
|
45 @request.session[:user_id] = 2 # manager
|
Chris@1115
|
46 xhr :get, :new, :project_id => '1'
|
Chris@1115
|
47
|
Chris@1115
|
48 assert_response :success
|
Chris@1115
|
49 assert_template 'new'
|
Chris@1115
|
50 assert_equal 'text/javascript', response.content_type
|
Chris@0
|
51 end
|
Chris@909
|
52
|
Chris@909
|
53 def test_create
|
Chris@0
|
54 @request.session[:user_id] = 2 # manager
|
Chris@0
|
55 assert_difference 'IssueCategory.count' do
|
Chris@909
|
56 post :create, :project_id => '1', :issue_category => {:name => 'New category'}
|
Chris@0
|
57 end
|
Chris@0
|
58 assert_redirected_to '/projects/ecookbook/settings/categories'
|
Chris@0
|
59 category = IssueCategory.find_by_name('New category')
|
Chris@0
|
60 assert_not_nil category
|
Chris@0
|
61 assert_equal 1, category.project_id
|
Chris@0
|
62 end
|
Chris@909
|
63
|
Chris@909
|
64 def test_create_failure
|
Chris@909
|
65 @request.session[:user_id] = 2
|
Chris@909
|
66 post :create, :project_id => '1', :issue_category => {:name => ''}
|
Chris@909
|
67 assert_response :success
|
Chris@909
|
68 assert_template 'new'
|
Chris@909
|
69 end
|
Chris@909
|
70
|
Chris@1115
|
71 def test_create_from_issue_form
|
Chris@1115
|
72 @request.session[:user_id] = 2 # manager
|
Chris@1115
|
73 assert_difference 'IssueCategory.count' do
|
Chris@1115
|
74 xhr :post, :create, :project_id => '1', :issue_category => {:name => 'New category'}
|
Chris@1115
|
75 end
|
Chris@1115
|
76 category = IssueCategory.first(:order => 'id DESC')
|
Chris@1115
|
77 assert_equal 'New category', category.name
|
Chris@1115
|
78
|
Chris@1115
|
79 assert_response :success
|
Chris@1115
|
80 assert_template 'create'
|
Chris@1115
|
81 assert_equal 'text/javascript', response.content_type
|
Chris@1115
|
82 end
|
Chris@1115
|
83
|
Chris@1115
|
84 def test_create_from_issue_form_with_failure
|
Chris@1115
|
85 @request.session[:user_id] = 2 # manager
|
Chris@1115
|
86 assert_no_difference 'IssueCategory.count' do
|
Chris@1115
|
87 xhr :post, :create, :project_id => '1', :issue_category => {:name => ''}
|
Chris@1115
|
88 end
|
Chris@1115
|
89
|
Chris@1115
|
90 assert_response :success
|
Chris@1115
|
91 assert_template 'new'
|
Chris@1115
|
92 assert_equal 'text/javascript', response.content_type
|
Chris@1115
|
93 end
|
Chris@1115
|
94
|
Chris@909
|
95 def test_edit
|
Chris@909
|
96 @request.session[:user_id] = 2
|
Chris@909
|
97 get :edit, :id => 2
|
Chris@909
|
98 assert_response :success
|
Chris@909
|
99 assert_template 'edit'
|
Chris@1115
|
100 assert_select 'input[name=?][value=?]', 'issue_category[name]', 'Recipes'
|
Chris@909
|
101 end
|
Chris@909
|
102
|
Chris@909
|
103 def test_update
|
Chris@0
|
104 assert_no_difference 'IssueCategory.count' do
|
Chris@909
|
105 put :update, :id => 2, :issue_category => { :name => 'Testing' }
|
Chris@0
|
106 end
|
Chris@0
|
107 assert_redirected_to '/projects/ecookbook/settings/categories'
|
Chris@0
|
108 assert_equal 'Testing', IssueCategory.find(2).name
|
Chris@0
|
109 end
|
Chris@909
|
110
|
Chris@909
|
111 def test_update_failure
|
Chris@909
|
112 put :update, :id => 2, :issue_category => { :name => '' }
|
Chris@909
|
113 assert_response :success
|
Chris@909
|
114 assert_template 'edit'
|
Chris@909
|
115 end
|
Chris@909
|
116
|
Chris@909
|
117 def test_update_not_found
|
Chris@909
|
118 put :update, :id => 97, :issue_category => { :name => 'Testing' }
|
Chris@0
|
119 assert_response 404
|
Chris@0
|
120 end
|
Chris@909
|
121
|
Chris@0
|
122 def test_destroy_category_not_in_use
|
Chris@909
|
123 delete :destroy, :id => 2
|
Chris@0
|
124 assert_redirected_to '/projects/ecookbook/settings/categories'
|
Chris@0
|
125 assert_nil IssueCategory.find_by_id(2)
|
Chris@0
|
126 end
|
Chris@909
|
127
|
Chris@0
|
128 def test_destroy_category_in_use
|
Chris@909
|
129 delete :destroy, :id => 1
|
Chris@0
|
130 assert_response :success
|
Chris@0
|
131 assert_template 'destroy'
|
Chris@0
|
132 assert_not_nil IssueCategory.find_by_id(1)
|
Chris@0
|
133 end
|
Chris@909
|
134
|
Chris@0
|
135 def test_destroy_category_in_use_with_reassignment
|
Chris@0
|
136 issue = Issue.find(:first, :conditions => {:category_id => 1})
|
Chris@909
|
137 delete :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2
|
Chris@0
|
138 assert_redirected_to '/projects/ecookbook/settings/categories'
|
Chris@0
|
139 assert_nil IssueCategory.find_by_id(1)
|
Chris@0
|
140 # check that the issue was reassign
|
Chris@0
|
141 assert_equal 2, issue.reload.category_id
|
Chris@0
|
142 end
|
Chris@909
|
143
|
Chris@0
|
144 def test_destroy_category_in_use_without_reassignment
|
Chris@0
|
145 issue = Issue.find(:first, :conditions => {:category_id => 1})
|
Chris@909
|
146 delete :destroy, :id => 1, :todo => 'nullify'
|
Chris@0
|
147 assert_redirected_to '/projects/ecookbook/settings/categories'
|
Chris@0
|
148 assert_nil IssueCategory.find_by_id(1)
|
Chris@0
|
149 # check that the issue category was nullified
|
Chris@0
|
150 assert_nil issue.reload.category_id
|
Chris@0
|
151 end
|
Chris@0
|
152 end
|