@@ -1,192 +1,186 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 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 | class VersionsController < ApplicationController |
|
18 | class VersionsController < ApplicationController | |
19 | menu_item :roadmap |
|
19 | menu_item :roadmap | |
20 | model_object Version |
|
20 | model_object Version | |
21 | before_filter :find_model_object, :except => [:index, :new, :create, :close_completed] |
|
21 | before_filter :find_model_object, :except => [:index, :new, :create, :close_completed] | |
22 | before_filter :find_project_from_association, :except => [:index, :new, :create, :close_completed] |
|
22 | before_filter :find_project_from_association, :except => [:index, :new, :create, :close_completed] | |
23 | before_filter :find_project, :only => [:index, :new, :create, :close_completed] |
|
23 | before_filter :find_project, :only => [:index, :new, :create, :close_completed] | |
24 | before_filter :authorize |
|
24 | before_filter :authorize | |
25 |
|
25 | |||
26 | accept_api_auth :index, :create, :update, :destroy |
|
26 | accept_api_auth :index, :create, :update, :destroy | |
27 |
|
27 | |||
28 | helper :custom_fields |
|
28 | helper :custom_fields | |
29 | helper :projects |
|
29 | helper :projects | |
30 |
|
30 | |||
31 | def index |
|
31 | def index | |
32 | respond_to do |format| |
|
32 | respond_to do |format| | |
33 | format.html { |
|
33 | format.html { | |
34 | @trackers = @project.trackers.find(:all, :order => 'position') |
|
34 | @trackers = @project.trackers.find(:all, :order => 'position') | |
35 | retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?}) |
|
35 | retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?}) | |
36 | @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1') |
|
36 | @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1') | |
37 | project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id] |
|
37 | project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id] | |
38 |
|
38 | |||
39 | @versions = @project.shared_versions || [] |
|
39 | @versions = @project.shared_versions || [] | |
40 | @versions += @project.rolled_up_versions.visible if @with_subprojects |
|
40 | @versions += @project.rolled_up_versions.visible if @with_subprojects | |
41 | @versions = @versions.uniq.sort |
|
41 | @versions = @versions.uniq.sort | |
42 | @versions.reject! {|version| version.closed? || version.completed? } unless params[:completed] |
|
42 | @versions.reject! {|version| version.closed? || version.completed? } unless params[:completed] | |
43 |
|
43 | |||
44 | @issues_by_version = {} |
|
44 | @issues_by_version = {} | |
45 | unless @selected_tracker_ids.empty? |
|
45 | unless @selected_tracker_ids.empty? | |
46 | @versions.each do |version| |
|
46 | @versions.each do |version| | |
47 | issues = version.fixed_issues.visible.find(:all, |
|
47 | issues = version.fixed_issues.visible.find(:all, | |
48 | :include => [:project, :status, :tracker, :priority], |
|
48 | :include => [:project, :status, :tracker, :priority], | |
49 | :conditions => {:tracker_id => @selected_tracker_ids, :project_id => project_ids}, |
|
49 | :conditions => {:tracker_id => @selected_tracker_ids, :project_id => project_ids}, | |
50 | :order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id") |
|
50 | :order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id") | |
51 | @issues_by_version[version] = issues |
|
51 | @issues_by_version[version] = issues | |
52 | end |
|
52 | end | |
53 | end |
|
53 | end | |
54 | @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?} |
|
54 | @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?} | |
55 | } |
|
55 | } | |
56 | format.api { |
|
56 | format.api { | |
57 | @versions = @project.shared_versions.all |
|
57 | @versions = @project.shared_versions.all | |
58 | } |
|
58 | } | |
59 | end |
|
59 | end | |
60 | end |
|
60 | end | |
61 |
|
61 | |||
62 | def show |
|
62 | def show | |
63 | respond_to do |format| |
|
63 | respond_to do |format| | |
64 | format.html { |
|
64 | format.html { | |
65 | @issues = @version.fixed_issues.visible.find(:all, |
|
65 | @issues = @version.fixed_issues.visible.find(:all, | |
66 | :include => [:status, :tracker, :priority], |
|
66 | :include => [:status, :tracker, :priority], | |
67 | :order => "#{Tracker.table_name}.position, #{Issue.table_name}.id") |
|
67 | :order => "#{Tracker.table_name}.position, #{Issue.table_name}.id") | |
68 | } |
|
68 | } | |
69 | format.api |
|
69 | format.api | |
70 | end |
|
70 | end | |
71 | end |
|
71 | end | |
72 |
|
72 | |||
73 | def new |
|
73 | def new | |
74 | @version = @project.versions.build |
|
74 | @version = @project.versions.build(params[:version]) | |
75 | if params[:version] |
|
|||
76 | attributes = params[:version].dup |
|
|||
77 | attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing']) |
|
|||
78 | @version.attributes = attributes |
|
|||
79 | end |
|
|||
80 | end |
|
75 | end | |
81 |
|
76 | |||
82 | def create |
|
77 | def create | |
83 | # TODO: refactor with code above in #new |
|
|||
84 | @version = @project.versions.build |
|
78 | @version = @project.versions.build | |
85 | if params[:version] |
|
79 | if params[:version] | |
86 | attributes = params[:version].dup |
|
80 | attributes = params[:version].dup | |
87 | attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing']) |
|
81 | attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing']) | |
88 | @version.attributes = attributes |
|
82 | @version.attributes = attributes | |
89 | end |
|
83 | end | |
90 |
|
84 | |||
91 | if request.post? |
|
85 | if request.post? | |
92 | if @version.save |
|
86 | if @version.save | |
93 | respond_to do |format| |
|
87 | respond_to do |format| | |
94 | format.html do |
|
88 | format.html do | |
95 | flash[:notice] = l(:notice_successful_create) |
|
89 | flash[:notice] = l(:notice_successful_create) | |
96 | redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project |
|
90 | redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project | |
97 | end |
|
91 | end | |
98 | format.js do |
|
92 | format.js do | |
99 | # IE doesn't support the replace_html rjs method for select box options |
|
93 | # IE doesn't support the replace_html rjs method for select box options | |
100 | render(:update) {|page| page.replace "issue_fixed_version_id", |
|
94 | render(:update) {|page| page.replace "issue_fixed_version_id", | |
101 | content_tag('select', '<option></option>' + version_options_for_select(@project.shared_versions.open, @version), :id => 'issue_fixed_version_id', :name => 'issue[fixed_version_id]') |
|
95 | content_tag('select', '<option></option>' + version_options_for_select(@project.shared_versions.open, @version), :id => 'issue_fixed_version_id', :name => 'issue[fixed_version_id]') | |
102 | } |
|
96 | } | |
103 | end |
|
97 | end | |
104 | format.api do |
|
98 | format.api do | |
105 | render :action => 'show', :status => :created, :location => version_url(@version) |
|
99 | render :action => 'show', :status => :created, :location => version_url(@version) | |
106 | end |
|
100 | end | |
107 | end |
|
101 | end | |
108 | else |
|
102 | else | |
109 | respond_to do |format| |
|
103 | respond_to do |format| | |
110 | format.html { render :action => 'new' } |
|
104 | format.html { render :action => 'new' } | |
111 | format.js do |
|
105 | format.js do | |
112 | render(:update) {|page| page.alert(@version.errors.full_messages.join('\n')) } |
|
106 | render(:update) {|page| page.alert(@version.errors.full_messages.join('\n')) } | |
113 | end |
|
107 | end | |
114 | format.api { render_validation_errors(@version) } |
|
108 | format.api { render_validation_errors(@version) } | |
115 | end |
|
109 | end | |
116 | end |
|
110 | end | |
117 | end |
|
111 | end | |
118 | end |
|
112 | end | |
119 |
|
113 | |||
120 | def edit |
|
114 | def edit | |
121 | end |
|
115 | end | |
122 |
|
116 | |||
123 | def update |
|
117 | def update | |
124 | if request.put? && params[:version] |
|
118 | if request.put? && params[:version] | |
125 | attributes = params[:version].dup |
|
119 | attributes = params[:version].dup | |
126 | attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing']) |
|
120 | attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing']) | |
127 | if @version.update_attributes(attributes) |
|
121 | if @version.update_attributes(attributes) | |
128 | respond_to do |format| |
|
122 | respond_to do |format| | |
129 | format.html { |
|
123 | format.html { | |
130 | flash[:notice] = l(:notice_successful_update) |
|
124 | flash[:notice] = l(:notice_successful_update) | |
131 | redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project |
|
125 | redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project | |
132 | } |
|
126 | } | |
133 | format.api { head :ok } |
|
127 | format.api { head :ok } | |
134 | end |
|
128 | end | |
135 | else |
|
129 | else | |
136 | respond_to do |format| |
|
130 | respond_to do |format| | |
137 | format.html { render :action => 'edit' } |
|
131 | format.html { render :action => 'edit' } | |
138 | format.api { render_validation_errors(@version) } |
|
132 | format.api { render_validation_errors(@version) } | |
139 | end |
|
133 | end | |
140 | end |
|
134 | end | |
141 | end |
|
135 | end | |
142 | end |
|
136 | end | |
143 |
|
137 | |||
144 | def close_completed |
|
138 | def close_completed | |
145 | if request.put? |
|
139 | if request.put? | |
146 | @project.close_completed_versions |
|
140 | @project.close_completed_versions | |
147 | end |
|
141 | end | |
148 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project |
|
142 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project | |
149 | end |
|
143 | end | |
150 |
|
144 | |||
151 | verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed } |
|
145 | verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed } | |
152 | def destroy |
|
146 | def destroy | |
153 | if @version.fixed_issues.empty? |
|
147 | if @version.fixed_issues.empty? | |
154 | @version.destroy |
|
148 | @version.destroy | |
155 | respond_to do |format| |
|
149 | respond_to do |format| | |
156 | format.html { redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project } |
|
150 | format.html { redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project } | |
157 | format.api { head :ok } |
|
151 | format.api { head :ok } | |
158 | end |
|
152 | end | |
159 | else |
|
153 | else | |
160 | respond_to do |format| |
|
154 | respond_to do |format| | |
161 | format.html { |
|
155 | format.html { | |
162 | flash[:error] = l(:notice_unable_delete_version) |
|
156 | flash[:error] = l(:notice_unable_delete_version) | |
163 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project |
|
157 | redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project | |
164 | } |
|
158 | } | |
165 | format.api { head :unprocessable_entity } |
|
159 | format.api { head :unprocessable_entity } | |
166 | end |
|
160 | end | |
167 | end |
|
161 | end | |
168 | end |
|
162 | end | |
169 |
|
163 | |||
170 | def status_by |
|
164 | def status_by | |
171 | respond_to do |format| |
|
165 | respond_to do |format| | |
172 | format.html { render :action => 'show' } |
|
166 | format.html { render :action => 'show' } | |
173 | format.js { render(:update) {|page| page.replace_html 'status_by', render_issue_status_by(@version, params[:status_by])} } |
|
167 | format.js { render(:update) {|page| page.replace_html 'status_by', render_issue_status_by(@version, params[:status_by])} } | |
174 | end |
|
168 | end | |
175 | end |
|
169 | end | |
176 |
|
170 | |||
177 | private |
|
171 | private | |
178 | def find_project |
|
172 | def find_project | |
179 | @project = Project.find(params[:project_id]) |
|
173 | @project = Project.find(params[:project_id]) | |
180 | rescue ActiveRecord::RecordNotFound |
|
174 | rescue ActiveRecord::RecordNotFound | |
181 | render_404 |
|
175 | render_404 | |
182 | end |
|
176 | end | |
183 |
|
177 | |||
184 | def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil) |
|
178 | def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil) | |
185 | if ids = params[:tracker_ids] |
|
179 | if ids = params[:tracker_ids] | |
186 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } |
|
180 | @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s } | |
187 | else |
|
181 | else | |
188 | @selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s } |
|
182 | @selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s } | |
189 | end |
|
183 | end | |
190 | end |
|
184 | end | |
191 |
|
185 | |||
192 | end |
|
186 | end |
@@ -1,154 +1,181 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 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, :issue_statuses |
|
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_with_tracker_ids | |||
|
59 | get :index, :project_id => 1, :tracker_ids => [1, 3] | |||
|
60 | assert_response :success | |||
|
61 | assert_template 'index' | |||
|
62 | assert_not_nil assigns(:issues_by_version) | |||
|
63 | assert_nil assigns(:issues_by_version).values.flatten.detect {|issue| issue.tracker_id == 2} | |||
|
64 | end | |||
|
65 | ||||
58 | def test_index_showing_subprojects_versions |
|
66 | def test_index_showing_subprojects_versions | |
59 | @subproject_version = Version.generate!(:project => Project.find(3)) |
|
67 | @subproject_version = Version.generate!(:project => Project.find(3)) | |
60 | get :index, :project_id => 1, :with_subprojects => 1 |
|
68 | get :index, :project_id => 1, :with_subprojects => 1 | |
61 | assert_response :success |
|
69 | assert_response :success | |
62 | assert_template 'index' |
|
70 | assert_template 'index' | |
63 | assert_not_nil assigns(:versions) |
|
71 | assert_not_nil assigns(:versions) | |
64 |
|
72 | |||
65 | assert assigns(:versions).include?(Version.find(4)), "Shared version not found" |
|
73 | assert assigns(:versions).include?(Version.find(4)), "Shared version not found" | |
66 | assert assigns(:versions).include?(@subproject_version), "Subproject version not found" |
|
74 | assert assigns(:versions).include?(@subproject_version), "Subproject version not found" | |
67 | end |
|
75 | end | |
68 |
|
76 | |||
69 | def test_show |
|
77 | def test_show | |
70 | get :show, :id => 2 |
|
78 | get :show, :id => 2 | |
71 | assert_response :success |
|
79 | assert_response :success | |
72 | assert_template 'show' |
|
80 | assert_template 'show' | |
73 | assert_not_nil assigns(:version) |
|
81 | assert_not_nil assigns(:version) | |
74 |
|
82 | |||
75 | assert_tag :tag => 'h2', :content => /1.0/ |
|
83 | assert_tag :tag => 'h2', :content => /1.0/ | |
76 | end |
|
84 | end | |
77 |
|
85 | |||
|
86 | def test_new | |||
|
87 | @request.session[:user_id] = 2 | |||
|
88 | get :new, :project_id => '1' | |||
|
89 | assert_response :success | |||
|
90 | assert_template 'new' | |||
|
91 | end | |||
|
92 | ||||
78 | def test_create |
|
93 | def test_create | |
79 | @request.session[:user_id] = 2 # manager |
|
94 | @request.session[:user_id] = 2 # manager | |
80 | assert_difference 'Version.count' do |
|
95 | assert_difference 'Version.count' do | |
81 | post :create, :project_id => '1', :version => {:name => 'test_add_version'} |
|
96 | post :create, :project_id => '1', :version => {:name => 'test_add_version'} | |
82 | end |
|
97 | end | |
83 | assert_redirected_to '/projects/ecookbook/settings/versions' |
|
98 | assert_redirected_to '/projects/ecookbook/settings/versions' | |
84 | version = Version.find_by_name('test_add_version') |
|
99 | version = Version.find_by_name('test_add_version') | |
85 | assert_not_nil version |
|
100 | assert_not_nil version | |
86 | assert_equal 1, version.project_id |
|
101 | assert_equal 1, version.project_id | |
87 | end |
|
102 | end | |
88 |
|
103 | |||
89 | def test_create_from_issue_form |
|
104 | def test_create_from_issue_form | |
90 | @request.session[:user_id] = 2 # manager |
|
105 | @request.session[:user_id] = 2 # manager | |
91 | assert_difference 'Version.count' do |
|
106 | assert_difference 'Version.count' do | |
92 | xhr :post, :create, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'} |
|
107 | xhr :post, :create, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'} | |
93 | end |
|
108 | end | |
94 | assert_response :success |
|
109 | assert_response :success | |
95 | assert_select_rjs :replace, 'issue_fixed_version_id' |
|
110 | assert_select_rjs :replace, 'issue_fixed_version_id' | |
96 | version = Version.find_by_name('test_add_version_from_issue_form') |
|
111 | version = Version.find_by_name('test_add_version_from_issue_form') | |
97 | assert_not_nil version |
|
112 | assert_not_nil version | |
98 | assert_equal 1, version.project_id |
|
113 | assert_equal 1, version.project_id | |
99 | end |
|
114 | end | |
100 |
|
115 | |||
101 | def test_get_edit |
|
116 | def test_get_edit | |
102 | @request.session[:user_id] = 2 |
|
117 | @request.session[:user_id] = 2 | |
103 | get :edit, :id => 2 |
|
118 | get :edit, :id => 2 | |
104 | assert_response :success |
|
119 | assert_response :success | |
105 | assert_template 'edit' |
|
120 | assert_template 'edit' | |
106 | end |
|
121 | end | |
107 |
|
122 | |||
108 | def test_close_completed |
|
123 | def test_close_completed | |
109 | Version.update_all("status = 'open'") |
|
124 | Version.update_all("status = 'open'") | |
110 | @request.session[:user_id] = 2 |
|
125 | @request.session[:user_id] = 2 | |
111 | put :close_completed, :project_id => 'ecookbook' |
|
126 | put :close_completed, :project_id => 'ecookbook' | |
112 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
127 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' | |
113 | assert_not_nil Version.find_by_status('closed') |
|
128 | assert_not_nil Version.find_by_status('closed') | |
114 | end |
|
129 | end | |
115 |
|
130 | |||
116 | def test_post_update |
|
131 | def test_post_update | |
117 | @request.session[:user_id] = 2 |
|
132 | @request.session[:user_id] = 2 | |
118 | put :update, :id => 2, |
|
133 | put :update, :id => 2, | |
119 | :version => { :name => 'New version name', |
|
134 | :version => { :name => 'New version name', | |
120 | :effective_date => Date.today.strftime("%Y-%m-%d")} |
|
135 | :effective_date => Date.today.strftime("%Y-%m-%d")} | |
121 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
136 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' | |
122 | version = Version.find(2) |
|
137 | version = Version.find(2) | |
123 | assert_equal 'New version name', version.name |
|
138 | assert_equal 'New version name', version.name | |
124 | assert_equal Date.today, version.effective_date |
|
139 | assert_equal Date.today, version.effective_date | |
125 | end |
|
140 | end | |
126 |
|
141 | |||
127 | def test_post_update_with_validation_failure |
|
142 | def test_post_update_with_validation_failure | |
128 | @request.session[:user_id] = 2 |
|
143 | @request.session[:user_id] = 2 | |
129 | put :update, :id => 2, |
|
144 | put :update, :id => 2, | |
130 | :version => { :name => '', |
|
145 | :version => { :name => '', | |
131 | :effective_date => Date.today.strftime("%Y-%m-%d")} |
|
146 | :effective_date => Date.today.strftime("%Y-%m-%d")} | |
132 | assert_response :success |
|
147 | assert_response :success | |
133 | assert_template 'edit' |
|
148 | assert_template 'edit' | |
134 | end |
|
149 | end | |
135 |
|
150 | |||
136 | def test_destroy |
|
151 | def test_destroy | |
137 | @request.session[:user_id] = 2 |
|
152 | @request.session[:user_id] = 2 | |
|
153 | assert_difference 'Version.count', -1 do | |||
138 | delete :destroy, :id => 3 |
|
154 | delete :destroy, :id => 3 | |
|
155 | end | |||
139 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' |
|
156 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' | |
140 | assert_nil Version.find_by_id(3) |
|
157 | assert_nil Version.find_by_id(3) | |
141 | end |
|
158 | end | |
142 |
|
159 | |||
|
160 | def test_destroy_version_in_use_should_fail | |||
|
161 | @request.session[:user_id] = 2 | |||
|
162 | assert_no_difference 'Version.count' do | |||
|
163 | delete :destroy, :id => 2 | |||
|
164 | end | |||
|
165 | assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook' | |||
|
166 | assert flash[:error].match(/Unable to delete version/) | |||
|
167 | assert Version.find_by_id(2) | |||
|
168 | end | |||
|
169 | ||||
143 | def test_issue_status_by |
|
170 | def test_issue_status_by | |
144 | xhr :get, :status_by, :id => 2 |
|
171 | xhr :get, :status_by, :id => 2 | |
145 | assert_response :success |
|
172 | assert_response :success | |
146 | assert_template '_issue_counts' |
|
173 | assert_template '_issue_counts' | |
147 | end |
|
174 | end | |
148 |
|
175 | |||
149 | def test_issue_status_by_status |
|
176 | def test_issue_status_by_status | |
150 | xhr :get, :status_by, :id => 2, :status_by => 'status' |
|
177 | xhr :get, :status_by, :id => 2, :status_by => 'status' | |
151 | assert_response :success |
|
178 | assert_response :success | |
152 | assert_template '_issue_counts' |
|
179 | assert_template '_issue_counts' | |
153 | end |
|
180 | end | |
154 | end |
|
181 | end |
General Comments 0
You need to be logged in to leave comments.
Login now