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