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