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