@@ -1,56 +1,57 | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | # |
|
3 | 3 | # Redmine - project management software |
|
4 | 4 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
5 | 5 | # |
|
6 | 6 | # This program is free software; you can redistribute it and/or |
|
7 | 7 | # modify it under the terms of the GNU General Public License |
|
8 | 8 | # as published by the Free Software Foundation; either version 2 |
|
9 | 9 | # of the License, or (at your option) any later version. |
|
10 | 10 | # |
|
11 | 11 | # This program is distributed in the hope that it will be useful, |
|
12 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 | 14 | # GNU General Public License for more details. |
|
15 | 15 | # |
|
16 | 16 | # You should have received a copy of the GNU General Public License |
|
17 | 17 | # along with this program; if not, write to the Free Software |
|
18 | 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 | 19 | |
|
20 | 20 | module VersionsHelper |
|
21 | 21 | |
|
22 | 22 | def version_anchor(version) |
|
23 | 23 | if @project == version.project |
|
24 | 24 | anchor version.name |
|
25 | 25 | else |
|
26 | 26 | anchor "#{version.project.try(:identifier)}-#{version.name}" |
|
27 | 27 | end |
|
28 | 28 | end |
|
29 | 29 | |
|
30 | 30 | STATUS_BY_CRITERIAS = %w(tracker status priority author assigned_to category) |
|
31 | 31 | |
|
32 | 32 | def render_issue_status_by(version, criteria) |
|
33 | 33 | criteria = 'tracker' unless STATUS_BY_CRITERIAS.include?(criteria) |
|
34 | 34 | |
|
35 | 35 | h = Hash.new {|k,v| k[v] = [0, 0]} |
|
36 | 36 | begin |
|
37 | 37 | # Total issue count |
|
38 | 38 | Issue.count(:group => criteria, |
|
39 | 39 | :conditions => ["#{Issue.table_name}.fixed_version_id = ?", version.id]).each {|c,s| h[c][0] = s} |
|
40 | 40 | # Open issues count |
|
41 | 41 | Issue.count(:group => criteria, |
|
42 | 42 | :include => :status, |
|
43 | 43 | :conditions => ["#{Issue.table_name}.fixed_version_id = ? AND #{IssueStatus.table_name}.is_closed = ?", version.id, false]).each {|c,s| h[c][1] = s} |
|
44 | 44 | rescue ActiveRecord::RecordNotFound |
|
45 | 45 | # When grouping by an association, Rails throws this exception if there's no result (bug) |
|
46 | 46 | end |
|
47 | counts = h.keys.compact.sort.collect {|k| {:group => k, :total => h[k][0], :open => h[k][1], :closed => (h[k][0] - h[k][1])}} | |
|
47 | # Sort with nil keys in last position | |
|
48 | counts = h.keys.sort {|a,b| a.nil? ? 1 : (b.nil? ? -1 : a <=> b)}.collect {|k| {:group => k, :total => h[k][0], :open => h[k][1], :closed => (h[k][0] - h[k][1])}} | |
|
48 | 49 | max = counts.collect {|c| c[:total]}.max |
|
49 | 50 | |
|
50 | 51 | render :partial => 'issue_counts', :locals => {:version => version, :criteria => criteria, :counts => counts, :max => max} |
|
51 | 52 | end |
|
52 | 53 | |
|
53 | 54 | def status_by_options_for_select(value) |
|
54 | 55 | options_for_select(STATUS_BY_CRITERIAS.collect {|criteria| [l("field_#{criteria}".to_sym), criteria]}, value) |
|
55 | 56 | end |
|
56 | 57 | end |
@@ -1,34 +1,33 | |||
|
1 | 1 | <%= form_tag({}, :id => "status_by_form") do -%> |
|
2 | 2 | <fieldset> |
|
3 | 3 | <legend> |
|
4 | 4 | <%= l(:label_issues_by, |
|
5 | 5 | select_tag('status_by', |
|
6 | 6 | status_by_options_for_select(criteria), |
|
7 | 7 | :id => 'status_by_select', |
|
8 | 8 | :data => {:remote => true, :method => 'post', :url => status_by_version_path(version)})).html_safe %> |
|
9 | 9 | </legend> |
|
10 | 10 | <% if counts.empty? %> |
|
11 | 11 | <p><em><%= l(:label_no_data) %></em></p> |
|
12 | 12 | <% else %> |
|
13 | 13 | <table> |
|
14 | 14 | <% counts.each do |count| %> |
|
15 | 15 | <tr> |
|
16 | 16 | <td width="130px" align="right" > |
|
17 | <%= link_to h(count[:group]), {:controller => 'issues', | |
|
18 | :action => 'index', | |
|
19 | :project_id => version.project, | |
|
20 | :set_filter => 1, | |
|
21 | :status_id => '*', | |
|
22 | :fixed_version_id => version}.merge("#{criteria}_id".to_sym => count[:group]) %> | |
|
17 | <% if count[:group] -%> | |
|
18 | <%= link_to(h(count[:group]), project_issues_path(version.project, :set_filter => 1, :status_id => '*', :fixed_version_id => version, "#{criteria}_id" => count[:group])) %> | |
|
19 | <% else -%> | |
|
20 | <%= link_to(l(:label_none), project_issues_path(version.project, :set_filter => 1, :status_id => '*', :fixed_version_id => version, "#{criteria}_id" => "!*")) %> | |
|
21 | <% end %> | |
|
23 | 22 | </td> |
|
24 | 23 | <td width="240px"> |
|
25 | 24 | <%= progress_bar((count[:closed].to_f / count[:total])*100, |
|
26 | 25 | :legend => "#{count[:closed]}/#{count[:total]}", |
|
27 | 26 | :width => "#{(count[:total].to_f / max * 200).floor}px;") %> |
|
28 | 27 | </td> |
|
29 | 28 | </tr> |
|
30 | 29 | <% end %> |
|
31 | 30 | </table> |
|
32 | 31 | <% end %> |
|
33 | 32 | </fieldset> |
|
34 | 33 | <% end %> |
@@ -1,226 +1,239 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2012 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 | require 'versions_controller' |
|
20 | 20 | |
|
21 | 21 | # Re-raise errors caught by the controller. |
|
22 | 22 | class VersionsController; def rescue_action(e) raise e end; end |
|
23 | 23 | |
|
24 | 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 | 27 | def setup |
|
28 | 28 | @controller = VersionsController.new |
|
29 | 29 | @request = ActionController::TestRequest.new |
|
30 | 30 | @response = ActionController::TestResponse.new |
|
31 | 31 | User.current = nil |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | def test_index |
|
35 | 35 | get :index, :project_id => 1 |
|
36 | 36 | assert_response :success |
|
37 | 37 | assert_template 'index' |
|
38 | 38 | assert_not_nil assigns(:versions) |
|
39 | 39 | # Version with no date set appears |
|
40 | 40 | assert assigns(:versions).include?(Version.find(3)) |
|
41 | 41 | # Completed version doesn't appear |
|
42 | 42 | assert !assigns(:versions).include?(Version.find(1)) |
|
43 | 43 | # Context menu on issues |
|
44 | 44 | assert_select "script", :text => Regexp.new(Regexp.escape("contextMenuInit('/issues/context_menu')")) |
|
45 | 45 | # Links to versions anchors |
|
46 | 46 | assert_tag 'a', :attributes => {:href => '#2.0'}, |
|
47 | 47 | :ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}} |
|
48 | 48 | # Links to completed versions in the sidebar |
|
49 | 49 | assert_tag 'a', :attributes => {:href => '/versions/1'}, |
|
50 | 50 | :ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}} |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | def test_index_with_completed_versions |
|
54 | 54 | get :index, :project_id => 1, :completed => 1 |
|
55 | 55 | assert_response :success |
|
56 | 56 | assert_template 'index' |
|
57 | 57 | assert_not_nil assigns(:versions) |
|
58 | 58 | # Version with no date set appears |
|
59 | 59 | assert assigns(:versions).include?(Version.find(3)) |
|
60 | 60 | # Completed version appears |
|
61 | 61 | assert assigns(:versions).include?(Version.find(1)) |
|
62 | 62 | end |
|
63 | 63 | |
|
64 | 64 | def test_index_with_tracker_ids |
|
65 | 65 | get :index, :project_id => 1, :tracker_ids => [1, 3] |
|
66 | 66 | assert_response :success |
|
67 | 67 | assert_template 'index' |
|
68 | 68 | assert_not_nil assigns(:issues_by_version) |
|
69 | 69 | assert_nil assigns(:issues_by_version).values.flatten.detect {|issue| issue.tracker_id == 2} |
|
70 | 70 | end |
|
71 | 71 | |
|
72 | 72 | def test_index_showing_subprojects_versions |
|
73 | 73 | @subproject_version = Version.create!(:project => Project.find(3), :name => "Subproject version") |
|
74 | 74 | get :index, :project_id => 1, :with_subprojects => 1 |
|
75 | 75 | assert_response :success |
|
76 | 76 | assert_template 'index' |
|
77 | 77 | assert_not_nil assigns(:versions) |
|
78 | 78 | |
|
79 | 79 | assert assigns(:versions).include?(Version.find(4)), "Shared version not found" |
|
80 | 80 | assert assigns(:versions).include?(@subproject_version), "Subproject version not found" |
|
81 | 81 | end |
|
82 | 82 | |
|
83 | 83 | def test_index_should_prepend_shared_versions |
|
84 | 84 | get :index, :project_id => 1 |
|
85 | 85 | assert_response :success |
|
86 | 86 | |
|
87 | 87 | assert_select '#sidebar' do |
|
88 | 88 | assert_select 'a[href=?]', '#2.0', :text => '2.0' |
|
89 | 89 | assert_select 'a[href=?]', '#subproject1-2.0', :text => 'eCookbook Subproject 1 - 2.0' |
|
90 | 90 | end |
|
91 | 91 | assert_select '#content' do |
|
92 | 92 | assert_select 'a[name=?]', '2.0', :text => '2.0' |
|
93 | 93 | assert_select 'a[name=?]', 'subproject1-2.0', :text => 'eCookbook Subproject 1 - 2.0' |
|
94 | 94 | end |
|
95 | 95 | end |
|
96 | 96 | |
|
97 | 97 | def test_show |
|
98 | 98 | get :show, :id => 2 |
|
99 | 99 | assert_response :success |
|
100 | 100 | assert_template 'show' |
|
101 | 101 | assert_not_nil assigns(:version) |
|
102 | 102 | |
|
103 | 103 | assert_tag :tag => 'h2', :content => /1.0/ |
|
104 | 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 | 119 | def test_new |
|
107 | 120 | @request.session[:user_id] = 2 |
|
108 | 121 | get :new, :project_id => '1' |
|
109 | 122 | assert_response :success |
|
110 | 123 | assert_template 'new' |
|
111 | 124 | end |
|
112 | 125 | |
|
113 | 126 | def test_new_from_issue_form |
|
114 | 127 | @request.session[:user_id] = 2 |
|
115 | 128 | xhr :get, :new, :project_id => '1' |
|
116 | 129 | assert_response :success |
|
117 | 130 | assert_template 'new' |
|
118 | 131 | assert_equal 'text/javascript', response.content_type |
|
119 | 132 | end |
|
120 | 133 | |
|
121 | 134 | def test_create |
|
122 | 135 | @request.session[:user_id] = 2 # manager |
|
123 | 136 | assert_difference 'Version.count' do |
|
124 | 137 | post :create, :project_id => '1', :version => {:name => 'test_add_version'} |
|
125 | 138 | end |
|
126 | 139 | assert_redirected_to '/projects/ecookbook/settings/versions' |
|
127 | 140 | version = Version.find_by_name('test_add_version') |
|
128 | 141 | assert_not_nil version |
|
129 | 142 | assert_equal 1, version.project_id |
|
130 | 143 | end |
|
131 | 144 | |
|
132 | 145 | def test_create_from_issue_form |
|
133 | 146 | @request.session[:user_id] = 2 |
|
134 | 147 | assert_difference 'Version.count' do |
|
135 | 148 | xhr :post, :create, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'} |
|
136 | 149 | end |
|
137 | 150 | version = Version.find_by_name('test_add_version_from_issue_form') |
|
138 | 151 | assert_not_nil version |
|
139 | 152 | assert_equal 1, version.project_id |
|
140 | 153 | |
|
141 | 154 | assert_response :success |
|
142 | 155 | assert_template 'create' |
|
143 | 156 | assert_equal 'text/javascript', response.content_type |
|
144 | 157 | assert_include 'test_add_version_from_issue_form', response.body |
|
145 | 158 | end |
|
146 | 159 | |
|
147 | 160 | def test_create_from_issue_form_with_failure |
|
148 | 161 | @request.session[:user_id] = 2 |
|
149 | 162 | assert_no_difference 'Version.count' do |
|
150 | 163 | xhr :post, :create, :project_id => '1', :version => {:name => ''} |
|
151 | 164 | end |
|
152 | 165 | assert_response :success |
|
153 | 166 | assert_template 'new' |
|
154 | 167 | assert_equal 'text/javascript', response.content_type |
|
155 | 168 | end |
|
156 | 169 | |
|
157 | 170 | def test_get_edit |
|
158 | 171 | @request.session[:user_id] = 2 |
|
159 | 172 | get :edit, :id => 2 |
|
160 | 173 | assert_response :success |
|
161 | 174 | assert_template 'edit' |
|
162 | 175 | end |
|
163 | 176 | |
|
164 | 177 | def test_close_completed |
|
165 | 178 | Version.update_all("status = 'open'") |
|
166 | 179 | @request.session[:user_id] = 2 |
|
167 | 180 | put :close_completed, :project_id => 'ecookbook' |
|
168 | 181 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
169 | 182 | assert_not_nil Version.find_by_status('closed') |
|
170 | 183 | end |
|
171 | 184 | |
|
172 | 185 | def test_post_update |
|
173 | 186 | @request.session[:user_id] = 2 |
|
174 | 187 | put :update, :id => 2, |
|
175 | 188 | :version => { :name => 'New version name', |
|
176 | 189 | :effective_date => Date.today.strftime("%Y-%m-%d")} |
|
177 | 190 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
178 | 191 | version = Version.find(2) |
|
179 | 192 | assert_equal 'New version name', version.name |
|
180 | 193 | assert_equal Date.today, version.effective_date |
|
181 | 194 | end |
|
182 | 195 | |
|
183 | 196 | def test_post_update_with_validation_failure |
|
184 | 197 | @request.session[:user_id] = 2 |
|
185 | 198 | put :update, :id => 2, |
|
186 | 199 | :version => { :name => '', |
|
187 | 200 | :effective_date => Date.today.strftime("%Y-%m-%d")} |
|
188 | 201 | assert_response :success |
|
189 | 202 | assert_template 'edit' |
|
190 | 203 | end |
|
191 | 204 | |
|
192 | 205 | def test_destroy |
|
193 | 206 | @request.session[:user_id] = 2 |
|
194 | 207 | assert_difference 'Version.count', -1 do |
|
195 | 208 | delete :destroy, :id => 3 |
|
196 | 209 | end |
|
197 | 210 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
198 | 211 | assert_nil Version.find_by_id(3) |
|
199 | 212 | end |
|
200 | 213 | |
|
201 | 214 | def test_destroy_version_in_use_should_fail |
|
202 | 215 | @request.session[:user_id] = 2 |
|
203 | 216 | assert_no_difference 'Version.count' do |
|
204 | 217 | delete :destroy, :id => 2 |
|
205 | 218 | end |
|
206 | 219 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
207 | 220 | assert flash[:error].match(/Unable to delete version/) |
|
208 | 221 | assert Version.find_by_id(2) |
|
209 | 222 | end |
|
210 | 223 | |
|
211 | 224 | def test_issue_status_by |
|
212 | 225 | xhr :get, :status_by, :id => 2 |
|
213 | 226 | assert_response :success |
|
214 | 227 | assert_template 'status_by' |
|
215 | 228 | assert_template '_issue_counts' |
|
216 | 229 | end |
|
217 | 230 | |
|
218 | 231 | def test_issue_status_by_status |
|
219 | 232 | xhr :get, :status_by, :id => 2, :status_by => 'status' |
|
220 | 233 | assert_response :success |
|
221 | 234 | assert_template 'status_by' |
|
222 | 235 | assert_template '_issue_counts' |
|
223 | 236 | assert_include 'Assigned', response.body |
|
224 | 237 | assert_include 'Closed', response.body |
|
225 | 238 | end |
|
226 | 239 | end |
General Comments 0
You need to be logged in to leave comments.
Login now