##// END OF EJS Templates
Don't call #slice on association proxy....
Jean-Philippe Lang -
r15350:3c88dd5041d7
parent child
Show More
@@ -1,217 +1,217
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2016 Jean-Philippe Lang
2 # Copyright (C) 2006-2016 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 < Redmine::ControllerTest
20 class BoardsControllerTest < Redmine::ControllerTest
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_select 'table.boards'
30 assert_select 'table.boards'
31 end
31 end
32
32
33 def test_index_not_found
33 def test_index_not_found
34 get :index, :project_id => 97
34 get :index, :project_id => 97
35 assert_response 404
35 assert_response 404
36 end
36 end
37
37
38 def test_index_should_show_messages_if_only_one_board
38 def test_index_should_show_messages_if_only_one_board
39 Project.find(1).boards.slice(1..-1).each(&:destroy)
39 Project.find(1).boards.to_a.slice(1..-1).each(&:destroy)
40
40
41 get :index, :project_id => 1
41 get :index, :project_id => 1
42 assert_response :success
42 assert_response :success
43
43
44 assert_select 'table.boards', 0
44 assert_select 'table.boards', 0
45 assert_select 'table.messages'
45 assert_select 'table.messages'
46 end
46 end
47
47
48 def test_show
48 def test_show
49 get :show, :project_id => 1, :id => 1
49 get :show, :project_id => 1, :id => 1
50 assert_response :success
50 assert_response :success
51
51
52 assert_select 'table.messages tbody' do
52 assert_select 'table.messages tbody' do
53 assert_select 'tr', Board.find(1).topics.count
53 assert_select 'tr', Board.find(1).topics.count
54 end
54 end
55 end
55 end
56
56
57 def test_show_should_display_sticky_messages_first
57 def test_show_should_display_sticky_messages_first
58 Message.update_all(:sticky => 0)
58 Message.update_all(:sticky => 0)
59 Message.where({:id => 1}).update_all({:sticky => 1})
59 Message.where({:id => 1}).update_all({:sticky => 1})
60
60
61 get :show, :project_id => 1, :id => 1
61 get :show, :project_id => 1, :id => 1
62 assert_response :success
62 assert_response :success
63
63
64 assert_select 'table.messages tbody' do
64 assert_select 'table.messages tbody' do
65 # row is here...
65 # row is here...
66 assert_select 'tr.sticky'
66 assert_select 'tr.sticky'
67 # ...and in first position
67 # ...and in first position
68 assert_select 'tr.sticky:first-child'
68 assert_select 'tr.sticky:first-child'
69 end
69 end
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
82
83 assert_select 'table.messages tbody' do
83 assert_select 'table.messages tbody' do
84 assert_select "tr#message-#{old_topic.id}"
84 assert_select "tr#message-#{old_topic.id}"
85 assert_select "tr#message-#{old_topic.id}:first-child"
85 assert_select "tr#message-#{old_topic.id}:first-child"
86 end
86 end
87 end
87 end
88
88
89 def test_show_with_permission_should_display_the_new_message_form
89 def test_show_with_permission_should_display_the_new_message_form
90 @request.session[:user_id] = 2
90 @request.session[:user_id] = 2
91 get :show, :project_id => 1, :id => 1
91 get :show, :project_id => 1, :id => 1
92 assert_response :success
92 assert_response :success
93
93
94 assert_select 'form#message-form' do
94 assert_select 'form#message-form' do
95 assert_select 'input[name=?]', 'message[subject]'
95 assert_select 'input[name=?]', 'message[subject]'
96 end
96 end
97 end
97 end
98
98
99 def test_show_atom
99 def test_show_atom
100 get :show, :project_id => 1, :id => 1, :format => 'atom'
100 get :show, :project_id => 1, :id => 1, :format => 'atom'
101 assert_response :success
101 assert_response :success
102
102
103 assert_select 'feed > entry > title', :text => 'Help: RE: post 2'
103 assert_select 'feed > entry > title', :text => 'Help: RE: post 2'
104 end
104 end
105
105
106 def test_show_not_found
106 def test_show_not_found
107 get :index, :project_id => 1, :id => 97
107 get :index, :project_id => 1, :id => 97
108 assert_response 404
108 assert_response 404
109 end
109 end
110
110
111 def test_new
111 def test_new
112 @request.session[:user_id] = 2
112 @request.session[:user_id] = 2
113 get :new, :project_id => 1
113 get :new, :project_id => 1
114 assert_response :success
114 assert_response :success
115
115
116 assert_select 'select[name=?]', 'board[parent_id]' do
116 assert_select 'select[name=?]', 'board[parent_id]' do
117 assert_select 'option', (Project.find(1).boards.size + 1)
117 assert_select 'option', (Project.find(1).boards.size + 1)
118 assert_select 'option[value=""]'
118 assert_select 'option[value=""]'
119 assert_select 'option[value="1"]', :text => 'Help'
119 assert_select 'option[value="1"]', :text => 'Help'
120 end
120 end
121
121
122 # &nbsp; replaced by nokogiri, not easy to test in DOM assertions
122 # &nbsp; replaced by nokogiri, not easy to test in DOM assertions
123 assert_not_include '<option value=""></option>', response.body
123 assert_not_include '<option value=""></option>', response.body
124 assert_include '<option value="">&nbsp;</option>', response.body
124 assert_include '<option value="">&nbsp;</option>', response.body
125 end
125 end
126
126
127 def test_new_without_project_boards
127 def test_new_without_project_boards
128 Project.find(1).boards.delete_all
128 Project.find(1).boards.delete_all
129 @request.session[:user_id] = 2
129 @request.session[:user_id] = 2
130
130
131 get :new, :project_id => 1
131 get :new, :project_id => 1
132 assert_response :success
132 assert_response :success
133
133
134 assert_select 'select[name=?]', 'board[parent_id]', 0
134 assert_select 'select[name=?]', 'board[parent_id]', 0
135 end
135 end
136
136
137 def test_create
137 def test_create
138 @request.session[:user_id] = 2
138 @request.session[:user_id] = 2
139 assert_difference 'Board.count' do
139 assert_difference 'Board.count' do
140 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
140 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
141 end
141 end
142 assert_redirected_to '/projects/ecookbook/settings/boards'
142 assert_redirected_to '/projects/ecookbook/settings/boards'
143 board = Board.order('id DESC').first
143 board = Board.order('id DESC').first
144 assert_equal 'Testing', board.name
144 assert_equal 'Testing', board.name
145 assert_equal 'Testing board creation', board.description
145 assert_equal 'Testing board creation', board.description
146 end
146 end
147
147
148 def test_create_with_parent
148 def test_create_with_parent
149 @request.session[:user_id] = 2
149 @request.session[:user_id] = 2
150 assert_difference 'Board.count' do
150 assert_difference 'Board.count' do
151 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing', :parent_id => 2}
151 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing', :parent_id => 2}
152 end
152 end
153 assert_redirected_to '/projects/ecookbook/settings/boards'
153 assert_redirected_to '/projects/ecookbook/settings/boards'
154 board = Board.order('id DESC').first
154 board = Board.order('id DESC').first
155 assert_equal Board.find(2), board.parent
155 assert_equal Board.find(2), board.parent
156 end
156 end
157
157
158 def test_create_with_failure
158 def test_create_with_failure
159 @request.session[:user_id] = 2
159 @request.session[:user_id] = 2
160 assert_no_difference 'Board.count' do
160 assert_no_difference 'Board.count' do
161 post :create, :project_id => 1, :board => { :name => '', :description => 'Testing board creation'}
161 post :create, :project_id => 1, :board => { :name => '', :description => 'Testing board creation'}
162 end
162 end
163 assert_response :success
163 assert_response :success
164 assert_select_error /Name cannot be blank/
164 assert_select_error /Name cannot be blank/
165 end
165 end
166
166
167 def test_edit
167 def test_edit
168 @request.session[:user_id] = 2
168 @request.session[:user_id] = 2
169 get :edit, :project_id => 1, :id => 2
169 get :edit, :project_id => 1, :id => 2
170 assert_response :success
170 assert_response :success
171 assert_select 'input[name=?][value=?]', 'board[name]', 'Discussion'
171 assert_select 'input[name=?][value=?]', 'board[name]', 'Discussion'
172 end
172 end
173
173
174 def test_edit_with_parent
174 def test_edit_with_parent
175 board = Board.generate!(:project_id => 1, :parent_id => 2)
175 board = Board.generate!(:project_id => 1, :parent_id => 2)
176 @request.session[:user_id] = 2
176 @request.session[:user_id] = 2
177 get :edit, :project_id => 1, :id => board.id
177 get :edit, :project_id => 1, :id => board.id
178 assert_response :success
178 assert_response :success
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 => { :position => 1}
196 put :update, :project_id => 1, :id => 2, :board => { :position => 1}
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_select_error /Name cannot be blank/
206 assert_select_error /Name cannot be blank/
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