##// END OF EJS Templates
Rails4: replace deprecated Relation#update_all at BoardsControllerTest...
Toshi MARUYAMA -
r12238:4ca6fb4226df
parent child
Show More
@@ -1,217 +1,217
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
2 # Copyright (C) 2006-2013 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.expand_path('../../test_helper', __FILE__)
18 require File.expand_path('../../test_helper', __FILE__)
19
19
20 class BoardsControllerTest < ActionController::TestCase
20 class BoardsControllerTest < ActionController::TestCase
21 fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
21 fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
22
22
23 def setup
23 def setup
24 User.current = nil
24 User.current = nil
25 end
25 end
26
26
27 def test_index
27 def test_index
28 get :index, :project_id => 1
28 get :index, :project_id => 1
29 assert_response :success
29 assert_response :success
30 assert_template 'index'
30 assert_template 'index'
31 assert_not_nil assigns(:boards)
31 assert_not_nil assigns(:boards)
32 assert_not_nil assigns(:project)
32 assert_not_nil assigns(:project)
33 end
33 end
34
34
35 def test_index_not_found
35 def test_index_not_found
36 get :index, :project_id => 97
36 get :index, :project_id => 97
37 assert_response 404
37 assert_response 404
38 end
38 end
39
39
40 def test_index_should_show_messages_if_only_one_board
40 def test_index_should_show_messages_if_only_one_board
41 Project.find(1).boards.slice(1..-1).each(&:destroy)
41 Project.find(1).boards.slice(1..-1).each(&:destroy)
42
42
43 get :index, :project_id => 1
43 get :index, :project_id => 1
44 assert_response :success
44 assert_response :success
45 assert_template 'show'
45 assert_template 'show'
46 assert_not_nil assigns(:topics)
46 assert_not_nil assigns(:topics)
47 end
47 end
48
48
49 def test_show
49 def test_show
50 get :show, :project_id => 1, :id => 1
50 get :show, :project_id => 1, :id => 1
51 assert_response :success
51 assert_response :success
52 assert_template 'show'
52 assert_template 'show'
53 assert_not_nil assigns(:board)
53 assert_not_nil assigns(:board)
54 assert_not_nil assigns(:project)
54 assert_not_nil assigns(:project)
55 assert_not_nil assigns(:topics)
55 assert_not_nil assigns(:topics)
56 end
56 end
57
57
58 def test_show_should_display_sticky_messages_first
58 def test_show_should_display_sticky_messages_first
59 Message.update_all(:sticky => 0)
59 Message.update_all(:sticky => 0)
60 Message.update_all({:sticky => 1}, {:id => 1})
60 Message.where({:id => 1}).update_all({:sticky => 1})
61
61
62 get :show, :project_id => 1, :id => 1
62 get :show, :project_id => 1, :id => 1
63 assert_response :success
63 assert_response :success
64
64
65 topics = assigns(:topics)
65 topics = assigns(:topics)
66 assert_not_nil topics
66 assert_not_nil topics
67 assert topics.size > 1, "topics size was #{topics.size}"
67 assert topics.size > 1, "topics size was #{topics.size}"
68 assert topics.first.sticky?
68 assert topics.first.sticky?
69 assert topics.first.updated_on < topics.second.updated_on
69 assert topics.first.updated_on < topics.second.updated_on
70 end
70 end
71
71
72 def test_show_should_display_message_with_last_reply_first
72 def test_show_should_display_message_with_last_reply_first
73 Message.update_all(:sticky => 0)
73 Message.update_all(:sticky => 0)
74
74
75 # Reply to an old topic
75 # Reply to an old topic
76 old_topic = Message.where(:board_id => 1, :parent_id => nil).order('created_on ASC').first
76 old_topic = Message.where(:board_id => 1, :parent_id => nil).order('created_on ASC').first
77 reply = Message.new(:board_id => 1, :subject => 'New reply', :content => 'New reply', :author_id => 2)
77 reply = Message.new(:board_id => 1, :subject => 'New reply', :content => 'New reply', :author_id => 2)
78 old_topic.children << reply
78 old_topic.children << reply
79
79
80 get :show, :project_id => 1, :id => 1
80 get :show, :project_id => 1, :id => 1
81 assert_response :success
81 assert_response :success
82 topics = assigns(:topics)
82 topics = assigns(:topics)
83 assert_not_nil topics
83 assert_not_nil topics
84 assert_equal old_topic, topics.first
84 assert_equal old_topic, topics.first
85 end
85 end
86
86
87 def test_show_with_permission_should_display_the_new_message_form
87 def test_show_with_permission_should_display_the_new_message_form
88 @request.session[:user_id] = 2
88 @request.session[:user_id] = 2
89 get :show, :project_id => 1, :id => 1
89 get :show, :project_id => 1, :id => 1
90 assert_response :success
90 assert_response :success
91 assert_template 'show'
91 assert_template 'show'
92
92
93 assert_select 'form#message-form' do
93 assert_select 'form#message-form' do
94 assert_select 'input[name=?]', 'message[subject]'
94 assert_select 'input[name=?]', 'message[subject]'
95 end
95 end
96 end
96 end
97
97
98 def test_show_atom
98 def test_show_atom
99 get :show, :project_id => 1, :id => 1, :format => 'atom'
99 get :show, :project_id => 1, :id => 1, :format => 'atom'
100 assert_response :success
100 assert_response :success
101 assert_template 'common/feed'
101 assert_template 'common/feed'
102 assert_not_nil assigns(:board)
102 assert_not_nil assigns(:board)
103 assert_not_nil assigns(:project)
103 assert_not_nil assigns(:project)
104 assert_not_nil assigns(:messages)
104 assert_not_nil assigns(:messages)
105 end
105 end
106
106
107 def test_show_not_found
107 def test_show_not_found
108 get :index, :project_id => 1, :id => 97
108 get :index, :project_id => 1, :id => 97
109 assert_response 404
109 assert_response 404
110 end
110 end
111
111
112 def test_new
112 def test_new
113 @request.session[:user_id] = 2
113 @request.session[:user_id] = 2
114 get :new, :project_id => 1
114 get :new, :project_id => 1
115 assert_response :success
115 assert_response :success
116 assert_template 'new'
116 assert_template 'new'
117
117
118 assert_select 'select[name=?]', 'board[parent_id]' do
118 assert_select 'select[name=?]', 'board[parent_id]' do
119 assert_select 'option', (Project.find(1).boards.size + 1)
119 assert_select 'option', (Project.find(1).boards.size + 1)
120 assert_select 'option[value=]', :text => '&nbsp;'
120 assert_select 'option[value=]', :text => '&nbsp;'
121 assert_select 'option[value=1]', :text => 'Help'
121 assert_select 'option[value=1]', :text => 'Help'
122 end
122 end
123 end
123 end
124
124
125 def test_new_without_project_boards
125 def test_new_without_project_boards
126 Project.find(1).boards.delete_all
126 Project.find(1).boards.delete_all
127 @request.session[:user_id] = 2
127 @request.session[:user_id] = 2
128
128
129 get :new, :project_id => 1
129 get :new, :project_id => 1
130 assert_response :success
130 assert_response :success
131 assert_template 'new'
131 assert_template 'new'
132
132
133 assert_select 'select[name=?]', 'board[parent_id]', 0
133 assert_select 'select[name=?]', 'board[parent_id]', 0
134 end
134 end
135
135
136 def test_create
136 def test_create
137 @request.session[:user_id] = 2
137 @request.session[:user_id] = 2
138 assert_difference 'Board.count' do
138 assert_difference 'Board.count' do
139 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
139 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
140 end
140 end
141 assert_redirected_to '/projects/ecookbook/settings/boards'
141 assert_redirected_to '/projects/ecookbook/settings/boards'
142 board = Board.order('id DESC').first
142 board = Board.order('id DESC').first
143 assert_equal 'Testing', board.name
143 assert_equal 'Testing', board.name
144 assert_equal 'Testing board creation', board.description
144 assert_equal 'Testing board creation', board.description
145 end
145 end
146
146
147 def test_create_with_parent
147 def test_create_with_parent
148 @request.session[:user_id] = 2
148 @request.session[:user_id] = 2
149 assert_difference 'Board.count' do
149 assert_difference 'Board.count' do
150 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing', :parent_id => 2}
150 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing', :parent_id => 2}
151 end
151 end
152 assert_redirected_to '/projects/ecookbook/settings/boards'
152 assert_redirected_to '/projects/ecookbook/settings/boards'
153 board = Board.order('id DESC').first
153 board = Board.order('id DESC').first
154 assert_equal Board.find(2), board.parent
154 assert_equal Board.find(2), board.parent
155 end
155 end
156
156
157 def test_create_with_failure
157 def test_create_with_failure
158 @request.session[:user_id] = 2
158 @request.session[:user_id] = 2
159 assert_no_difference 'Board.count' do
159 assert_no_difference 'Board.count' do
160 post :create, :project_id => 1, :board => { :name => '', :description => 'Testing board creation'}
160 post :create, :project_id => 1, :board => { :name => '', :description => 'Testing board creation'}
161 end
161 end
162 assert_response :success
162 assert_response :success
163 assert_template 'new'
163 assert_template 'new'
164 end
164 end
165
165
166 def test_edit
166 def test_edit
167 @request.session[:user_id] = 2
167 @request.session[:user_id] = 2
168 get :edit, :project_id => 1, :id => 2
168 get :edit, :project_id => 1, :id => 2
169 assert_response :success
169 assert_response :success
170 assert_template 'edit'
170 assert_template 'edit'
171 end
171 end
172
172
173 def test_edit_with_parent
173 def test_edit_with_parent
174 board = Board.generate!(:project_id => 1, :parent_id => 2)
174 board = Board.generate!(:project_id => 1, :parent_id => 2)
175 @request.session[:user_id] = 2
175 @request.session[:user_id] = 2
176 get :edit, :project_id => 1, :id => board.id
176 get :edit, :project_id => 1, :id => board.id
177 assert_response :success
177 assert_response :success
178 assert_template 'edit'
178 assert_template 'edit'
179
179
180 assert_select 'select[name=?]', 'board[parent_id]' do
180 assert_select 'select[name=?]', 'board[parent_id]' do
181 assert_select 'option[value=2][selected=selected]'
181 assert_select 'option[value=2][selected=selected]'
182 end
182 end
183 end
183 end
184
184
185 def test_update
185 def test_update
186 @request.session[:user_id] = 2
186 @request.session[:user_id] = 2
187 assert_no_difference 'Board.count' do
187 assert_no_difference 'Board.count' do
188 put :update, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'}
188 put :update, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'}
189 end
189 end
190 assert_redirected_to '/projects/ecookbook/settings/boards'
190 assert_redirected_to '/projects/ecookbook/settings/boards'
191 assert_equal 'Testing', Board.find(2).name
191 assert_equal 'Testing', Board.find(2).name
192 end
192 end
193
193
194 def test_update_position
194 def test_update_position
195 @request.session[:user_id] = 2
195 @request.session[:user_id] = 2
196 put :update, :project_id => 1, :id => 2, :board => { :move_to => 'highest'}
196 put :update, :project_id => 1, :id => 2, :board => { :move_to => 'highest'}
197 assert_redirected_to '/projects/ecookbook/settings/boards'
197 assert_redirected_to '/projects/ecookbook/settings/boards'
198 board = Board.find(2)
198 board = Board.find(2)
199 assert_equal 1, board.position
199 assert_equal 1, board.position
200 end
200 end
201
201
202 def test_update_with_failure
202 def test_update_with_failure
203 @request.session[:user_id] = 2
203 @request.session[:user_id] = 2
204 put :update, :project_id => 1, :id => 2, :board => { :name => '', :description => 'Testing board update'}
204 put :update, :project_id => 1, :id => 2, :board => { :name => '', :description => 'Testing board update'}
205 assert_response :success
205 assert_response :success
206 assert_template 'edit'
206 assert_template 'edit'
207 end
207 end
208
208
209 def test_destroy
209 def test_destroy
210 @request.session[:user_id] = 2
210 @request.session[:user_id] = 2
211 assert_difference 'Board.count', -1 do
211 assert_difference 'Board.count', -1 do
212 delete :destroy, :project_id => 1, :id => 2
212 delete :destroy, :project_id => 1, :id => 2
213 end
213 end
214 assert_redirected_to '/projects/ecookbook/settings/boards'
214 assert_redirected_to '/projects/ecookbook/settings/boards'
215 assert_nil Board.find_by_id(2)
215 assert_nil Board.find_by_id(2)
216 end
216 end
217 end
217 end
General Comments 0
You need to be logged in to leave comments. Login now