@@ -1,48 +1,56 | |||
|
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 | def version_anchor(version) | |
|
23 | if @project == version.project | |
|
24 | anchor version.name | |
|
25 | else | |
|
26 | anchor "#{version.project.try(:identifier)}-#{version.name}" | |
|
27 | end | |
|
28 | end | |
|
29 | ||
|
22 | 30 | STATUS_BY_CRITERIAS = %w(tracker status priority author assigned_to category) |
|
23 | 31 | |
|
24 | 32 | def render_issue_status_by(version, criteria) |
|
25 | 33 | criteria = 'tracker' unless STATUS_BY_CRITERIAS.include?(criteria) |
|
26 | 34 | |
|
27 | 35 | h = Hash.new {|k,v| k[v] = [0, 0]} |
|
28 | 36 | begin |
|
29 | 37 | # Total issue count |
|
30 | 38 | Issue.count(:group => criteria, |
|
31 | 39 | :conditions => ["#{Issue.table_name}.fixed_version_id = ?", version.id]).each {|c,s| h[c][0] = s} |
|
32 | 40 | # Open issues count |
|
33 | 41 | Issue.count(:group => criteria, |
|
34 | 42 | :include => :status, |
|
35 | 43 | :conditions => ["#{Issue.table_name}.fixed_version_id = ? AND #{IssueStatus.table_name}.is_closed = ?", version.id, false]).each {|c,s| h[c][1] = s} |
|
36 | 44 | rescue ActiveRecord::RecordNotFound |
|
37 | 45 | # When grouping by an association, Rails throws this exception if there's no result (bug) |
|
38 | 46 | end |
|
39 | 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])}} |
|
40 | 48 | max = counts.collect {|c| c[:total]}.max |
|
41 | 49 | |
|
42 | 50 | render :partial => 'issue_counts', :locals => {:version => version, :criteria => criteria, :counts => counts, :max => max} |
|
43 | 51 | end |
|
44 | 52 | |
|
45 | 53 | def status_by_options_for_select(value) |
|
46 | 54 | options_for_select(STATUS_BY_CRITERIAS.collect {|criteria| [l("field_#{criteria}".to_sym), criteria]}, value) |
|
47 | 55 | end |
|
48 | 56 | end |
@@ -1,68 +1,68 | |||
|
1 | 1 | <div class="contextual"> |
|
2 | 2 | <%= link_to l(:label_version_new), new_project_version_path(@project), :class => 'icon icon-add' if User.current.allowed_to?(:manage_versions, @project) %> |
|
3 | 3 | </div> |
|
4 | 4 | |
|
5 | 5 | <h2><%=l(:label_roadmap)%></h2> |
|
6 | 6 | |
|
7 | 7 | <% if @versions.empty? %> |
|
8 | 8 | <p class="nodata"><%= l(:label_no_data) %></p> |
|
9 | 9 | <% else %> |
|
10 | 10 | <div id="roadmap"> |
|
11 | 11 | <% @versions.each do |version| %> |
|
12 |
<h3 class="version"><%= link_to_version version, :name => anchor(version |
|
|
12 | <h3 class="version"><%= link_to_version version, :name => version_anchor(version) %></h3> | |
|
13 | 13 | <%= render :partial => 'versions/overview', :locals => {:version => version} %> |
|
14 | 14 | <%= render(:partial => "wiki/content", :locals => {:content => version.wiki_page.content}) if version.wiki_page %> |
|
15 | 15 | |
|
16 | 16 | <% if (issues = @issues_by_version[version]) && issues.size > 0 %> |
|
17 | 17 | <%= form_tag({}) do -%> |
|
18 | 18 | <table class="list related-issues"> |
|
19 | 19 | <caption><%= l(:label_related_issues) %></caption> |
|
20 | 20 | <% issues.each do |issue| -%> |
|
21 | 21 | <tr class="hascontextmenu"> |
|
22 | 22 | <td class="checkbox"><%= check_box_tag 'ids[]', issue.id, false, :id => nil %></td> |
|
23 | 23 | <td><%= link_to_issue(issue, :project => (@project != issue.project)) %></td> |
|
24 | 24 | </tr> |
|
25 | 25 | <% end -%> |
|
26 | 26 | </table> |
|
27 | 27 | <% end %> |
|
28 | 28 | <% end %> |
|
29 | 29 | <%= call_hook :view_projects_roadmap_version_bottom, :version => version %> |
|
30 | 30 | <% end %> |
|
31 | 31 | </div> |
|
32 | 32 | <% end %> |
|
33 | 33 | |
|
34 | 34 | <% content_for :sidebar do %> |
|
35 | 35 | <%= form_tag({}, :method => :get) do %> |
|
36 | 36 | <h3><%= l(:label_roadmap) %></h3> |
|
37 | 37 | <% @trackers.each do |tracker| %> |
|
38 | 38 | <label><%= check_box_tag "tracker_ids[]", tracker.id, (@selected_tracker_ids.include? tracker.id.to_s), :id => nil %> |
|
39 | 39 | <%=h tracker.name %></label><br /> |
|
40 | 40 | <% end %> |
|
41 | 41 | <br /> |
|
42 | 42 | <label for="completed"><%= check_box_tag "completed", 1, params[:completed] %> <%= l(:label_show_completed_versions) %></label> |
|
43 | 43 | <% if @project.descendants.active.any? %> |
|
44 | 44 | <%= hidden_field_tag 'with_subprojects', 0 %> |
|
45 | 45 | <br /><label><%= check_box_tag 'with_subprojects', 1, @with_subprojects %> <%=l(:label_subproject_plural)%></label> |
|
46 | 46 | <% end %> |
|
47 | 47 | <p><%= submit_tag l(:button_apply), :class => 'button-small', :name => nil %></p> |
|
48 | 48 | <% end %> |
|
49 | 49 | |
|
50 | 50 | <h3><%= l(:label_version_plural) %></h3> |
|
51 | 51 | <% @versions.each do |version| %> |
|
52 |
<%= link_to format_version_name(version), "##{anchor(version |
|
|
52 | <%= link_to format_version_name(version), "##{version_anchor(version)}" %><br /> | |
|
53 | 53 | <% end %> |
|
54 | 54 | <% if @completed_versions.present? %> |
|
55 | 55 | <p> |
|
56 | 56 | <%= link_to_function l(:label_completed_versions), |
|
57 | 57 | '$("#toggle-completed-versions").toggleClass("collapsed"); $("#completed-versions").toggle()', |
|
58 | 58 | :id => 'toggle-completed-versions', :class => 'collapsible collapsed' %><br /> |
|
59 | 59 | <span id="completed-versions" style="display:none;"> |
|
60 | 60 | <%= @completed_versions.map {|version| link_to format_version_name(version), version_path(version)}.join("<br />\n").html_safe %> |
|
61 | 61 | </span> |
|
62 | 62 | </p> |
|
63 | 63 | <% end %> |
|
64 | 64 | <% end %> |
|
65 | 65 | |
|
66 | 66 | <% html_title(l(:label_roadmap)) %> |
|
67 | 67 | |
|
68 | 68 | <%= context_menu issues_context_menu_path %> |
@@ -1,212 +1,226 | |||
|
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 | 25 | fixtures :projects, :versions, :issues, :users, :roles, :members, :member_roles, :enabled_modules, :issue_statuses |
|
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 | def test_index_should_prepend_shared_versions | |
|
84 | get :index, :project_id => 1 | |
|
85 | assert_response :success | |
|
86 | ||
|
87 | assert_select '#sidebar' do | |
|
88 | assert_select 'a[href=?]', '#2.0', :text => '2.0' | |
|
89 | assert_select 'a[href=?]', '#subproject1-2.0', :text => 'eCookbook Subproject 1 - 2.0' | |
|
90 | end | |
|
91 | assert_select '#content' do | |
|
92 | assert_select 'a[name=?]', '2.0', :text => '2.0' | |
|
93 | assert_select 'a[name=?]', 'subproject1-2.0', :text => 'eCookbook Subproject 1 - 2.0' | |
|
94 | end | |
|
95 | end | |
|
96 | ||
|
83 | 97 | def test_show |
|
84 | 98 | get :show, :id => 2 |
|
85 | 99 | assert_response :success |
|
86 | 100 | assert_template 'show' |
|
87 | 101 | assert_not_nil assigns(:version) |
|
88 | 102 | |
|
89 | 103 | assert_tag :tag => 'h2', :content => /1.0/ |
|
90 | 104 | end |
|
91 | 105 | |
|
92 | 106 | def test_new |
|
93 | 107 | @request.session[:user_id] = 2 |
|
94 | 108 | get :new, :project_id => '1' |
|
95 | 109 | assert_response :success |
|
96 | 110 | assert_template 'new' |
|
97 | 111 | end |
|
98 | 112 | |
|
99 | 113 | def test_new_from_issue_form |
|
100 | 114 | @request.session[:user_id] = 2 |
|
101 | 115 | xhr :get, :new, :project_id => '1' |
|
102 | 116 | assert_response :success |
|
103 | 117 | assert_template 'new' |
|
104 | 118 | assert_equal 'text/javascript', response.content_type |
|
105 | 119 | end |
|
106 | 120 | |
|
107 | 121 | def test_create |
|
108 | 122 | @request.session[:user_id] = 2 # manager |
|
109 | 123 | assert_difference 'Version.count' do |
|
110 | 124 | post :create, :project_id => '1', :version => {:name => 'test_add_version'} |
|
111 | 125 | end |
|
112 | 126 | assert_redirected_to '/projects/ecookbook/settings/versions' |
|
113 | 127 | version = Version.find_by_name('test_add_version') |
|
114 | 128 | assert_not_nil version |
|
115 | 129 | assert_equal 1, version.project_id |
|
116 | 130 | end |
|
117 | 131 | |
|
118 | 132 | def test_create_from_issue_form |
|
119 | 133 | @request.session[:user_id] = 2 |
|
120 | 134 | assert_difference 'Version.count' do |
|
121 | 135 | xhr :post, :create, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'} |
|
122 | 136 | end |
|
123 | 137 | version = Version.find_by_name('test_add_version_from_issue_form') |
|
124 | 138 | assert_not_nil version |
|
125 | 139 | assert_equal 1, version.project_id |
|
126 | 140 | |
|
127 | 141 | assert_response :success |
|
128 | 142 | assert_template 'create' |
|
129 | 143 | assert_equal 'text/javascript', response.content_type |
|
130 | 144 | assert_include 'test_add_version_from_issue_form', response.body |
|
131 | 145 | end |
|
132 | 146 | |
|
133 | 147 | def test_create_from_issue_form_with_failure |
|
134 | 148 | @request.session[:user_id] = 2 |
|
135 | 149 | assert_no_difference 'Version.count' do |
|
136 | 150 | xhr :post, :create, :project_id => '1', :version => {:name => ''} |
|
137 | 151 | end |
|
138 | 152 | assert_response :success |
|
139 | 153 | assert_template 'new' |
|
140 | 154 | assert_equal 'text/javascript', response.content_type |
|
141 | 155 | end |
|
142 | 156 | |
|
143 | 157 | def test_get_edit |
|
144 | 158 | @request.session[:user_id] = 2 |
|
145 | 159 | get :edit, :id => 2 |
|
146 | 160 | assert_response :success |
|
147 | 161 | assert_template 'edit' |
|
148 | 162 | end |
|
149 | 163 | |
|
150 | 164 | def test_close_completed |
|
151 | 165 | Version.update_all("status = 'open'") |
|
152 | 166 | @request.session[:user_id] = 2 |
|
153 | 167 | put :close_completed, :project_id => 'ecookbook' |
|
154 | 168 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
155 | 169 | assert_not_nil Version.find_by_status('closed') |
|
156 | 170 | end |
|
157 | 171 | |
|
158 | 172 | def test_post_update |
|
159 | 173 | @request.session[:user_id] = 2 |
|
160 | 174 | put :update, :id => 2, |
|
161 | 175 | :version => { :name => 'New version name', |
|
162 | 176 | :effective_date => Date.today.strftime("%Y-%m-%d")} |
|
163 | 177 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
164 | 178 | version = Version.find(2) |
|
165 | 179 | assert_equal 'New version name', version.name |
|
166 | 180 | assert_equal Date.today, version.effective_date |
|
167 | 181 | end |
|
168 | 182 | |
|
169 | 183 | def test_post_update_with_validation_failure |
|
170 | 184 | @request.session[:user_id] = 2 |
|
171 | 185 | put :update, :id => 2, |
|
172 | 186 | :version => { :name => '', |
|
173 | 187 | :effective_date => Date.today.strftime("%Y-%m-%d")} |
|
174 | 188 | assert_response :success |
|
175 | 189 | assert_template 'edit' |
|
176 | 190 | end |
|
177 | 191 | |
|
178 | 192 | def test_destroy |
|
179 | 193 | @request.session[:user_id] = 2 |
|
180 | 194 | assert_difference 'Version.count', -1 do |
|
181 | 195 | delete :destroy, :id => 3 |
|
182 | 196 | end |
|
183 | 197 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
184 | 198 | assert_nil Version.find_by_id(3) |
|
185 | 199 | end |
|
186 | 200 | |
|
187 | 201 | def test_destroy_version_in_use_should_fail |
|
188 | 202 | @request.session[:user_id] = 2 |
|
189 | 203 | assert_no_difference 'Version.count' do |
|
190 | 204 | delete :destroy, :id => 2 |
|
191 | 205 | end |
|
192 | 206 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
193 | 207 | assert flash[:error].match(/Unable to delete version/) |
|
194 | 208 | assert Version.find_by_id(2) |
|
195 | 209 | end |
|
196 | 210 | |
|
197 | 211 | def test_issue_status_by |
|
198 | 212 | xhr :get, :status_by, :id => 2 |
|
199 | 213 | assert_response :success |
|
200 | 214 | assert_template 'status_by' |
|
201 | 215 | assert_template '_issue_counts' |
|
202 | 216 | end |
|
203 | 217 | |
|
204 | 218 | def test_issue_status_by_status |
|
205 | 219 | xhr :get, :status_by, :id => 2, :status_by => 'status' |
|
206 | 220 | assert_response :success |
|
207 | 221 | assert_template 'status_by' |
|
208 | 222 | assert_template '_issue_counts' |
|
209 | 223 | assert_include 'Assigned', response.body |
|
210 | 224 | assert_include 'Closed', response.body |
|
211 | 225 | end |
|
212 | 226 | end |
General Comments 0
You need to be logged in to leave comments.
Login now