##// END OF EJS Templates
Adds an option to view issues count by status on the version page (#7921)....
Jean-Philippe Lang -
r5059:e1ae0e977712
parent child
Show More
@@ -1,47 +1,47
1 # redMine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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 module VersionsHelper
18 module VersionsHelper
19
19
20 STATUS_BY_CRITERIAS = %w(category tracker priority author assigned_to)
20 STATUS_BY_CRITERIAS = %w(category tracker status priority author assigned_to)
21
21
22 def render_issue_status_by(version, criteria)
22 def render_issue_status_by(version, criteria)
23 criteria ||= 'category'
23 criteria ||= 'category'
24 raise 'Unknown criteria' unless STATUS_BY_CRITERIAS.include?(criteria)
24 raise 'Unknown criteria' unless STATUS_BY_CRITERIAS.include?(criteria)
25
25
26 h = Hash.new {|k,v| k[v] = [0, 0]}
26 h = Hash.new {|k,v| k[v] = [0, 0]}
27 begin
27 begin
28 # Total issue count
28 # Total issue count
29 Issue.count(:group => criteria,
29 Issue.count(:group => criteria,
30 :conditions => ["#{Issue.table_name}.fixed_version_id = ?", version.id]).each {|c,s| h[c][0] = s}
30 :conditions => ["#{Issue.table_name}.fixed_version_id = ?", version.id]).each {|c,s| h[c][0] = s}
31 # Open issues count
31 # Open issues count
32 Issue.count(:group => criteria,
32 Issue.count(:group => criteria,
33 :include => :status,
33 :include => :status,
34 :conditions => ["#{Issue.table_name}.fixed_version_id = ? AND #{IssueStatus.table_name}.is_closed = ?", version.id, false]).each {|c,s| h[c][1] = s}
34 :conditions => ["#{Issue.table_name}.fixed_version_id = ? AND #{IssueStatus.table_name}.is_closed = ?", version.id, false]).each {|c,s| h[c][1] = s}
35 rescue ActiveRecord::RecordNotFound
35 rescue ActiveRecord::RecordNotFound
36 # When grouping by an association, Rails throws this exception if there's no result (bug)
36 # When grouping by an association, Rails throws this exception if there's no result (bug)
37 end
37 end
38 counts = h.keys.compact.sort.collect {|k| {:group => k, :total => h[k][0], :open => h[k][1], :closed => (h[k][0] - h[k][1])}}
38 counts = h.keys.compact.sort.collect {|k| {:group => k, :total => h[k][0], :open => h[k][1], :closed => (h[k][0] - h[k][1])}}
39 max = counts.collect {|c| c[:total]}.max
39 max = counts.collect {|c| c[:total]}.max
40
40
41 render :partial => 'issue_counts', :locals => {:version => version, :criteria => criteria, :counts => counts, :max => max}
41 render :partial => 'issue_counts', :locals => {:version => version, :criteria => criteria, :counts => counts, :max => max}
42 end
42 end
43
43
44 def status_by_options_for_select(value)
44 def status_by_options_for_select(value)
45 options_for_select(STATUS_BY_CRITERIAS.collect {|criteria| [l("field_#{criteria}".to_sym), criteria]}, value)
45 options_for_select(STATUS_BY_CRITERIAS.collect {|criteria| [l("field_#{criteria}".to_sym), criteria]}, value)
46 end
46 end
47 end
47 end
@@ -1,148 +1,154
1 # redMine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 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
25 fixtures :projects, :versions, :issues, :users, :roles, :members, :member_roles, :enabled_modules, :issue_statuses
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("new ContextMenu('/issues/context_menu')"))
44 assert_select "script", :text => Regexp.new(Regexp.escape("new ContextMenu('/issues/context_menu')"))
45 end
45 end
46
46
47 def test_index_with_completed_versions
47 def test_index_with_completed_versions
48 get :index, :project_id => 1, :completed => 1
48 get :index, :project_id => 1, :completed => 1
49 assert_response :success
49 assert_response :success
50 assert_template 'index'
50 assert_template 'index'
51 assert_not_nil assigns(:versions)
51 assert_not_nil assigns(:versions)
52 # Version with no date set appears
52 # Version with no date set appears
53 assert assigns(:versions).include?(Version.find(3))
53 assert assigns(:versions).include?(Version.find(3))
54 # Completed version appears
54 # Completed version appears
55 assert assigns(:versions).include?(Version.find(1))
55 assert assigns(:versions).include?(Version.find(1))
56 end
56 end
57
57
58 def test_index_showing_subprojects_versions
58 def test_index_showing_subprojects_versions
59 @subproject_version = Version.generate!(:project => Project.find(3))
59 @subproject_version = Version.generate!(:project => Project.find(3))
60 get :index, :project_id => 1, :with_subprojects => 1
60 get :index, :project_id => 1, :with_subprojects => 1
61 assert_response :success
61 assert_response :success
62 assert_template 'index'
62 assert_template 'index'
63 assert_not_nil assigns(:versions)
63 assert_not_nil assigns(:versions)
64
64
65 assert assigns(:versions).include?(Version.find(4)), "Shared version not found"
65 assert assigns(:versions).include?(Version.find(4)), "Shared version not found"
66 assert assigns(:versions).include?(@subproject_version), "Subproject version not found"
66 assert assigns(:versions).include?(@subproject_version), "Subproject version not found"
67 end
67 end
68
68
69 def test_show
69 def test_show
70 get :show, :id => 2
70 get :show, :id => 2
71 assert_response :success
71 assert_response :success
72 assert_template 'show'
72 assert_template 'show'
73 assert_not_nil assigns(:version)
73 assert_not_nil assigns(:version)
74
74
75 assert_tag :tag => 'h2', :content => /1.0/
75 assert_tag :tag => 'h2', :content => /1.0/
76 end
76 end
77
77
78 def test_create
78 def test_create
79 @request.session[:user_id] = 2 # manager
79 @request.session[:user_id] = 2 # manager
80 assert_difference 'Version.count' do
80 assert_difference 'Version.count' do
81 post :create, :project_id => '1', :version => {:name => 'test_add_version'}
81 post :create, :project_id => '1', :version => {:name => 'test_add_version'}
82 end
82 end
83 assert_redirected_to '/projects/ecookbook/settings/versions'
83 assert_redirected_to '/projects/ecookbook/settings/versions'
84 version = Version.find_by_name('test_add_version')
84 version = Version.find_by_name('test_add_version')
85 assert_not_nil version
85 assert_not_nil version
86 assert_equal 1, version.project_id
86 assert_equal 1, version.project_id
87 end
87 end
88
88
89 def test_create_from_issue_form
89 def test_create_from_issue_form
90 @request.session[:user_id] = 2 # manager
90 @request.session[:user_id] = 2 # manager
91 assert_difference 'Version.count' do
91 assert_difference 'Version.count' do
92 xhr :post, :create, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'}
92 xhr :post, :create, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'}
93 end
93 end
94 assert_response :success
94 assert_response :success
95 assert_select_rjs :replace, 'issue_fixed_version_id'
95 assert_select_rjs :replace, 'issue_fixed_version_id'
96 version = Version.find_by_name('test_add_version_from_issue_form')
96 version = Version.find_by_name('test_add_version_from_issue_form')
97 assert_not_nil version
97 assert_not_nil version
98 assert_equal 1, version.project_id
98 assert_equal 1, version.project_id
99 end
99 end
100
100
101 def test_get_edit
101 def test_get_edit
102 @request.session[:user_id] = 2
102 @request.session[:user_id] = 2
103 get :edit, :id => 2
103 get :edit, :id => 2
104 assert_response :success
104 assert_response :success
105 assert_template 'edit'
105 assert_template 'edit'
106 end
106 end
107
107
108 def test_close_completed
108 def test_close_completed
109 Version.update_all("status = 'open'")
109 Version.update_all("status = 'open'")
110 @request.session[:user_id] = 2
110 @request.session[:user_id] = 2
111 put :close_completed, :project_id => 'ecookbook'
111 put :close_completed, :project_id => 'ecookbook'
112 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
112 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
113 assert_not_nil Version.find_by_status('closed')
113 assert_not_nil Version.find_by_status('closed')
114 end
114 end
115
115
116 def test_post_update
116 def test_post_update
117 @request.session[:user_id] = 2
117 @request.session[:user_id] = 2
118 put :update, :id => 2,
118 put :update, :id => 2,
119 :version => { :name => 'New version name',
119 :version => { :name => 'New version name',
120 :effective_date => Date.today.strftime("%Y-%m-%d")}
120 :effective_date => Date.today.strftime("%Y-%m-%d")}
121 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
121 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
122 version = Version.find(2)
122 version = Version.find(2)
123 assert_equal 'New version name', version.name
123 assert_equal 'New version name', version.name
124 assert_equal Date.today, version.effective_date
124 assert_equal Date.today, version.effective_date
125 end
125 end
126
126
127 def test_post_update_with_validation_failure
127 def test_post_update_with_validation_failure
128 @request.session[:user_id] = 2
128 @request.session[:user_id] = 2
129 put :update, :id => 2,
129 put :update, :id => 2,
130 :version => { :name => '',
130 :version => { :name => '',
131 :effective_date => Date.today.strftime("%Y-%m-%d")}
131 :effective_date => Date.today.strftime("%Y-%m-%d")}
132 assert_response :success
132 assert_response :success
133 assert_template 'edit'
133 assert_template 'edit'
134 end
134 end
135
135
136 def test_destroy
136 def test_destroy
137 @request.session[:user_id] = 2
137 @request.session[:user_id] = 2
138 delete :destroy, :id => 3
138 delete :destroy, :id => 3
139 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
139 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
140 assert_nil Version.find_by_id(3)
140 assert_nil Version.find_by_id(3)
141 end
141 end
142
142
143 def test_issue_status_by
143 def test_issue_status_by
144 xhr :get, :status_by, :id => 2
144 xhr :get, :status_by, :id => 2
145 assert_response :success
145 assert_response :success
146 assert_template '_issue_counts'
146 assert_template '_issue_counts'
147 end
147 end
148
149 def test_issue_status_by_status
150 xhr :get, :status_by, :id => 2, :status_by => 'status'
151 assert_response :success
152 assert_template '_issue_counts'
153 end
148 end
154 end
General Comments 0
You need to be logged in to leave comments. Login now