@@ -1,16 +1,18 | |||
|
1 | 1 | <%= back_url_hidden_field_tag %> |
|
2 | 2 | <%= error_messages_for 'version' %> |
|
3 | 3 | |
|
4 | 4 | <div class="box tabular"> |
|
5 | 5 | <p><%= f.text_field :name, :size => 60, :required => true %></p> |
|
6 | 6 | <p><%= f.text_field :description, :size => 60 %></p> |
|
7 | <p><%= f.select :status, Version::VERSION_STATUSES.collect {|s| [l("version_status_#{s}"), s]} %></p> | |
|
7 | <% unless @version.new_record? %> | |
|
8 | <p><%= f.select :status, Version::VERSION_STATUSES.collect {|s| [l("version_status_#{s}"), s]} %></p> | |
|
9 | <% end %> | |
|
8 | 10 | <p><%= f.text_field :wiki_page_title, :label => :label_wiki_page, :size => 60, :disabled => @project.wiki.nil? %></p> |
|
9 | 11 | <p><%= f.date_field :effective_date, :size => 10 %><%= calendar_for('version_effective_date') %></p> |
|
10 | 12 | <p><%= f.select :sharing, @version.allowed_sharings.collect {|v| [format_version_sharing(v), v]} %></p> |
|
11 | 13 | |
|
12 | 14 | <% @version.custom_field_values.each do |value| %> |
|
13 | 15 | <p><%= custom_field_tag_with_label :version, value %></p> |
|
14 | 16 | <% end %> |
|
15 | 17 | |
|
16 | 18 | </div> |
@@ -1,251 +1,257 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class VersionsControllerTest < Redmine::ControllerTest |
|
21 | 21 | fixtures :projects, :versions, :issues, :users, :roles, :members, |
|
22 | 22 | :member_roles, :enabled_modules, :issue_statuses, |
|
23 | 23 | :issue_categories, :enumerations |
|
24 | 24 | |
|
25 | 25 | def setup |
|
26 | 26 | User.current = nil |
|
27 | 27 | end |
|
28 | 28 | |
|
29 | 29 | def test_index |
|
30 | 30 | get :index, :params => {:project_id => 1} |
|
31 | 31 | assert_response :success |
|
32 | 32 | |
|
33 | 33 | # Version with no date set appears |
|
34 | 34 | assert_select 'h3', :text => Version.find(3).name |
|
35 | 35 | # Completed version doesn't appear |
|
36 | 36 | assert_select 'h3', :text => Version.find(1).name, :count => 0 |
|
37 | 37 | |
|
38 | 38 | # Context menu on issues |
|
39 | 39 | assert_select "script", :text => Regexp.new(Regexp.escape("contextMenuInit('/issues/context_menu')")) |
|
40 | 40 | assert_select "div#sidebar" do |
|
41 | 41 | # Links to versions anchors |
|
42 | 42 | assert_select 'a[href=?]', '#2.0' |
|
43 | 43 | # Links to completed versions in the sidebar |
|
44 | 44 | assert_select 'a[href=?]', '/versions/1' |
|
45 | 45 | end |
|
46 | 46 | end |
|
47 | 47 | |
|
48 | 48 | def test_index_with_completed_versions |
|
49 | 49 | get :index, :params => {:project_id => 1, :completed => 1} |
|
50 | 50 | assert_response :success |
|
51 | 51 | |
|
52 | 52 | # Version with no date set appears |
|
53 | 53 | assert_select 'h3', :text => Version.find(3).name |
|
54 | 54 | # Completed version appears |
|
55 | 55 | assert_select 'h3', :text => Version.find(1).name |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | def test_index_with_tracker_ids |
|
59 | 59 | (1..3).each do |tracker_id| |
|
60 | 60 | Issue.generate! :project_id => 1, :fixed_version_id => 3, :tracker_id => tracker_id |
|
61 | 61 | end |
|
62 | 62 | get :index, :params => {:project_id => 1, :tracker_ids => [1, 3]} |
|
63 | 63 | assert_response :success |
|
64 | 64 | assert_select 'a.issue.tracker-1' |
|
65 | 65 | assert_select 'a.issue.tracker-2', 0 |
|
66 | 66 | assert_select 'a.issue.tracker-3' |
|
67 | 67 | end |
|
68 | 68 | |
|
69 | 69 | def test_index_showing_subprojects_versions |
|
70 | 70 | @subproject_version = Version.create!(:project => Project.find(3), :name => "Subproject version") |
|
71 | 71 | get :index, :params => {:project_id => 1, :with_subprojects => 1} |
|
72 | 72 | assert_response :success |
|
73 | 73 | |
|
74 | 74 | # Shared version |
|
75 | 75 | assert_select 'h3', :text => Version.find(4).name |
|
76 | 76 | # Subproject version |
|
77 | 77 | assert_select 'h3', :text => /Subproject version/ |
|
78 | 78 | end |
|
79 | 79 | |
|
80 | 80 | def test_index_should_prepend_shared_versions |
|
81 | 81 | get :index, :params => {:project_id => 1} |
|
82 | 82 | assert_response :success |
|
83 | 83 | |
|
84 | 84 | assert_select '#sidebar' do |
|
85 | 85 | assert_select 'a[href=?]', '#2.0', :text => '2.0' |
|
86 | 86 | assert_select 'a[href=?]', '#subproject1-2.0', :text => 'eCookbook Subproject 1 - 2.0' |
|
87 | 87 | end |
|
88 | 88 | assert_select '#content' do |
|
89 | 89 | assert_select 'a[name=?]', '2.0', :text => '2.0' |
|
90 | 90 | assert_select 'a[name=?]', 'subproject1-2.0', :text => 'eCookbook Subproject 1 - 2.0' |
|
91 | 91 | end |
|
92 | 92 | end |
|
93 | 93 | |
|
94 | 94 | def test_show |
|
95 | 95 | get :show, :params => {:id => 2} |
|
96 | 96 | assert_response :success |
|
97 | 97 | |
|
98 | 98 | assert_select 'h2', :text => /1.0/ |
|
99 | 99 | end |
|
100 | 100 | |
|
101 | 101 | def test_show_should_link_to_spent_time_on_version |
|
102 | 102 | version = Version.generate! |
|
103 | 103 | issue = Issue.generate(:fixed_version => version) |
|
104 | 104 | TimeEntry.generate!(:issue => issue, :hours => 7.2) |
|
105 | 105 | |
|
106 | 106 | get :show, :params => {:id => version.id} |
|
107 | 107 | assert_response :success |
|
108 | 108 | |
|
109 | 109 | assert_select '.total-hours', :text => '7.20 hours' |
|
110 | 110 | assert_select '.total-hours a[href=?]', "/projects/ecookbook/time_entries?issue.fixed_version_id=#{version.id}&set_filter=1" |
|
111 | 111 | end |
|
112 | 112 | |
|
113 | 113 | def test_show_should_display_nil_counts |
|
114 | 114 | with_settings :default_language => 'en' do |
|
115 | 115 | get :show, :params => {:id => 2, :status_by => 'category'} |
|
116 | 116 | assert_response :success |
|
117 | 117 | assert_select 'div#status_by' do |
|
118 | 118 | assert_select 'select[name=status_by]' do |
|
119 | 119 | assert_select 'option[value=category][selected=selected]' |
|
120 | 120 | end |
|
121 | 121 | assert_select 'a', :text => 'none' |
|
122 | 122 | end |
|
123 | 123 | end |
|
124 | 124 | end |
|
125 | 125 | |
|
126 | 126 | def test_new |
|
127 | 127 | @request.session[:user_id] = 2 |
|
128 | 128 | get :new, :params => {:project_id => '1'} |
|
129 | 129 | assert_response :success |
|
130 | 130 | assert_select 'input[name=?]', 'version[name]' |
|
131 | assert_select 'select[name=?]', 'version[status]', false | |
|
131 | 132 | end |
|
132 | 133 | |
|
133 | 134 | def test_new_from_issue_form |
|
134 | 135 | @request.session[:user_id] = 2 |
|
135 | 136 | xhr :get, :new, :params => {:project_id => '1'} |
|
136 | 137 | assert_response :success |
|
137 | 138 | assert_equal 'text/javascript', response.content_type |
|
138 | 139 | end |
|
139 | 140 | |
|
140 | 141 | def test_create |
|
141 | 142 | @request.session[:user_id] = 2 # manager |
|
142 | 143 | assert_difference 'Version.count' do |
|
143 | 144 | post :create, :params => {:project_id => '1', :version => {:name => 'test_add_version'}} |
|
144 | 145 | end |
|
145 | 146 | assert_redirected_to '/projects/ecookbook/settings/versions' |
|
146 | 147 | version = Version.find_by_name('test_add_version') |
|
147 | 148 | assert_not_nil version |
|
148 | 149 | assert_equal 1, version.project_id |
|
149 | 150 | end |
|
150 | 151 | |
|
151 | 152 | def test_create_from_issue_form |
|
152 | 153 | @request.session[:user_id] = 2 |
|
153 | 154 | assert_difference 'Version.count' do |
|
154 | 155 | xhr :post, :create, :params => {:project_id => '1', :version => {:name => 'test_add_version_from_issue_form'}} |
|
155 | 156 | end |
|
156 | 157 | version = Version.find_by_name('test_add_version_from_issue_form') |
|
157 | 158 | assert_not_nil version |
|
158 | 159 | assert_equal 1, version.project_id |
|
159 | 160 | |
|
160 | 161 | assert_response :success |
|
161 | 162 | assert_equal 'text/javascript', response.content_type |
|
162 | 163 | assert_include 'test_add_version_from_issue_form', response.body |
|
163 | 164 | end |
|
164 | 165 | |
|
165 | 166 | def test_create_from_issue_form_with_failure |
|
166 | 167 | @request.session[:user_id] = 2 |
|
167 | 168 | assert_no_difference 'Version.count' do |
|
168 | 169 | xhr :post, :create, :params => {:project_id => '1', :version => {:name => ''}} |
|
169 | 170 | end |
|
170 | 171 | assert_response :success |
|
171 | 172 | assert_equal 'text/javascript', response.content_type |
|
172 | 173 | end |
|
173 | 174 | |
|
174 | 175 | def test_get_edit |
|
175 | 176 | @request.session[:user_id] = 2 |
|
176 | 177 | get :edit, :params => {:id => 2} |
|
177 | 178 | assert_response :success |
|
178 | assert_select 'input[name=?][value=?]', 'version[name]', Version.find(2).name | |
|
179 | version = Version.find(2) | |
|
180 | ||
|
181 | assert_select 'select[name=?]', 'version[status]' do | |
|
182 | assert_select 'option[value=?][selected="selected"]', version.status | |
|
183 | end | |
|
184 | assert_select 'input[name=?][value=?]', 'version[name]', version.name | |
|
179 | 185 | end |
|
180 | 186 | |
|
181 | 187 | def test_close_completed |
|
182 | 188 | Version.update_all("status = 'open'") |
|
183 | 189 | @request.session[:user_id] = 2 |
|
184 | 190 | put :close_completed, :params => {:project_id => 'ecookbook'} |
|
185 | 191 | assert_redirected_to :controller => 'projects', :action => 'settings', |
|
186 | 192 | :tab => 'versions', :id => 'ecookbook' |
|
187 | 193 | assert_not_nil Version.find_by_status('closed') |
|
188 | 194 | end |
|
189 | 195 | |
|
190 | 196 | def test_post_update |
|
191 | 197 | @request.session[:user_id] = 2 |
|
192 | 198 | put :update, :params => { |
|
193 |
:id => 2, |
|
|
199 | :id => 2, | |
|
194 | 200 | :version => { |
|
195 | 201 | :name => 'New version name', |
|
196 | 202 | :effective_date => Date.today.strftime("%Y-%m-%d") |
|
197 | 203 | } |
|
198 | 204 | } |
|
199 | 205 | assert_redirected_to :controller => 'projects', :action => 'settings', |
|
200 | 206 | :tab => 'versions', :id => 'ecookbook' |
|
201 | 207 | version = Version.find(2) |
|
202 | 208 | assert_equal 'New version name', version.name |
|
203 | 209 | assert_equal Date.today, version.effective_date |
|
204 | 210 | end |
|
205 | 211 | |
|
206 | 212 | def test_post_update_with_validation_failure |
|
207 | 213 | @request.session[:user_id] = 2 |
|
208 | 214 | put :update, :params => { |
|
209 | 215 | :id => 2, |
|
210 | 216 | :version => { |
|
211 | 217 | :name => '', |
|
212 | 218 | :effective_date => Date.today.strftime("%Y-%m-%d") |
|
213 | 219 | } |
|
214 | 220 | } |
|
215 | 221 | assert_response :success |
|
216 | 222 | assert_select_error /Name cannot be blank/ |
|
217 | 223 | end |
|
218 | 224 | |
|
219 | 225 | def test_destroy |
|
220 | 226 | @request.session[:user_id] = 2 |
|
221 | 227 | assert_difference 'Version.count', -1 do |
|
222 | 228 | delete :destroy, :params => {:id => 3} |
|
223 | 229 | end |
|
224 | 230 | assert_redirected_to :controller => 'projects', :action => 'settings', |
|
225 | 231 | :tab => 'versions', :id => 'ecookbook' |
|
226 | 232 | assert_nil Version.find_by_id(3) |
|
227 | 233 | end |
|
228 | 234 | |
|
229 | 235 | def test_destroy_version_in_use_should_fail |
|
230 | 236 | @request.session[:user_id] = 2 |
|
231 | 237 | assert_no_difference 'Version.count' do |
|
232 | 238 | delete :destroy, :params => {:id => 2} |
|
233 | 239 | end |
|
234 | 240 | assert_redirected_to :controller => 'projects', :action => 'settings', |
|
235 | 241 | :tab => 'versions', :id => 'ecookbook' |
|
236 | 242 | assert flash[:error].match(/Unable to delete version/) |
|
237 | 243 | assert Version.find_by_id(2) |
|
238 | 244 | end |
|
239 | 245 | |
|
240 | 246 | def test_issue_status_by |
|
241 | 247 | xhr :get, :status_by, :params => {:id => 2} |
|
242 | 248 | assert_response :success |
|
243 | 249 | end |
|
244 | 250 | |
|
245 | 251 | def test_issue_status_by_status |
|
246 | 252 | xhr :get, :status_by, :params => {:id => 2, :status_by => 'status'} |
|
247 | 253 | assert_response :success |
|
248 | 254 | assert_include 'Assigned', response.body |
|
249 | 255 | assert_include 'Closed', response.body |
|
250 | 256 | end |
|
251 | 257 | end |
General Comments 0
You need to be logged in to leave comments.
Login now