comparison .svn/pristine/6f/6ffa0ee9adc461e348a513bb42e310bb6ccba1cd.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
comparison
equal deleted inserted replaced
1297:0a574315af3e 1298:4f746d8966dd
1 # Redmine - project management software
2 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18 require File.expand_path('../../test_helper', __FILE__)
19
20 class BoardsControllerTest < ActionController::TestCase
21 fixtures :projects, :users, :members, :member_roles, :roles, :boards, :messages, :enabled_modules
22
23 def setup
24 User.current = nil
25 end
26
27 def test_index
28 get :index, :project_id => 1
29 assert_response :success
30 assert_template 'index'
31 assert_not_nil assigns(:boards)
32 assert_not_nil assigns(:project)
33 end
34
35 def test_index_not_found
36 get :index, :project_id => 97
37 assert_response 404
38 end
39
40 def test_index_should_show_messages_if_only_one_board
41 Project.find(1).boards.slice(1..-1).each(&:destroy)
42
43 get :index, :project_id => 1
44 assert_response :success
45 assert_template 'show'
46 assert_not_nil assigns(:topics)
47 end
48
49 def test_show
50 get :show, :project_id => 1, :id => 1
51 assert_response :success
52 assert_template 'show'
53 assert_not_nil assigns(:board)
54 assert_not_nil assigns(:project)
55 assert_not_nil assigns(:topics)
56 end
57
58 def test_show_should_display_sticky_messages_first
59 Message.update_all(:sticky => 0)
60 Message.update_all({:sticky => 1}, {:id => 1})
61
62 get :show, :project_id => 1, :id => 1
63 assert_response :success
64
65 topics = assigns(:topics)
66 assert_not_nil topics
67 assert topics.size > 1, "topics size was #{topics.size}"
68 assert topics.first.sticky?
69 assert topics.first.updated_on < topics.second.updated_on
70 end
71
72 def test_show_should_display_message_with_last_reply_first
73 Message.update_all(:sticky => 0)
74
75 # Reply to an old topic
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)
78 old_topic.children << reply
79
80 get :show, :project_id => 1, :id => 1
81 assert_response :success
82 topics = assigns(:topics)
83 assert_not_nil topics
84 assert_equal old_topic, topics.first
85 end
86
87 def test_show_with_permission_should_display_the_new_message_form
88 @request.session[:user_id] = 2
89 get :show, :project_id => 1, :id => 1
90 assert_response :success
91 assert_template 'show'
92
93 assert_select 'form#message-form' do
94 assert_select 'input[name=?]', 'message[subject]'
95 end
96 end
97
98 def test_show_atom
99 get :show, :project_id => 1, :id => 1, :format => 'atom'
100 assert_response :success
101 assert_template 'common/feed'
102 assert_not_nil assigns(:board)
103 assert_not_nil assigns(:project)
104 assert_not_nil assigns(:messages)
105 end
106
107 def test_show_not_found
108 get :index, :project_id => 1, :id => 97
109 assert_response 404
110 end
111
112 def test_new
113 @request.session[:user_id] = 2
114 get :new, :project_id => 1
115 assert_response :success
116 assert_template 'new'
117
118 assert_select 'select[name=?]', 'board[parent_id]' do
119 assert_select 'option', (Project.find(1).boards.size + 1)
120 assert_select 'option[value=]', :text => ''
121 assert_select 'option[value=1]', :text => 'Help'
122 end
123 end
124
125 def test_new_without_project_boards
126 Project.find(1).boards.delete_all
127 @request.session[:user_id] = 2
128
129 get :new, :project_id => 1
130 assert_response :success
131 assert_template 'new'
132
133 assert_select 'select[name=?]', 'board[parent_id]', 0
134 end
135
136 def test_create
137 @request.session[:user_id] = 2
138 assert_difference 'Board.count' do
139 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing board creation'}
140 end
141 assert_redirected_to '/projects/ecookbook/settings/boards'
142 board = Board.first(:order => 'id DESC')
143 assert_equal 'Testing', board.name
144 assert_equal 'Testing board creation', board.description
145 end
146
147 def test_create_with_parent
148 @request.session[:user_id] = 2
149 assert_difference 'Board.count' do
150 post :create, :project_id => 1, :board => { :name => 'Testing', :description => 'Testing', :parent_id => 2}
151 end
152 assert_redirected_to '/projects/ecookbook/settings/boards'
153 board = Board.first(:order => 'id DESC')
154 assert_equal Board.find(2), board.parent
155 end
156
157 def test_create_with_failure
158 @request.session[:user_id] = 2
159 assert_no_difference 'Board.count' do
160 post :create, :project_id => 1, :board => { :name => '', :description => 'Testing board creation'}
161 end
162 assert_response :success
163 assert_template 'new'
164 end
165
166 def test_edit
167 @request.session[:user_id] = 2
168 get :edit, :project_id => 1, :id => 2
169 assert_response :success
170 assert_template 'edit'
171 end
172
173 def test_edit_with_parent
174 board = Board.generate!(:project_id => 1, :parent_id => 2)
175 @request.session[:user_id] = 2
176 get :edit, :project_id => 1, :id => board.id
177 assert_response :success
178 assert_template 'edit'
179
180 assert_select 'select[name=?]', 'board[parent_id]' do
181 assert_select 'option[value=2][selected=selected]'
182 end
183 end
184
185 def test_update
186 @request.session[:user_id] = 2
187 assert_no_difference 'Board.count' do
188 put :update, :project_id => 1, :id => 2, :board => { :name => 'Testing', :description => 'Testing board update'}
189 end
190 assert_redirected_to '/projects/ecookbook/settings/boards'
191 assert_equal 'Testing', Board.find(2).name
192 end
193
194 def test_update_position
195 @request.session[:user_id] = 2
196 put :update, :project_id => 1, :id => 2, :board => { :move_to => 'highest'}
197 assert_redirected_to '/projects/ecookbook/settings/boards'
198 board = Board.find(2)
199 assert_equal 1, board.position
200 end
201
202 def test_update_with_failure
203 @request.session[:user_id] = 2
204 put :update, :project_id => 1, :id => 2, :board => { :name => '', :description => 'Testing board update'}
205 assert_response :success
206 assert_template 'edit'
207 end
208
209 def test_destroy
210 @request.session[:user_id] = 2
211 assert_difference 'Board.count', -1 do
212 delete :destroy, :project_id => 1, :id => 2
213 end
214 assert_redirected_to '/projects/ecookbook/settings/boards'
215 assert_nil Board.find_by_id(2)
216 end
217 end