##// END OF EJS Templates
Start removing the RJS stuff....
Jean-Philippe Lang -
r9860:035805fbd042
parent child
Show More
@@ -0,0 +1,3
1 hideModal();
2 <% select = content_tag('select', content_tag('option') + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]') %>
3 Element.replace('issue_category_id', '<%= escape_javascript(select) %>');
@@ -0,0 +1,3
1 Element.update('ajax-modal', '<%= escape_javascript(render :partial => 'issue_categories/new_modal') %>');
2 showModal('ajax-modal', '600px');
3 Form.Element.focus('issue_category_name');
@@ -0,0 +1,3
1 hideModal();
2 <% select = content_tag('select', content_tag('option') + version_options_for_select(@project.shared_versions.open, @version), :id => 'issue_fixed_version_id', :name => 'issue[fixed_version_id]') %>
3 Element.replace('issue_fixed_version_id', '<%= escape_javascript(select) %>');
@@ -0,0 +1,3
1 Element.update('ajax-modal', '<%= escape_javascript(render :partial => 'versions/new_modal') %>');
2 showModal('ajax-modal', '600px');
3 Form.Element.focus('version_name');
@@ -1,135 +1,117
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 IssueCategoriesController < ApplicationController
18 class IssueCategoriesController < ApplicationController
19 menu_item :settings
19 menu_item :settings
20 model_object IssueCategory
20 model_object IssueCategory
21 before_filter :find_model_object, :except => [:index, :new, :create]
21 before_filter :find_model_object, :except => [:index, :new, :create]
22 before_filter :find_project_from_association, :except => [:index, :new, :create]
22 before_filter :find_project_from_association, :except => [:index, :new, :create]
23 before_filter :find_project_by_project_id, :only => [:index, :new, :create]
23 before_filter :find_project_by_project_id, :only => [:index, :new, :create]
24 before_filter :authorize
24 before_filter :authorize
25 accept_api_auth :index, :show, :create, :update, :destroy
25 accept_api_auth :index, :show, :create, :update, :destroy
26
26
27 def index
27 def index
28 respond_to do |format|
28 respond_to do |format|
29 format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project }
29 format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project }
30 format.api { @categories = @project.issue_categories.all }
30 format.api { @categories = @project.issue_categories.all }
31 end
31 end
32 end
32 end
33
33
34 def show
34 def show
35 respond_to do |format|
35 respond_to do |format|
36 format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project }
36 format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project }
37 format.api
37 format.api
38 end
38 end
39 end
39 end
40
40
41 def new
41 def new
42 @category = @project.issue_categories.build
42 @category = @project.issue_categories.build
43 @category.safe_attributes = params[:issue_category]
43 @category.safe_attributes = params[:issue_category]
44
44
45 respond_to do |format|
45 respond_to do |format|
46 format.html
46 format.html
47 format.js do
47 format.js
48 render :update do |page|
49 page.replace_html 'ajax-modal', :partial => 'issue_categories/new_modal'
50 page << "showModal('ajax-modal', '600px');"
51 page << "Form.Element.focus('issue_category_name');"
52 end
53 end
54 end
48 end
55 end
49 end
56
50
57 def create
51 def create
58 @category = @project.issue_categories.build
52 @category = @project.issue_categories.build
59 @category.safe_attributes = params[:issue_category]
53 @category.safe_attributes = params[:issue_category]
60 if @category.save
54 if @category.save
61 respond_to do |format|
55 respond_to do |format|
62 format.html do
56 format.html do
63 flash[:notice] = l(:notice_successful_create)
57 flash[:notice] = l(:notice_successful_create)
64 redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
58 redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
65 end
59 end
66 format.js do
60 format.js
67 render(:update) {|page|
68 page << 'hideModal();'
69 # IE doesn't support the replace_html rjs method for select box options
70 page.replace "issue_category_id",
71 content_tag('select', content_tag('option') + options_from_collection_for_select(@project.issue_categories, 'id', 'name', @category.id), :id => 'issue_category_id', :name => 'issue[category_id]')
72 }
73 end
74 format.api { render :action => 'show', :status => :created, :location => issue_category_path(@category) }
61 format.api { render :action => 'show', :status => :created, :location => issue_category_path(@category) }
75 end
62 end
76 else
63 else
77 respond_to do |format|
64 respond_to do |format|
78 format.html { render :action => 'new'}
65 format.html { render :action => 'new'}
79 format.js do
66 format.js { render :action => 'new'}
80 render :update do |page|
81 page.replace_html 'ajax-modal', :partial => 'issue_categories/new_modal'
82 page << "Form.Element.focus('version_name');"
83 end
84 end
85 format.api { render_validation_errors(@category) }
67 format.api { render_validation_errors(@category) }
86 end
68 end
87 end
69 end
88 end
70 end
89
71
90 def edit
72 def edit
91 end
73 end
92
74
93 def update
75 def update
94 @category.safe_attributes = params[:issue_category]
76 @category.safe_attributes = params[:issue_category]
95 if @category.save
77 if @category.save
96 respond_to do |format|
78 respond_to do |format|
97 format.html {
79 format.html {
98 flash[:notice] = l(:notice_successful_update)
80 flash[:notice] = l(:notice_successful_update)
99 redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
81 redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
100 }
82 }
101 format.api { render_api_ok }
83 format.api { render_api_ok }
102 end
84 end
103 else
85 else
104 respond_to do |format|
86 respond_to do |format|
105 format.html { render :action => 'edit' }
87 format.html { render :action => 'edit' }
106 format.api { render_validation_errors(@category) }
88 format.api { render_validation_errors(@category) }
107 end
89 end
108 end
90 end
109 end
91 end
110
92
111 def destroy
93 def destroy
112 @issue_count = @category.issues.size
94 @issue_count = @category.issues.size
113 if @issue_count == 0 || params[:todo] || api_request?
95 if @issue_count == 0 || params[:todo] || api_request?
114 reassign_to = nil
96 reassign_to = nil
115 if params[:reassign_to_id] && (params[:todo] == 'reassign' || params[:todo].blank?)
97 if params[:reassign_to_id] && (params[:todo] == 'reassign' || params[:todo].blank?)
116 reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id])
98 reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id])
117 end
99 end
118 @category.destroy(reassign_to)
100 @category.destroy(reassign_to)
119 respond_to do |format|
101 respond_to do |format|
120 format.html { redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories' }
102 format.html { redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories' }
121 format.api { render_api_ok }
103 format.api { render_api_ok }
122 end
104 end
123 return
105 return
124 end
106 end
125 @categories = @project.issue_categories - [@category]
107 @categories = @project.issue_categories - [@category]
126 end
108 end
127
109
128 private
110 private
129 # Wrap ApplicationController's find_model_object method to set
111 # Wrap ApplicationController's find_model_object method to set
130 # @category instead of just @issue_category
112 # @category instead of just @issue_category
131 def find_model_object
113 def find_model_object
132 super
114 super
133 @category = @object
115 @category = @object
134 end
116 end
135 end
117 end
@@ -1,205 +1,187
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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, :show, :create, :update, :destroy
26 accept_api_auth :index, :show, :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 unless params[:completed]
42 unless params[:completed]
43 @completed_versions = @versions.select {|version| version.closed? || version.completed? }
43 @completed_versions = @versions.select {|version| version.closed? || version.completed? }
44 @versions -= @completed_versions
44 @versions -= @completed_versions
45 end
45 end
46
46
47 @issues_by_version = {}
47 @issues_by_version = {}
48 if @selected_tracker_ids.any? && @versions.any?
48 if @selected_tracker_ids.any? && @versions.any?
49 issues = Issue.visible.all(
49 issues = Issue.visible.all(
50 :include => [:project, :status, :tracker, :priority, :fixed_version],
50 :include => [:project, :status, :tracker, :priority, :fixed_version],
51 :conditions => {:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)},
51 :conditions => {:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)},
52 :order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id"
52 :order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id"
53 )
53 )
54 @issues_by_version = issues.group_by(&:fixed_version)
54 @issues_by_version = issues.group_by(&:fixed_version)
55 end
55 end
56 @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}
56 @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}
57 }
57 }
58 format.api {
58 format.api {
59 @versions = @project.shared_versions.all
59 @versions = @project.shared_versions.all
60 }
60 }
61 end
61 end
62 end
62 end
63
63
64 def show
64 def show
65 respond_to do |format|
65 respond_to do |format|
66 format.html {
66 format.html {
67 @issues = @version.fixed_issues.visible.find(:all,
67 @issues = @version.fixed_issues.visible.find(:all,
68 :include => [:status, :tracker, :priority],
68 :include => [:status, :tracker, :priority],
69 :order => "#{Tracker.table_name}.position, #{Issue.table_name}.id")
69 :order => "#{Tracker.table_name}.position, #{Issue.table_name}.id")
70 }
70 }
71 format.api
71 format.api
72 end
72 end
73 end
73 end
74
74
75 def new
75 def new
76 @version = @project.versions.build
76 @version = @project.versions.build
77 @version.safe_attributes = params[:version]
77 @version.safe_attributes = params[:version]
78
78
79 respond_to do |format|
79 respond_to do |format|
80 format.html
80 format.html
81 format.js do
81 format.js
82 render :update do |page|
83 page.replace_html 'ajax-modal', :partial => 'versions/new_modal'
84 page << "showModal('ajax-modal', '600px');"
85 page << "Form.Element.focus('version_name');"
86 end
87 end
88 end
82 end
89 end
83 end
90
84
91 def create
85 def create
92 @version = @project.versions.build
86 @version = @project.versions.build
93 if params[:version]
87 if params[:version]
94 attributes = params[:version].dup
88 attributes = params[:version].dup
95 attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
89 attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
96 @version.safe_attributes = attributes
90 @version.safe_attributes = attributes
97 end
91 end
98
92
99 if request.post?
93 if request.post?
100 if @version.save
94 if @version.save
101 respond_to do |format|
95 respond_to do |format|
102 format.html do
96 format.html do
103 flash[:notice] = l(:notice_successful_create)
97 flash[:notice] = l(:notice_successful_create)
104 redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
98 redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
105 end
99 end
106 format.js do
100 format.js
107 render(:update) {|page|
108 page << 'hideModal();'
109 # IE doesn't support the replace_html rjs method for select box options
110 page.replace "issue_fixed_version_id",
111 content_tag('select', content_tag('option') + version_options_for_select(@project.shared_versions.open, @version), :id => 'issue_fixed_version_id', :name => 'issue[fixed_version_id]')
112 }
113 end
114 format.api do
101 format.api do
115 render :action => 'show', :status => :created, :location => version_url(@version)
102 render :action => 'show', :status => :created, :location => version_url(@version)
116 end
103 end
117 end
104 end
118 else
105 else
119 respond_to do |format|
106 respond_to do |format|
120 format.html { render :action => 'new' }
107 format.html { render :action => 'new' }
121 format.js do
108 format.js { render :action => 'new' }
122 render :update do |page|
123 page.replace_html 'ajax-modal', :partial => 'versions/new_modal'
124 page << "Form.Element.focus('version_name');"
125 end
126 end
127 format.api { render_validation_errors(@version) }
109 format.api { render_validation_errors(@version) }
128 end
110 end
129 end
111 end
130 end
112 end
131 end
113 end
132
114
133 def edit
115 def edit
134 end
116 end
135
117
136 def update
118 def update
137 if request.put? && params[:version]
119 if request.put? && params[:version]
138 attributes = params[:version].dup
120 attributes = params[:version].dup
139 attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing'])
121 attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing'])
140 @version.safe_attributes = attributes
122 @version.safe_attributes = attributes
141 if @version.save
123 if @version.save
142 respond_to do |format|
124 respond_to do |format|
143 format.html {
125 format.html {
144 flash[:notice] = l(:notice_successful_update)
126 flash[:notice] = l(:notice_successful_update)
145 redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
127 redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
146 }
128 }
147 format.api { render_api_ok }
129 format.api { render_api_ok }
148 end
130 end
149 else
131 else
150 respond_to do |format|
132 respond_to do |format|
151 format.html { render :action => 'edit' }
133 format.html { render :action => 'edit' }
152 format.api { render_validation_errors(@version) }
134 format.api { render_validation_errors(@version) }
153 end
135 end
154 end
136 end
155 end
137 end
156 end
138 end
157
139
158 def close_completed
140 def close_completed
159 if request.put?
141 if request.put?
160 @project.close_completed_versions
142 @project.close_completed_versions
161 end
143 end
162 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
144 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
163 end
145 end
164
146
165 def destroy
147 def destroy
166 if @version.fixed_issues.empty?
148 if @version.fixed_issues.empty?
167 @version.destroy
149 @version.destroy
168 respond_to do |format|
150 respond_to do |format|
169 format.html { redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project }
151 format.html { redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project }
170 format.api { render_api_ok }
152 format.api { render_api_ok }
171 end
153 end
172 else
154 else
173 respond_to do |format|
155 respond_to do |format|
174 format.html {
156 format.html {
175 flash[:error] = l(:notice_unable_delete_version)
157 flash[:error] = l(:notice_unable_delete_version)
176 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
158 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
177 }
159 }
178 format.api { head :unprocessable_entity }
160 format.api { head :unprocessable_entity }
179 end
161 end
180 end
162 end
181 end
163 end
182
164
183 def status_by
165 def status_by
184 respond_to do |format|
166 respond_to do |format|
185 format.html { render :action => 'show' }
167 format.html { render :action => 'show' }
186 format.js { render(:update) {|page| page.replace_html 'status_by', render_issue_status_by(@version, params[:status_by])} }
168 format.js { render(:update) {|page| page.replace_html 'status_by', render_issue_status_by(@version, params[:status_by])} }
187 end
169 end
188 end
170 end
189
171
190 private
172 private
191 def find_project
173 def find_project
192 @project = Project.find(params[:project_id])
174 @project = Project.find(params[:project_id])
193 rescue ActiveRecord::RecordNotFound
175 rescue ActiveRecord::RecordNotFound
194 render_404
176 render_404
195 end
177 end
196
178
197 def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil)
179 def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil)
198 if ids = params[:tracker_ids]
180 if ids = params[:tracker_ids]
199 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
181 @selected_tracker_ids = (ids.is_a? Array) ? ids.collect { |id| id.to_i.to_s } : ids.split('/').collect { |id| id.to_i.to_s }
200 else
182 else
201 @selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s }
183 @selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s }
202 end
184 end
203 end
185 end
204
186
205 end
187 end
@@ -1,144 +1,151
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 'issue_categories_controller'
19 require 'issue_categories_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class IssueCategoriesController; def rescue_action(e) raise e end; end
22 class IssueCategoriesController; def rescue_action(e) raise e end; end
23
23
24 class IssueCategoriesControllerTest < ActionController::TestCase
24 class IssueCategoriesControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, :issue_categories
25 fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, :issue_categories
26
26
27 def setup
27 def setup
28 @controller = IssueCategoriesController.new
28 @controller = IssueCategoriesController.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 @request.session[:user_id] = 2
32 @request.session[:user_id] = 2
33 end
33 end
34
34
35 def test_new
35 def test_new
36 @request.session[:user_id] = 2 # manager
36 @request.session[:user_id] = 2 # manager
37 get :new, :project_id => '1'
37 get :new, :project_id => '1'
38 assert_response :success
38 assert_response :success
39 assert_template 'new'
39 assert_template 'new'
40 assert_select 'input[name=?]', 'issue_category[name]'
40 assert_select 'input[name=?]', 'issue_category[name]'
41 end
41 end
42
42
43 def test_new_from_issue_form
44 @request.session[:user_id] = 2 # manager
45 xhr :get, :new, :project_id => '1'
46
47 assert_response :success
48 assert_template 'new'
49 assert_equal 'text/javascript', response.content_type
50 end
51
43 def test_create
52 def test_create
44 @request.session[:user_id] = 2 # manager
53 @request.session[:user_id] = 2 # manager
45 assert_difference 'IssueCategory.count' do
54 assert_difference 'IssueCategory.count' do
46 post :create, :project_id => '1', :issue_category => {:name => 'New category'}
55 post :create, :project_id => '1', :issue_category => {:name => 'New category'}
47 end
56 end
48 assert_redirected_to '/projects/ecookbook/settings/categories'
57 assert_redirected_to '/projects/ecookbook/settings/categories'
49 category = IssueCategory.find_by_name('New category')
58 category = IssueCategory.find_by_name('New category')
50 assert_not_nil category
59 assert_not_nil category
51 assert_equal 1, category.project_id
60 assert_equal 1, category.project_id
52 end
61 end
53
62
54 def test_create_failure
63 def test_create_failure
55 @request.session[:user_id] = 2
64 @request.session[:user_id] = 2
56 post :create, :project_id => '1', :issue_category => {:name => ''}
65 post :create, :project_id => '1', :issue_category => {:name => ''}
57 assert_response :success
66 assert_response :success
58 assert_template 'new'
67 assert_template 'new'
59 end
68 end
60
69
61 def test_create_from_issue_form
70 def test_create_from_issue_form
62 @request.session[:user_id] = 2 # manager
71 @request.session[:user_id] = 2 # manager
63 assert_difference 'IssueCategory.count' do
72 assert_difference 'IssueCategory.count' do
64 xhr :post, :create, :project_id => '1', :issue_category => {:name => 'New category'}
73 xhr :post, :create, :project_id => '1', :issue_category => {:name => 'New category'}
65 end
74 end
66 category = IssueCategory.first(:order => 'id DESC')
75 category = IssueCategory.first(:order => 'id DESC')
67 assert_equal 'New category', category.name
76 assert_equal 'New category', category.name
68
77
69 assert_response :success
78 assert_response :success
70 assert_select_rjs :replace, 'issue_category_id' do
79 assert_template 'create'
71 assert_select "option[value=#{category.id}][selected=selected]"
80 assert_equal 'text/javascript', response.content_type
72 end
73 end
81 end
74
82
75 def test_create_from_issue_form_with_failure
83 def test_create_from_issue_form_with_failure
76 @request.session[:user_id] = 2 # manager
84 @request.session[:user_id] = 2 # manager
77 assert_no_difference 'IssueCategory.count' do
85 assert_no_difference 'IssueCategory.count' do
78 xhr :post, :create, :project_id => '1', :issue_category => {:name => ''}
86 xhr :post, :create, :project_id => '1', :issue_category => {:name => ''}
79 end
87 end
80
88
81 assert_response :success
89 assert_response :success
82 assert_select_rjs :replace_html, "ajax-modal" do
90 assert_template 'new'
83 assert_select "div#errorExplanation"
91 assert_equal 'text/javascript', response.content_type
84 end
85 end
92 end
86
93
87 def test_edit
94 def test_edit
88 @request.session[:user_id] = 2
95 @request.session[:user_id] = 2
89 get :edit, :id => 2
96 get :edit, :id => 2
90 assert_response :success
97 assert_response :success
91 assert_template 'edit'
98 assert_template 'edit'
92 assert_select 'input[name=?][value=?]', 'issue_category[name]', 'Recipes'
99 assert_select 'input[name=?][value=?]', 'issue_category[name]', 'Recipes'
93 end
100 end
94
101
95 def test_update
102 def test_update
96 assert_no_difference 'IssueCategory.count' do
103 assert_no_difference 'IssueCategory.count' do
97 put :update, :id => 2, :issue_category => { :name => 'Testing' }
104 put :update, :id => 2, :issue_category => { :name => 'Testing' }
98 end
105 end
99 assert_redirected_to '/projects/ecookbook/settings/categories'
106 assert_redirected_to '/projects/ecookbook/settings/categories'
100 assert_equal 'Testing', IssueCategory.find(2).name
107 assert_equal 'Testing', IssueCategory.find(2).name
101 end
108 end
102
109
103 def test_update_failure
110 def test_update_failure
104 put :update, :id => 2, :issue_category => { :name => '' }
111 put :update, :id => 2, :issue_category => { :name => '' }
105 assert_response :success
112 assert_response :success
106 assert_template 'edit'
113 assert_template 'edit'
107 end
114 end
108
115
109 def test_update_not_found
116 def test_update_not_found
110 put :update, :id => 97, :issue_category => { :name => 'Testing' }
117 put :update, :id => 97, :issue_category => { :name => 'Testing' }
111 assert_response 404
118 assert_response 404
112 end
119 end
113
120
114 def test_destroy_category_not_in_use
121 def test_destroy_category_not_in_use
115 delete :destroy, :id => 2
122 delete :destroy, :id => 2
116 assert_redirected_to '/projects/ecookbook/settings/categories'
123 assert_redirected_to '/projects/ecookbook/settings/categories'
117 assert_nil IssueCategory.find_by_id(2)
124 assert_nil IssueCategory.find_by_id(2)
118 end
125 end
119
126
120 def test_destroy_category_in_use
127 def test_destroy_category_in_use
121 delete :destroy, :id => 1
128 delete :destroy, :id => 1
122 assert_response :success
129 assert_response :success
123 assert_template 'destroy'
130 assert_template 'destroy'
124 assert_not_nil IssueCategory.find_by_id(1)
131 assert_not_nil IssueCategory.find_by_id(1)
125 end
132 end
126
133
127 def test_destroy_category_in_use_with_reassignment
134 def test_destroy_category_in_use_with_reassignment
128 issue = Issue.find(:first, :conditions => {:category_id => 1})
135 issue = Issue.find(:first, :conditions => {:category_id => 1})
129 delete :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2
136 delete :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2
130 assert_redirected_to '/projects/ecookbook/settings/categories'
137 assert_redirected_to '/projects/ecookbook/settings/categories'
131 assert_nil IssueCategory.find_by_id(1)
138 assert_nil IssueCategory.find_by_id(1)
132 # check that the issue was reassign
139 # check that the issue was reassign
133 assert_equal 2, issue.reload.category_id
140 assert_equal 2, issue.reload.category_id
134 end
141 end
135
142
136 def test_destroy_category_in_use_without_reassignment
143 def test_destroy_category_in_use_without_reassignment
137 issue = Issue.find(:first, :conditions => {:category_id => 1})
144 issue = Issue.find(:first, :conditions => {:category_id => 1})
138 delete :destroy, :id => 1, :todo => 'nullify'
145 delete :destroy, :id => 1, :todo => 'nullify'
139 assert_redirected_to '/projects/ecookbook/settings/categories'
146 assert_redirected_to '/projects/ecookbook/settings/categories'
140 assert_nil IssueCategory.find_by_id(1)
147 assert_nil IssueCategory.find_by_id(1)
141 # check that the issue category was nullified
148 # check that the issue category was nullified
142 assert_nil issue.reload.category_id
149 assert_nil issue.reload.category_id
143 end
150 end
144 end
151 end
@@ -1,211 +1,207
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2012 Jean-Philippe Lang
2 # Copyright (C) 2006-2012 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 # Links to versions anchors
45 # Links to versions anchors
46 assert_tag 'a', :attributes => {:href => '#2.0'},
46 assert_tag 'a', :attributes => {:href => '#2.0'},
47 :ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}}
47 :ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}}
48 # Links to completed versions in the sidebar
48 # Links to completed versions in the sidebar
49 assert_tag 'a', :attributes => {:href => '/versions/1'},
49 assert_tag 'a', :attributes => {:href => '/versions/1'},
50 :ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}}
50 :ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}}
51 end
51 end
52
52
53 def test_index_with_completed_versions
53 def test_index_with_completed_versions
54 get :index, :project_id => 1, :completed => 1
54 get :index, :project_id => 1, :completed => 1
55 assert_response :success
55 assert_response :success
56 assert_template 'index'
56 assert_template 'index'
57 assert_not_nil assigns(:versions)
57 assert_not_nil assigns(:versions)
58 # Version with no date set appears
58 # Version with no date set appears
59 assert assigns(:versions).include?(Version.find(3))
59 assert assigns(:versions).include?(Version.find(3))
60 # Completed version appears
60 # Completed version appears
61 assert assigns(:versions).include?(Version.find(1))
61 assert assigns(:versions).include?(Version.find(1))
62 end
62 end
63
63
64 def test_index_with_tracker_ids
64 def test_index_with_tracker_ids
65 get :index, :project_id => 1, :tracker_ids => [1, 3]
65 get :index, :project_id => 1, :tracker_ids => [1, 3]
66 assert_response :success
66 assert_response :success
67 assert_template 'index'
67 assert_template 'index'
68 assert_not_nil assigns(:issues_by_version)
68 assert_not_nil assigns(:issues_by_version)
69 assert_nil assigns(:issues_by_version).values.flatten.detect {|issue| issue.tracker_id == 2}
69 assert_nil assigns(:issues_by_version).values.flatten.detect {|issue| issue.tracker_id == 2}
70 end
70 end
71
71
72 def test_index_showing_subprojects_versions
72 def test_index_showing_subprojects_versions
73 @subproject_version = Version.create!(:project => Project.find(3), :name => "Subproject version")
73 @subproject_version = Version.create!(:project => Project.find(3), :name => "Subproject version")
74 get :index, :project_id => 1, :with_subprojects => 1
74 get :index, :project_id => 1, :with_subprojects => 1
75 assert_response :success
75 assert_response :success
76 assert_template 'index'
76 assert_template 'index'
77 assert_not_nil assigns(:versions)
77 assert_not_nil assigns(:versions)
78
78
79 assert assigns(:versions).include?(Version.find(4)), "Shared version not found"
79 assert assigns(:versions).include?(Version.find(4)), "Shared version not found"
80 assert assigns(:versions).include?(@subproject_version), "Subproject version not found"
80 assert assigns(:versions).include?(@subproject_version), "Subproject version not found"
81 end
81 end
82
82
83 def test_show
83 def test_show
84 get :show, :id => 2
84 get :show, :id => 2
85 assert_response :success
85 assert_response :success
86 assert_template 'show'
86 assert_template 'show'
87 assert_not_nil assigns(:version)
87 assert_not_nil assigns(:version)
88
88
89 assert_tag :tag => 'h2', :content => /1.0/
89 assert_tag :tag => 'h2', :content => /1.0/
90 end
90 end
91
91
92 def test_new
92 def test_new
93 @request.session[:user_id] = 2
93 @request.session[:user_id] = 2
94 get :new, :project_id => '1'
94 get :new, :project_id => '1'
95 assert_response :success
95 assert_response :success
96 assert_template 'new'
96 assert_template 'new'
97 end
97 end
98
98
99 def test_new_from_issue_form
99 def test_new_from_issue_form
100 @request.session[:user_id] = 2
100 @request.session[:user_id] = 2
101 xhr :get, :new, :project_id => '1'
101 xhr :get, :new, :project_id => '1'
102 assert_response :success
102 assert_response :success
103 assert_select_rjs :replace_html, "ajax-modal" do
103 assert_template 'new'
104 assert_select "form[action=/projects/ecookbook/versions]"
104 assert_equal 'text/javascript', response.content_type
105 assert_select "input#version_name"
106 end
107 end
105 end
108
106
109 def test_create
107 def test_create
110 @request.session[:user_id] = 2 # manager
108 @request.session[:user_id] = 2 # manager
111 assert_difference 'Version.count' do
109 assert_difference 'Version.count' do
112 post :create, :project_id => '1', :version => {:name => 'test_add_version'}
110 post :create, :project_id => '1', :version => {:name => 'test_add_version'}
113 end
111 end
114 assert_redirected_to '/projects/ecookbook/settings/versions'
112 assert_redirected_to '/projects/ecookbook/settings/versions'
115 version = Version.find_by_name('test_add_version')
113 version = Version.find_by_name('test_add_version')
116 assert_not_nil version
114 assert_not_nil version
117 assert_equal 1, version.project_id
115 assert_equal 1, version.project_id
118 end
116 end
119
117
120 def test_create_from_issue_form
118 def test_create_from_issue_form
121 @request.session[:user_id] = 2
119 @request.session[:user_id] = 2
122 assert_difference 'Version.count' do
120 assert_difference 'Version.count' do
123 xhr :post, :create, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'}
121 xhr :post, :create, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'}
124 end
122 end
125 version = Version.find_by_name('test_add_version_from_issue_form')
123 version = Version.find_by_name('test_add_version_from_issue_form')
126 assert_not_nil version
124 assert_not_nil version
127 assert_equal 1, version.project_id
125 assert_equal 1, version.project_id
128
126
129 assert_response :success
127 assert_response :success
130 assert_select_rjs :replace, 'issue_fixed_version_id' do
128 assert_template 'create'
131 assert_select "option[value=#{version.id}][selected=selected]"
129 assert_equal 'text/javascript', response.content_type
132 end
133 end
130 end
134
131
135 def test_create_from_issue_form_with_failure
132 def test_create_from_issue_form_with_failure
136 @request.session[:user_id] = 2
133 @request.session[:user_id] = 2
137 assert_no_difference 'Version.count' do
134 assert_no_difference 'Version.count' do
138 xhr :post, :create, :project_id => '1', :version => {:name => ''}
135 xhr :post, :create, :project_id => '1', :version => {:name => ''}
139 end
136 end
140 assert_response :success
137 assert_response :success
141 assert_select_rjs :replace_html, "ajax-modal" do
138 assert_template 'new'
142 assert_select "div#errorExplanation"
139 assert_equal 'text/javascript', response.content_type
143 end
144 end
140 end
145
141
146 def test_get_edit
142 def test_get_edit
147 @request.session[:user_id] = 2
143 @request.session[:user_id] = 2
148 get :edit, :id => 2
144 get :edit, :id => 2
149 assert_response :success
145 assert_response :success
150 assert_template 'edit'
146 assert_template 'edit'
151 end
147 end
152
148
153 def test_close_completed
149 def test_close_completed
154 Version.update_all("status = 'open'")
150 Version.update_all("status = 'open'")
155 @request.session[:user_id] = 2
151 @request.session[:user_id] = 2
156 put :close_completed, :project_id => 'ecookbook'
152 put :close_completed, :project_id => 'ecookbook'
157 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
153 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
158 assert_not_nil Version.find_by_status('closed')
154 assert_not_nil Version.find_by_status('closed')
159 end
155 end
160
156
161 def test_post_update
157 def test_post_update
162 @request.session[:user_id] = 2
158 @request.session[:user_id] = 2
163 put :update, :id => 2,
159 put :update, :id => 2,
164 :version => { :name => 'New version name',
160 :version => { :name => 'New version name',
165 :effective_date => Date.today.strftime("%Y-%m-%d")}
161 :effective_date => Date.today.strftime("%Y-%m-%d")}
166 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
162 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
167 version = Version.find(2)
163 version = Version.find(2)
168 assert_equal 'New version name', version.name
164 assert_equal 'New version name', version.name
169 assert_equal Date.today, version.effective_date
165 assert_equal Date.today, version.effective_date
170 end
166 end
171
167
172 def test_post_update_with_validation_failure
168 def test_post_update_with_validation_failure
173 @request.session[:user_id] = 2
169 @request.session[:user_id] = 2
174 put :update, :id => 2,
170 put :update, :id => 2,
175 :version => { :name => '',
171 :version => { :name => '',
176 :effective_date => Date.today.strftime("%Y-%m-%d")}
172 :effective_date => Date.today.strftime("%Y-%m-%d")}
177 assert_response :success
173 assert_response :success
178 assert_template 'edit'
174 assert_template 'edit'
179 end
175 end
180
176
181 def test_destroy
177 def test_destroy
182 @request.session[:user_id] = 2
178 @request.session[:user_id] = 2
183 assert_difference 'Version.count', -1 do
179 assert_difference 'Version.count', -1 do
184 delete :destroy, :id => 3
180 delete :destroy, :id => 3
185 end
181 end
186 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
182 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
187 assert_nil Version.find_by_id(3)
183 assert_nil Version.find_by_id(3)
188 end
184 end
189
185
190 def test_destroy_version_in_use_should_fail
186 def test_destroy_version_in_use_should_fail
191 @request.session[:user_id] = 2
187 @request.session[:user_id] = 2
192 assert_no_difference 'Version.count' do
188 assert_no_difference 'Version.count' do
193 delete :destroy, :id => 2
189 delete :destroy, :id => 2
194 end
190 end
195 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
191 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
196 assert flash[:error].match(/Unable to delete version/)
192 assert flash[:error].match(/Unable to delete version/)
197 assert Version.find_by_id(2)
193 assert Version.find_by_id(2)
198 end
194 end
199
195
200 def test_issue_status_by
196 def test_issue_status_by
201 xhr :get, :status_by, :id => 2
197 xhr :get, :status_by, :id => 2
202 assert_response :success
198 assert_response :success
203 assert_template '_issue_counts'
199 assert_template '_issue_counts'
204 end
200 end
205
201
206 def test_issue_status_by_status
202 def test_issue_status_by_status
207 xhr :get, :status_by, :id => 2, :status_by => 'status'
203 xhr :get, :status_by, :id => 2, :status_by => 'status'
208 assert_response :success
204 assert_response :success
209 assert_template '_issue_counts'
205 assert_template '_issue_counts'
210 end
206 end
211 end
207 end
General Comments 0
You need to be logged in to leave comments. Login now