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