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