comparison .svn/pristine/19/1932ee9bec078be0ff0c0caab9f5e072b2fcecac.svn-base @ 1494:e248c7af89ec redmine-2.4

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