|
@@
-1,226
+1,239
|
|
1
|
# Redmine - project management software
|
|
1
|
# Redmine - project management software
|
|
2
|
# Copyright (C) 2006-2012 Jean-Philippe Lang
|
|
2
|
# Copyright (C) 2006-2012 Jean-Philippe Lang
|
|
3
|
#
|
|
3
|
#
|
|
4
|
# This program is free software; you can redistribute it and/or
|
|
4
|
# This program is free software; you can redistribute it and/or
|
|
5
|
# modify it under the terms of the GNU General Public License
|
|
5
|
# modify it under the terms of the GNU General Public License
|
|
6
|
# as published by the Free Software Foundation; either version 2
|
|
6
|
# as published by the Free Software Foundation; either version 2
|
|
7
|
# of the License, or (at your option) any later version.
|
|
7
|
# of the License, or (at your option) any later version.
|
|
8
|
#
|
|
8
|
#
|
|
9
|
# This program is distributed in the hope that it will be useful,
|
|
9
|
# This program is distributed in the hope that it will be useful,
|
|
10
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
# GNU General Public License for more details.
|
|
12
|
# GNU General Public License for more details.
|
|
13
|
#
|
|
13
|
#
|
|
14
|
# You should have received a copy of the GNU General Public License
|
|
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
|
|
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.
|
|
16
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
17
|
|
|
17
|
|
|
18
|
require File.expand_path('../../test_helper', __FILE__)
|
|
18
|
require File.expand_path('../../test_helper', __FILE__)
|
|
19
|
require 'versions_controller'
|
|
19
|
require 'versions_controller'
|
|
20
|
|
|
20
|
|
|
21
|
# Re-raise errors caught by the controller.
|
|
21
|
# Re-raise errors caught by the controller.
|
|
22
|
class VersionsController; def rescue_action(e) raise e end; end
|
|
22
|
class VersionsController; def rescue_action(e) raise e end; end
|
|
23
|
|
|
23
|
|
|
24
|
class VersionsControllerTest < ActionController::TestCase
|
|
24
|
class VersionsControllerTest < ActionController::TestCase
|
|
25
|
fixtures :projects, :versions, :issues, :users, :roles, :members, :member_roles, :enabled_modules, :issue_statuses
|
|
25
|
fixtures :projects, :versions, :issues, :users, :roles, :members, :member_roles, :enabled_modules, :issue_statuses, :issue_categories
|
|
26
|
|
|
26
|
|
|
27
|
def setup
|
|
27
|
def setup
|
|
28
|
@controller = VersionsController.new
|
|
28
|
@controller = VersionsController.new
|
|
29
|
@request = ActionController::TestRequest.new
|
|
29
|
@request = ActionController::TestRequest.new
|
|
30
|
@response = ActionController::TestResponse.new
|
|
30
|
@response = ActionController::TestResponse.new
|
|
31
|
User.current = nil
|
|
31
|
User.current = nil
|
|
32
|
end
|
|
32
|
end
|
|
33
|
|
|
33
|
|
|
34
|
def test_index
|
|
34
|
def test_index
|
|
35
|
get :index, :project_id => 1
|
|
35
|
get :index, :project_id => 1
|
|
36
|
assert_response :success
|
|
36
|
assert_response :success
|
|
37
|
assert_template 'index'
|
|
37
|
assert_template 'index'
|
|
38
|
assert_not_nil assigns(:versions)
|
|
38
|
assert_not_nil assigns(:versions)
|
|
39
|
# Version with no date set appears
|
|
39
|
# Version with no date set appears
|
|
40
|
assert assigns(:versions).include?(Version.find(3))
|
|
40
|
assert assigns(:versions).include?(Version.find(3))
|
|
41
|
# Completed version doesn't appear
|
|
41
|
# Completed version doesn't appear
|
|
42
|
assert !assigns(:versions).include?(Version.find(1))
|
|
42
|
assert !assigns(:versions).include?(Version.find(1))
|
|
43
|
# Context menu on issues
|
|
43
|
# Context menu on issues
|
|
44
|
assert_select "script", :text => Regexp.new(Regexp.escape("contextMenuInit('/issues/context_menu')"))
|
|
44
|
assert_select "script", :text => Regexp.new(Regexp.escape("contextMenuInit('/issues/context_menu')"))
|
|
45
|
# Links to versions anchors
|
|
45
|
# Links to versions anchors
|
|
46
|
assert_tag 'a', :attributes => {:href => '#2.0'},
|
|
46
|
assert_tag 'a', :attributes => {:href => '#2.0'},
|
|
47
|
:ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}}
|
|
47
|
:ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}}
|
|
48
|
# Links to completed versions in the sidebar
|
|
48
|
# Links to completed versions in the sidebar
|
|
49
|
assert_tag 'a', :attributes => {:href => '/versions/1'},
|
|
49
|
assert_tag 'a', :attributes => {:href => '/versions/1'},
|
|
50
|
:ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}}
|
|
50
|
:ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}}
|
|
51
|
end
|
|
51
|
end
|
|
52
|
|
|
52
|
|
|
53
|
def test_index_with_completed_versions
|
|
53
|
def test_index_with_completed_versions
|
|
54
|
get :index, :project_id => 1, :completed => 1
|
|
54
|
get :index, :project_id => 1, :completed => 1
|
|
55
|
assert_response :success
|
|
55
|
assert_response :success
|
|
56
|
assert_template 'index'
|
|
56
|
assert_template 'index'
|
|
57
|
assert_not_nil assigns(:versions)
|
|
57
|
assert_not_nil assigns(:versions)
|
|
58
|
# Version with no date set appears
|
|
58
|
# Version with no date set appears
|
|
59
|
assert assigns(:versions).include?(Version.find(3))
|
|
59
|
assert assigns(:versions).include?(Version.find(3))
|
|
60
|
# Completed version appears
|
|
60
|
# Completed version appears
|
|
61
|
assert assigns(:versions).include?(Version.find(1))
|
|
61
|
assert assigns(:versions).include?(Version.find(1))
|
|
62
|
end
|
|
62
|
end
|
|
63
|
|
|
63
|
|
|
64
|
def test_index_with_tracker_ids
|
|
64
|
def test_index_with_tracker_ids
|
|
65
|
get :index, :project_id => 1, :tracker_ids => [1, 3]
|
|
65
|
get :index, :project_id => 1, :tracker_ids => [1, 3]
|
|
66
|
assert_response :success
|
|
66
|
assert_response :success
|
|
67
|
assert_template 'index'
|
|
67
|
assert_template 'index'
|
|
68
|
assert_not_nil assigns(:issues_by_version)
|
|
68
|
assert_not_nil assigns(:issues_by_version)
|
|
69
|
assert_nil assigns(:issues_by_version).values.flatten.detect {|issue| issue.tracker_id == 2}
|
|
69
|
assert_nil assigns(:issues_by_version).values.flatten.detect {|issue| issue.tracker_id == 2}
|
|
70
|
end
|
|
70
|
end
|
|
71
|
|
|
71
|
|
|
72
|
def test_index_showing_subprojects_versions
|
|
72
|
def test_index_showing_subprojects_versions
|
|
73
|
@subproject_version = Version.create!(:project => Project.find(3), :name => "Subproject version")
|
|
73
|
@subproject_version = Version.create!(:project => Project.find(3), :name => "Subproject version")
|
|
74
|
get :index, :project_id => 1, :with_subprojects => 1
|
|
74
|
get :index, :project_id => 1, :with_subprojects => 1
|
|
75
|
assert_response :success
|
|
75
|
assert_response :success
|
|
76
|
assert_template 'index'
|
|
76
|
assert_template 'index'
|
|
77
|
assert_not_nil assigns(:versions)
|
|
77
|
assert_not_nil assigns(:versions)
|
|
78
|
|
|
78
|
|
|
79
|
assert assigns(:versions).include?(Version.find(4)), "Shared version not found"
|
|
79
|
assert assigns(:versions).include?(Version.find(4)), "Shared version not found"
|
|
80
|
assert assigns(:versions).include?(@subproject_version), "Subproject version not found"
|
|
80
|
assert assigns(:versions).include?(@subproject_version), "Subproject version not found"
|
|
81
|
end
|
|
81
|
end
|
|
82
|
|
|
82
|
|
|
83
|
def test_index_should_prepend_shared_versions
|
|
83
|
def test_index_should_prepend_shared_versions
|
|
84
|
get :index, :project_id => 1
|
|
84
|
get :index, :project_id => 1
|
|
85
|
assert_response :success
|
|
85
|
assert_response :success
|
|
86
|
|
|
86
|
|
|
87
|
assert_select '#sidebar' do
|
|
87
|
assert_select '#sidebar' do
|
|
88
|
assert_select 'a[href=?]', '#2.0', :text => '2.0'
|
|
88
|
assert_select 'a[href=?]', '#2.0', :text => '2.0'
|
|
89
|
assert_select 'a[href=?]', '#subproject1-2.0', :text => 'eCookbook Subproject 1 - 2.0'
|
|
89
|
assert_select 'a[href=?]', '#subproject1-2.0', :text => 'eCookbook Subproject 1 - 2.0'
|
|
90
|
end
|
|
90
|
end
|
|
91
|
assert_select '#content' do
|
|
91
|
assert_select '#content' do
|
|
92
|
assert_select 'a[name=?]', '2.0', :text => '2.0'
|
|
92
|
assert_select 'a[name=?]', '2.0', :text => '2.0'
|
|
93
|
assert_select 'a[name=?]', 'subproject1-2.0', :text => 'eCookbook Subproject 1 - 2.0'
|
|
93
|
assert_select 'a[name=?]', 'subproject1-2.0', :text => 'eCookbook Subproject 1 - 2.0'
|
|
94
|
end
|
|
94
|
end
|
|
95
|
end
|
|
95
|
end
|
|
96
|
|
|
96
|
|
|
97
|
def test_show
|
|
97
|
def test_show
|
|
98
|
get :show, :id => 2
|
|
98
|
get :show, :id => 2
|
|
99
|
assert_response :success
|
|
99
|
assert_response :success
|
|
100
|
assert_template 'show'
|
|
100
|
assert_template 'show'
|
|
101
|
assert_not_nil assigns(:version)
|
|
101
|
assert_not_nil assigns(:version)
|
|
102
|
|
|
102
|
|
|
103
|
assert_tag :tag => 'h2', :content => /1.0/
|
|
103
|
assert_tag :tag => 'h2', :content => /1.0/
|
|
104
|
end
|
|
104
|
end
|
|
105
|
|
|
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
|
|
|
106
|
def test_new
|
|
119
|
def test_new
|
|
107
|
@request.session[:user_id] = 2
|
|
120
|
@request.session[:user_id] = 2
|
|
108
|
get :new, :project_id => '1'
|
|
121
|
get :new, :project_id => '1'
|
|
109
|
assert_response :success
|
|
122
|
assert_response :success
|
|
110
|
assert_template 'new'
|
|
123
|
assert_template 'new'
|
|
111
|
end
|
|
124
|
end
|
|
112
|
|
|
125
|
|
|
113
|
def test_new_from_issue_form
|
|
126
|
def test_new_from_issue_form
|
|
114
|
@request.session[:user_id] = 2
|
|
127
|
@request.session[:user_id] = 2
|
|
115
|
xhr :get, :new, :project_id => '1'
|
|
128
|
xhr :get, :new, :project_id => '1'
|
|
116
|
assert_response :success
|
|
129
|
assert_response :success
|
|
117
|
assert_template 'new'
|
|
130
|
assert_template 'new'
|
|
118
|
assert_equal 'text/javascript', response.content_type
|
|
131
|
assert_equal 'text/javascript', response.content_type
|
|
119
|
end
|
|
132
|
end
|
|
120
|
|
|
133
|
|
|
121
|
def test_create
|
|
134
|
def test_create
|
|
122
|
@request.session[:user_id] = 2 # manager
|
|
135
|
@request.session[:user_id] = 2 # manager
|
|
123
|
assert_difference 'Version.count' do
|
|
136
|
assert_difference 'Version.count' do
|
|
124
|
post :create, :project_id => '1', :version => {:name => 'test_add_version'}
|
|
137
|
post :create, :project_id => '1', :version => {:name => 'test_add_version'}
|
|
125
|
end
|
|
138
|
end
|
|
126
|
assert_redirected_to '/projects/ecookbook/settings/versions'
|
|
139
|
assert_redirected_to '/projects/ecookbook/settings/versions'
|
|
127
|
version = Version.find_by_name('test_add_version')
|
|
140
|
version = Version.find_by_name('test_add_version')
|
|
128
|
assert_not_nil version
|
|
141
|
assert_not_nil version
|
|
129
|
assert_equal 1, version.project_id
|
|
142
|
assert_equal 1, version.project_id
|
|
130
|
end
|
|
143
|
end
|
|
131
|
|
|
144
|
|
|
132
|
def test_create_from_issue_form
|
|
145
|
def test_create_from_issue_form
|
|
133
|
@request.session[:user_id] = 2
|
|
146
|
@request.session[:user_id] = 2
|
|
134
|
assert_difference 'Version.count' do
|
|
147
|
assert_difference 'Version.count' do
|
|
135
|
xhr :post, :create, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'}
|
|
148
|
xhr :post, :create, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'}
|
|
136
|
end
|
|
149
|
end
|
|
137
|
version = Version.find_by_name('test_add_version_from_issue_form')
|
|
150
|
version = Version.find_by_name('test_add_version_from_issue_form')
|
|
138
|
assert_not_nil version
|
|
151
|
assert_not_nil version
|
|
139
|
assert_equal 1, version.project_id
|
|
152
|
assert_equal 1, version.project_id
|
|
140
|
|
|
153
|
|
|
141
|
assert_response :success
|
|
154
|
assert_response :success
|
|
142
|
assert_template 'create'
|
|
155
|
assert_template 'create'
|
|
143
|
assert_equal 'text/javascript', response.content_type
|
|
156
|
assert_equal 'text/javascript', response.content_type
|
|
144
|
assert_include 'test_add_version_from_issue_form', response.body
|
|
157
|
assert_include 'test_add_version_from_issue_form', response.body
|
|
145
|
end
|
|
158
|
end
|
|
146
|
|
|
159
|
|
|
147
|
def test_create_from_issue_form_with_failure
|
|
160
|
def test_create_from_issue_form_with_failure
|
|
148
|
@request.session[:user_id] = 2
|
|
161
|
@request.session[:user_id] = 2
|
|
149
|
assert_no_difference 'Version.count' do
|
|
162
|
assert_no_difference 'Version.count' do
|
|
150
|
xhr :post, :create, :project_id => '1', :version => {:name => ''}
|
|
163
|
xhr :post, :create, :project_id => '1', :version => {:name => ''}
|
|
151
|
end
|
|
164
|
end
|
|
152
|
assert_response :success
|
|
165
|
assert_response :success
|
|
153
|
assert_template 'new'
|
|
166
|
assert_template 'new'
|
|
154
|
assert_equal 'text/javascript', response.content_type
|
|
167
|
assert_equal 'text/javascript', response.content_type
|
|
155
|
end
|
|
168
|
end
|
|
156
|
|
|
169
|
|
|
157
|
def test_get_edit
|
|
170
|
def test_get_edit
|
|
158
|
@request.session[:user_id] = 2
|
|
171
|
@request.session[:user_id] = 2
|
|
159
|
get :edit, :id => 2
|
|
172
|
get :edit, :id => 2
|
|
160
|
assert_response :success
|
|
173
|
assert_response :success
|
|
161
|
assert_template 'edit'
|
|
174
|
assert_template 'edit'
|
|
162
|
end
|
|
175
|
end
|
|
163
|
|
|
176
|
|
|
164
|
def test_close_completed
|
|
177
|
def test_close_completed
|
|
165
|
Version.update_all("status = 'open'")
|
|
178
|
Version.update_all("status = 'open'")
|
|
166
|
@request.session[:user_id] = 2
|
|
179
|
@request.session[:user_id] = 2
|
|
167
|
put :close_completed, :project_id => 'ecookbook'
|
|
180
|
put :close_completed, :project_id => 'ecookbook'
|
|
168
|
assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
|
|
181
|
assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
|
|
169
|
assert_not_nil Version.find_by_status('closed')
|
|
182
|
assert_not_nil Version.find_by_status('closed')
|
|
170
|
end
|
|
183
|
end
|
|
171
|
|
|
184
|
|
|
172
|
def test_post_update
|
|
185
|
def test_post_update
|
|
173
|
@request.session[:user_id] = 2
|
|
186
|
@request.session[:user_id] = 2
|
|
174
|
put :update, :id => 2,
|
|
187
|
put :update, :id => 2,
|
|
175
|
:version => { :name => 'New version name',
|
|
188
|
:version => { :name => 'New version name',
|
|
176
|
:effective_date => Date.today.strftime("%Y-%m-%d")}
|
|
189
|
:effective_date => Date.today.strftime("%Y-%m-%d")}
|
|
177
|
assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
|
|
190
|
assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
|
|
178
|
version = Version.find(2)
|
|
191
|
version = Version.find(2)
|
|
179
|
assert_equal 'New version name', version.name
|
|
192
|
assert_equal 'New version name', version.name
|
|
180
|
assert_equal Date.today, version.effective_date
|
|
193
|
assert_equal Date.today, version.effective_date
|
|
181
|
end
|
|
194
|
end
|
|
182
|
|
|
195
|
|
|
183
|
def test_post_update_with_validation_failure
|
|
196
|
def test_post_update_with_validation_failure
|
|
184
|
@request.session[:user_id] = 2
|
|
197
|
@request.session[:user_id] = 2
|
|
185
|
put :update, :id => 2,
|
|
198
|
put :update, :id => 2,
|
|
186
|
:version => { :name => '',
|
|
199
|
:version => { :name => '',
|
|
187
|
:effective_date => Date.today.strftime("%Y-%m-%d")}
|
|
200
|
:effective_date => Date.today.strftime("%Y-%m-%d")}
|
|
188
|
assert_response :success
|
|
201
|
assert_response :success
|
|
189
|
assert_template 'edit'
|
|
202
|
assert_template 'edit'
|
|
190
|
end
|
|
203
|
end
|
|
191
|
|
|
204
|
|
|
192
|
def test_destroy
|
|
205
|
def test_destroy
|
|
193
|
@request.session[:user_id] = 2
|
|
206
|
@request.session[:user_id] = 2
|
|
194
|
assert_difference 'Version.count', -1 do
|
|
207
|
assert_difference 'Version.count', -1 do
|
|
195
|
delete :destroy, :id => 3
|
|
208
|
delete :destroy, :id => 3
|
|
196
|
end
|
|
209
|
end
|
|
197
|
assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
|
|
210
|
assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
|
|
198
|
assert_nil Version.find_by_id(3)
|
|
211
|
assert_nil Version.find_by_id(3)
|
|
199
|
end
|
|
212
|
end
|
|
200
|
|
|
213
|
|
|
201
|
def test_destroy_version_in_use_should_fail
|
|
214
|
def test_destroy_version_in_use_should_fail
|
|
202
|
@request.session[:user_id] = 2
|
|
215
|
@request.session[:user_id] = 2
|
|
203
|
assert_no_difference 'Version.count' do
|
|
216
|
assert_no_difference 'Version.count' do
|
|
204
|
delete :destroy, :id => 2
|
|
217
|
delete :destroy, :id => 2
|
|
205
|
end
|
|
218
|
end
|
|
206
|
assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
|
|
219
|
assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
|
|
207
|
assert flash[:error].match(/Unable to delete version/)
|
|
220
|
assert flash[:error].match(/Unable to delete version/)
|
|
208
|
assert Version.find_by_id(2)
|
|
221
|
assert Version.find_by_id(2)
|
|
209
|
end
|
|
222
|
end
|
|
210
|
|
|
223
|
|
|
211
|
def test_issue_status_by
|
|
224
|
def test_issue_status_by
|
|
212
|
xhr :get, :status_by, :id => 2
|
|
225
|
xhr :get, :status_by, :id => 2
|
|
213
|
assert_response :success
|
|
226
|
assert_response :success
|
|
214
|
assert_template 'status_by'
|
|
227
|
assert_template 'status_by'
|
|
215
|
assert_template '_issue_counts'
|
|
228
|
assert_template '_issue_counts'
|
|
216
|
end
|
|
229
|
end
|
|
217
|
|
|
230
|
|
|
218
|
def test_issue_status_by_status
|
|
231
|
def test_issue_status_by_status
|
|
219
|
xhr :get, :status_by, :id => 2, :status_by => 'status'
|
|
232
|
xhr :get, :status_by, :id => 2, :status_by => 'status'
|
|
220
|
assert_response :success
|
|
233
|
assert_response :success
|
|
221
|
assert_template 'status_by'
|
|
234
|
assert_template 'status_by'
|
|
222
|
assert_template '_issue_counts'
|
|
235
|
assert_template '_issue_counts'
|
|
223
|
assert_include 'Assigned', response.body
|
|
236
|
assert_include 'Assigned', response.body
|
|
224
|
assert_include 'Closed', response.body
|
|
237
|
assert_include 'Closed', response.body
|
|
225
|
end
|
|
238
|
end
|
|
226
|
end
|
|
239
|
end
|