comparison .svn/pristine/66/6624461ad2ec134b393374cac55a9167385a095a.svn-base @ 1295:622f24f53b42 redmine-2.3

Update to Redmine SVN revision 11972 on 2.3-stable branch
author Chris Cannam
date Fri, 14 Jun 2013 09:02:21 +0100
parents
children
comparison
equal deleted inserted replaced
1294:3e4c3460b6ca 1295:622f24f53b42
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 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 require 'versions_controller'
20
21 # Re-raise errors caught by the controller.
22 class VersionsController; def rescue_action(e) raise e end; end
23
24 class VersionsControllerTest < ActionController::TestCase
25 fixtures :projects, :versions, :issues, :users, :roles, :members, :member_roles, :enabled_modules, :issue_statuses, :issue_categories
26
27 def setup
28 @controller = VersionsController.new
29 @request = ActionController::TestRequest.new
30 @response = ActionController::TestResponse.new
31 User.current = nil
32 end
33
34 def test_index
35 get :index, :project_id => 1
36 assert_response :success
37 assert_template 'index'
38 assert_not_nil assigns(:versions)
39 # Version with no date set appears
40 assert assigns(:versions).include?(Version.find(3))
41 # Completed version doesn't appear
42 assert !assigns(:versions).include?(Version.find(1))
43 # Context menu on issues
44 assert_select "script", :text => Regexp.new(Regexp.escape("contextMenuInit('/issues/context_menu')"))
45 # Links to versions anchors
46 assert_tag 'a', :attributes => {:href => '#2.0'},
47 :ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}}
48 # Links to completed versions in the sidebar
49 assert_tag 'a', :attributes => {:href => '/versions/1'},
50 :ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}}
51 end
52
53 def test_index_with_completed_versions
54 get :index, :project_id => 1, :completed => 1
55 assert_response :success
56 assert_template 'index'
57 assert_not_nil assigns(:versions)
58 # Version with no date set appears
59 assert assigns(:versions).include?(Version.find(3))
60 # Completed version appears
61 assert assigns(:versions).include?(Version.find(1))
62 end
63
64 def test_index_with_tracker_ids
65 get :index, :project_id => 1, :tracker_ids => [1, 3]
66 assert_response :success
67 assert_template 'index'
68 assert_not_nil assigns(:issues_by_version)
69 assert_nil assigns(:issues_by_version).values.flatten.detect {|issue| issue.tracker_id == 2}
70 end
71
72 def test_index_showing_subprojects_versions
73 @subproject_version = Version.create!(:project => Project.find(3), :name => "Subproject version")
74 get :index, :project_id => 1, :with_subprojects => 1
75 assert_response :success
76 assert_template 'index'
77 assert_not_nil assigns(:versions)
78
79 assert assigns(:versions).include?(Version.find(4)), "Shared version not found"
80 assert assigns(:versions).include?(@subproject_version), "Subproject version not found"
81 end
82
83 def test_index_should_prepend_shared_versions
84 get :index, :project_id => 1
85 assert_response :success
86
87 assert_select '#sidebar' do
88 assert_select 'a[href=?]', '#2.0', :text => '2.0'
89 assert_select 'a[href=?]', '#subproject1-2.0', :text => 'eCookbook Subproject 1 - 2.0'
90 end
91 assert_select '#content' do
92 assert_select 'a[name=?]', '2.0', :text => '2.0'
93 assert_select 'a[name=?]', 'subproject1-2.0', :text => 'eCookbook Subproject 1 - 2.0'
94 end
95 end
96
97 def test_show
98 get :show, :id => 2
99 assert_response :success
100 assert_template 'show'
101 assert_not_nil assigns(:version)
102
103 assert_tag :tag => 'h2', :content => /1.0/
104 end
105
106 def test_show_should_display_nil_counts
107 with_settings :default_language => 'en' do
108 get :show, :id => 2, :status_by => 'category'
109 assert_response :success
110 assert_select 'div#status_by' do
111 assert_select 'select[name=status_by]' do
112 assert_select 'option[value=category][selected=selected]'
113 end
114 assert_select 'a', :text => 'none'
115 end
116 end
117 end
118
119 def test_new
120 @request.session[:user_id] = 2
121 get :new, :project_id => '1'
122 assert_response :success
123 assert_template 'new'
124 end
125
126 def test_new_from_issue_form
127 @request.session[:user_id] = 2
128 xhr :get, :new, :project_id => '1'
129 assert_response :success
130 assert_template 'new'
131 assert_equal 'text/javascript', response.content_type
132 end
133
134 def test_create
135 @request.session[:user_id] = 2 # manager
136 assert_difference 'Version.count' do
137 post :create, :project_id => '1', :version => {:name => 'test_add_version'}
138 end
139 assert_redirected_to '/projects/ecookbook/settings/versions'
140 version = Version.find_by_name('test_add_version')
141 assert_not_nil version
142 assert_equal 1, version.project_id
143 end
144
145 def test_create_from_issue_form
146 @request.session[:user_id] = 2
147 assert_difference 'Version.count' do
148 xhr :post, :create, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'}
149 end
150 version = Version.find_by_name('test_add_version_from_issue_form')
151 assert_not_nil version
152 assert_equal 1, version.project_id
153
154 assert_response :success
155 assert_template 'create'
156 assert_equal 'text/javascript', response.content_type
157 assert_include 'test_add_version_from_issue_form', response.body
158 end
159
160 def test_create_from_issue_form_with_failure
161 @request.session[:user_id] = 2
162 assert_no_difference 'Version.count' do
163 xhr :post, :create, :project_id => '1', :version => {:name => ''}
164 end
165 assert_response :success
166 assert_template 'new'
167 assert_equal 'text/javascript', response.content_type
168 end
169
170 def test_get_edit
171 @request.session[:user_id] = 2
172 get :edit, :id => 2
173 assert_response :success
174 assert_template 'edit'
175 end
176
177 def test_close_completed
178 Version.update_all("status = 'open'")
179 @request.session[:user_id] = 2
180 put :close_completed, :project_id => 'ecookbook'
181 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
182 assert_not_nil Version.find_by_status('closed')
183 end
184
185 def test_post_update
186 @request.session[:user_id] = 2
187 put :update, :id => 2,
188 :version => { :name => 'New version name',
189 :effective_date => Date.today.strftime("%Y-%m-%d")}
190 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
191 version = Version.find(2)
192 assert_equal 'New version name', version.name
193 assert_equal Date.today, version.effective_date
194 end
195
196 def test_post_update_with_validation_failure
197 @request.session[:user_id] = 2
198 put :update, :id => 2,
199 :version => { :name => '',
200 :effective_date => Date.today.strftime("%Y-%m-%d")}
201 assert_response :success
202 assert_template 'edit'
203 end
204
205 def test_destroy
206 @request.session[:user_id] = 2
207 assert_difference 'Version.count', -1 do
208 delete :destroy, :id => 3
209 end
210 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
211 assert_nil Version.find_by_id(3)
212 end
213
214 def test_destroy_version_in_use_should_fail
215 @request.session[:user_id] = 2
216 assert_no_difference 'Version.count' do
217 delete :destroy, :id => 2
218 end
219 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
220 assert flash[:error].match(/Unable to delete version/)
221 assert Version.find_by_id(2)
222 end
223
224 def test_issue_status_by
225 xhr :get, :status_by, :id => 2
226 assert_response :success
227 assert_template 'status_by'
228 assert_template '_issue_counts'
229 end
230
231 def test_issue_status_by_status
232 xhr :get, :status_by, :id => 2, :status_by => 'status'
233 assert_response :success
234 assert_template 'status_by'
235 assert_template '_issue_counts'
236 assert_include 'Assigned', response.body
237 assert_include 'Closed', response.body
238 end
239 end