##// 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 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class IssueCategoriesController < ApplicationController
19 19 menu_item :settings
20 20 model_object IssueCategory
21 21 before_filter :find_model_object, :except => [:index, :new, :create]
22 22 before_filter :find_project_from_association, :except => [:index, :new, :create]
23 23 before_filter :find_project_by_project_id, :only => [:index, :new, :create]
24 24 before_filter :authorize
25 25 accept_api_auth :index, :show, :create, :update, :destroy
26 26
27 27 def index
28 28 respond_to do |format|
29 29 format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project }
30 30 format.api { @categories = @project.issue_categories.all }
31 31 end
32 32 end
33 33
34 34 def show
35 35 respond_to do |format|
36 36 format.html { redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project }
37 37 format.api
38 38 end
39 39 end
40 40
41 41 def new
42 42 @category = @project.issue_categories.build
43 43 @category.safe_attributes = params[:issue_category]
44 44
45 45 respond_to do |format|
46 46 format.html
47 format.js do
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
47 format.js
54 48 end
55 49 end
56 50
57 51 def create
58 52 @category = @project.issue_categories.build
59 53 @category.safe_attributes = params[:issue_category]
60 54 if @category.save
61 55 respond_to do |format|
62 56 format.html do
63 57 flash[:notice] = l(:notice_successful_create)
64 58 redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
65 59 end
66 format.js do
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
60 format.js
74 61 format.api { render :action => 'show', :status => :created, :location => issue_category_path(@category) }
75 62 end
76 63 else
77 64 respond_to do |format|
78 65 format.html { render :action => 'new'}
79 format.js do
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
66 format.js { render :action => 'new'}
85 67 format.api { render_validation_errors(@category) }
86 68 end
87 69 end
88 70 end
89 71
90 72 def edit
91 73 end
92 74
93 75 def update
94 76 @category.safe_attributes = params[:issue_category]
95 77 if @category.save
96 78 respond_to do |format|
97 79 format.html {
98 80 flash[:notice] = l(:notice_successful_update)
99 81 redirect_to :controller => 'projects', :action => 'settings', :tab => 'categories', :id => @project
100 82 }
101 83 format.api { render_api_ok }
102 84 end
103 85 else
104 86 respond_to do |format|
105 87 format.html { render :action => 'edit' }
106 88 format.api { render_validation_errors(@category) }
107 89 end
108 90 end
109 91 end
110 92
111 93 def destroy
112 94 @issue_count = @category.issues.size
113 95 if @issue_count == 0 || params[:todo] || api_request?
114 96 reassign_to = nil
115 97 if params[:reassign_to_id] && (params[:todo] == 'reassign' || params[:todo].blank?)
116 98 reassign_to = @project.issue_categories.find_by_id(params[:reassign_to_id])
117 99 end
118 100 @category.destroy(reassign_to)
119 101 respond_to do |format|
120 102 format.html { redirect_to :controller => 'projects', :action => 'settings', :id => @project, :tab => 'categories' }
121 103 format.api { render_api_ok }
122 104 end
123 105 return
124 106 end
125 107 @categories = @project.issue_categories - [@category]
126 108 end
127 109
128 110 private
129 111 # Wrap ApplicationController's find_model_object method to set
130 112 # @category instead of just @issue_category
131 113 def find_model_object
132 114 super
133 115 @category = @object
134 116 end
135 117 end
@@ -1,205 +1,187
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 class VersionsController < ApplicationController
19 19 menu_item :roadmap
20 20 model_object Version
21 21 before_filter :find_model_object, :except => [:index, :new, :create, :close_completed]
22 22 before_filter :find_project_from_association, :except => [:index, :new, :create, :close_completed]
23 23 before_filter :find_project, :only => [:index, :new, :create, :close_completed]
24 24 before_filter :authorize
25 25
26 26 accept_api_auth :index, :show, :create, :update, :destroy
27 27
28 28 helper :custom_fields
29 29 helper :projects
30 30
31 31 def index
32 32 respond_to do |format|
33 33 format.html {
34 34 @trackers = @project.trackers.find(:all, :order => 'position')
35 35 retrieve_selected_tracker_ids(@trackers, @trackers.select {|t| t.is_in_roadmap?})
36 36 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
37 37 project_ids = @with_subprojects ? @project.self_and_descendants.collect(&:id) : [@project.id]
38 38
39 39 @versions = @project.shared_versions || []
40 40 @versions += @project.rolled_up_versions.visible if @with_subprojects
41 41 @versions = @versions.uniq.sort
42 42 unless params[:completed]
43 43 @completed_versions = @versions.select {|version| version.closed? || version.completed? }
44 44 @versions -= @completed_versions
45 45 end
46 46
47 47 @issues_by_version = {}
48 48 if @selected_tracker_ids.any? && @versions.any?
49 49 issues = Issue.visible.all(
50 50 :include => [:project, :status, :tracker, :priority, :fixed_version],
51 51 :conditions => {:tracker_id => @selected_tracker_ids, :project_id => project_ids, :fixed_version_id => @versions.map(&:id)},
52 52 :order => "#{Project.table_name}.lft, #{Tracker.table_name}.position, #{Issue.table_name}.id"
53 53 )
54 54 @issues_by_version = issues.group_by(&:fixed_version)
55 55 end
56 56 @versions.reject! {|version| !project_ids.include?(version.project_id) && @issues_by_version[version].blank?}
57 57 }
58 58 format.api {
59 59 @versions = @project.shared_versions.all
60 60 }
61 61 end
62 62 end
63 63
64 64 def show
65 65 respond_to do |format|
66 66 format.html {
67 67 @issues = @version.fixed_issues.visible.find(:all,
68 68 :include => [:status, :tracker, :priority],
69 69 :order => "#{Tracker.table_name}.position, #{Issue.table_name}.id")
70 70 }
71 71 format.api
72 72 end
73 73 end
74 74
75 75 def new
76 76 @version = @project.versions.build
77 77 @version.safe_attributes = params[:version]
78 78
79 79 respond_to do |format|
80 80 format.html
81 format.js do
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
81 format.js
88 82 end
89 83 end
90 84
91 85 def create
92 86 @version = @project.versions.build
93 87 if params[:version]
94 88 attributes = params[:version].dup
95 89 attributes.delete('sharing') unless attributes.nil? || @version.allowed_sharings.include?(attributes['sharing'])
96 90 @version.safe_attributes = attributes
97 91 end
98 92
99 93 if request.post?
100 94 if @version.save
101 95 respond_to do |format|
102 96 format.html do
103 97 flash[:notice] = l(:notice_successful_create)
104 98 redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
105 99 end
106 format.js do
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
100 format.js
114 101 format.api do
115 102 render :action => 'show', :status => :created, :location => version_url(@version)
116 103 end
117 104 end
118 105 else
119 106 respond_to do |format|
120 107 format.html { render :action => 'new' }
121 format.js do
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
108 format.js { render :action => 'new' }
127 109 format.api { render_validation_errors(@version) }
128 110 end
129 111 end
130 112 end
131 113 end
132 114
133 115 def edit
134 116 end
135 117
136 118 def update
137 119 if request.put? && params[:version]
138 120 attributes = params[:version].dup
139 121 attributes.delete('sharing') unless @version.allowed_sharings.include?(attributes['sharing'])
140 122 @version.safe_attributes = attributes
141 123 if @version.save
142 124 respond_to do |format|
143 125 format.html {
144 126 flash[:notice] = l(:notice_successful_update)
145 127 redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
146 128 }
147 129 format.api { render_api_ok }
148 130 end
149 131 else
150 132 respond_to do |format|
151 133 format.html { render :action => 'edit' }
152 134 format.api { render_validation_errors(@version) }
153 135 end
154 136 end
155 137 end
156 138 end
157 139
158 140 def close_completed
159 141 if request.put?
160 142 @project.close_completed_versions
161 143 end
162 144 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
163 145 end
164 146
165 147 def destroy
166 148 if @version.fixed_issues.empty?
167 149 @version.destroy
168 150 respond_to do |format|
169 151 format.html { redirect_back_or_default :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project }
170 152 format.api { render_api_ok }
171 153 end
172 154 else
173 155 respond_to do |format|
174 156 format.html {
175 157 flash[:error] = l(:notice_unable_delete_version)
176 158 redirect_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => @project
177 159 }
178 160 format.api { head :unprocessable_entity }
179 161 end
180 162 end
181 163 end
182 164
183 165 def status_by
184 166 respond_to do |format|
185 167 format.html { render :action => 'show' }
186 168 format.js { render(:update) {|page| page.replace_html 'status_by', render_issue_status_by(@version, params[:status_by])} }
187 169 end
188 170 end
189 171
190 172 private
191 173 def find_project
192 174 @project = Project.find(params[:project_id])
193 175 rescue ActiveRecord::RecordNotFound
194 176 render_404
195 177 end
196 178
197 179 def retrieve_selected_tracker_ids(selectable_trackers, default_trackers=nil)
198 180 if ids = params[:tracker_ids]
199 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 182 else
201 183 @selected_tracker_ids = (default_trackers || selectable_trackers).collect {|t| t.id.to_s }
202 184 end
203 185 end
204 186
205 187 end
@@ -1,144 +1,151
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19 require 'issue_categories_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class IssueCategoriesController; def rescue_action(e) raise e end; end
23 23
24 24 class IssueCategoriesControllerTest < ActionController::TestCase
25 25 fixtures :projects, :users, :members, :member_roles, :roles, :enabled_modules, :issue_categories
26 26
27 27 def setup
28 28 @controller = IssueCategoriesController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 User.current = nil
32 32 @request.session[:user_id] = 2
33 33 end
34 34
35 35 def test_new
36 36 @request.session[:user_id] = 2 # manager
37 37 get :new, :project_id => '1'
38 38 assert_response :success
39 39 assert_template 'new'
40 40 assert_select 'input[name=?]', 'issue_category[name]'
41 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 52 def test_create
44 53 @request.session[:user_id] = 2 # manager
45 54 assert_difference 'IssueCategory.count' do
46 55 post :create, :project_id => '1', :issue_category => {:name => 'New category'}
47 56 end
48 57 assert_redirected_to '/projects/ecookbook/settings/categories'
49 58 category = IssueCategory.find_by_name('New category')
50 59 assert_not_nil category
51 60 assert_equal 1, category.project_id
52 61 end
53 62
54 63 def test_create_failure
55 64 @request.session[:user_id] = 2
56 65 post :create, :project_id => '1', :issue_category => {:name => ''}
57 66 assert_response :success
58 67 assert_template 'new'
59 68 end
60 69
61 70 def test_create_from_issue_form
62 71 @request.session[:user_id] = 2 # manager
63 72 assert_difference 'IssueCategory.count' do
64 73 xhr :post, :create, :project_id => '1', :issue_category => {:name => 'New category'}
65 74 end
66 75 category = IssueCategory.first(:order => 'id DESC')
67 76 assert_equal 'New category', category.name
68 77
69 78 assert_response :success
70 assert_select_rjs :replace, 'issue_category_id' do
71 assert_select "option[value=#{category.id}][selected=selected]"
72 end
79 assert_template 'create'
80 assert_equal 'text/javascript', response.content_type
73 81 end
74 82
75 83 def test_create_from_issue_form_with_failure
76 84 @request.session[:user_id] = 2 # manager
77 85 assert_no_difference 'IssueCategory.count' do
78 86 xhr :post, :create, :project_id => '1', :issue_category => {:name => ''}
79 87 end
80 88
81 89 assert_response :success
82 assert_select_rjs :replace_html, "ajax-modal" do
83 assert_select "div#errorExplanation"
84 end
90 assert_template 'new'
91 assert_equal 'text/javascript', response.content_type
85 92 end
86 93
87 94 def test_edit
88 95 @request.session[:user_id] = 2
89 96 get :edit, :id => 2
90 97 assert_response :success
91 98 assert_template 'edit'
92 99 assert_select 'input[name=?][value=?]', 'issue_category[name]', 'Recipes'
93 100 end
94 101
95 102 def test_update
96 103 assert_no_difference 'IssueCategory.count' do
97 104 put :update, :id => 2, :issue_category => { :name => 'Testing' }
98 105 end
99 106 assert_redirected_to '/projects/ecookbook/settings/categories'
100 107 assert_equal 'Testing', IssueCategory.find(2).name
101 108 end
102 109
103 110 def test_update_failure
104 111 put :update, :id => 2, :issue_category => { :name => '' }
105 112 assert_response :success
106 113 assert_template 'edit'
107 114 end
108 115
109 116 def test_update_not_found
110 117 put :update, :id => 97, :issue_category => { :name => 'Testing' }
111 118 assert_response 404
112 119 end
113 120
114 121 def test_destroy_category_not_in_use
115 122 delete :destroy, :id => 2
116 123 assert_redirected_to '/projects/ecookbook/settings/categories'
117 124 assert_nil IssueCategory.find_by_id(2)
118 125 end
119 126
120 127 def test_destroy_category_in_use
121 128 delete :destroy, :id => 1
122 129 assert_response :success
123 130 assert_template 'destroy'
124 131 assert_not_nil IssueCategory.find_by_id(1)
125 132 end
126 133
127 134 def test_destroy_category_in_use_with_reassignment
128 135 issue = Issue.find(:first, :conditions => {:category_id => 1})
129 136 delete :destroy, :id => 1, :todo => 'reassign', :reassign_to_id => 2
130 137 assert_redirected_to '/projects/ecookbook/settings/categories'
131 138 assert_nil IssueCategory.find_by_id(1)
132 139 # check that the issue was reassign
133 140 assert_equal 2, issue.reload.category_id
134 141 end
135 142
136 143 def test_destroy_category_in_use_without_reassignment
137 144 issue = Issue.find(:first, :conditions => {:category_id => 1})
138 145 delete :destroy, :id => 1, :todo => 'nullify'
139 146 assert_redirected_to '/projects/ecookbook/settings/categories'
140 147 assert_nil IssueCategory.find_by_id(1)
141 148 # check that the issue category was nullified
142 149 assert_nil issue.reload.category_id
143 150 end
144 151 end
@@ -1,211 +1,207
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19 require 'versions_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class VersionsController; def rescue_action(e) raise e end; end
23 23
24 24 class VersionsControllerTest < ActionController::TestCase
25 25 fixtures :projects, :versions, :issues, :users, :roles, :members, :member_roles, :enabled_modules, :issue_statuses
26 26
27 27 def setup
28 28 @controller = VersionsController.new
29 29 @request = ActionController::TestRequest.new
30 30 @response = ActionController::TestResponse.new
31 31 User.current = nil
32 32 end
33 33
34 34 def test_index
35 35 get :index, :project_id => 1
36 36 assert_response :success
37 37 assert_template 'index'
38 38 assert_not_nil assigns(:versions)
39 39 # Version with no date set appears
40 40 assert assigns(:versions).include?(Version.find(3))
41 41 # Completed version doesn't appear
42 42 assert !assigns(:versions).include?(Version.find(1))
43 43 # Context menu on issues
44 44 assert_select "script", :text => Regexp.new(Regexp.escape("new ContextMenu('/issues/context_menu')"))
45 45 # Links to versions anchors
46 46 assert_tag 'a', :attributes => {:href => '#2.0'},
47 47 :ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}}
48 48 # Links to completed versions in the sidebar
49 49 assert_tag 'a', :attributes => {:href => '/versions/1'},
50 50 :ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}}
51 51 end
52 52
53 53 def test_index_with_completed_versions
54 54 get :index, :project_id => 1, :completed => 1
55 55 assert_response :success
56 56 assert_template 'index'
57 57 assert_not_nil assigns(:versions)
58 58 # Version with no date set appears
59 59 assert assigns(:versions).include?(Version.find(3))
60 60 # Completed version appears
61 61 assert assigns(:versions).include?(Version.find(1))
62 62 end
63 63
64 64 def test_index_with_tracker_ids
65 65 get :index, :project_id => 1, :tracker_ids => [1, 3]
66 66 assert_response :success
67 67 assert_template 'index'
68 68 assert_not_nil assigns(:issues_by_version)
69 69 assert_nil assigns(:issues_by_version).values.flatten.detect {|issue| issue.tracker_id == 2}
70 70 end
71 71
72 72 def test_index_showing_subprojects_versions
73 73 @subproject_version = Version.create!(:project => Project.find(3), :name => "Subproject version")
74 74 get :index, :project_id => 1, :with_subprojects => 1
75 75 assert_response :success
76 76 assert_template 'index'
77 77 assert_not_nil assigns(:versions)
78 78
79 79 assert assigns(:versions).include?(Version.find(4)), "Shared version not found"
80 80 assert assigns(:versions).include?(@subproject_version), "Subproject version not found"
81 81 end
82 82
83 83 def test_show
84 84 get :show, :id => 2
85 85 assert_response :success
86 86 assert_template 'show'
87 87 assert_not_nil assigns(:version)
88 88
89 89 assert_tag :tag => 'h2', :content => /1.0/
90 90 end
91 91
92 92 def test_new
93 93 @request.session[:user_id] = 2
94 94 get :new, :project_id => '1'
95 95 assert_response :success
96 96 assert_template 'new'
97 97 end
98 98
99 99 def test_new_from_issue_form
100 100 @request.session[:user_id] = 2
101 101 xhr :get, :new, :project_id => '1'
102 102 assert_response :success
103 assert_select_rjs :replace_html, "ajax-modal" do
104 assert_select "form[action=/projects/ecookbook/versions]"
105 assert_select "input#version_name"
106 end
103 assert_template 'new'
104 assert_equal 'text/javascript', response.content_type
107 105 end
108 106
109 107 def test_create
110 108 @request.session[:user_id] = 2 # manager
111 109 assert_difference 'Version.count' do
112 110 post :create, :project_id => '1', :version => {:name => 'test_add_version'}
113 111 end
114 112 assert_redirected_to '/projects/ecookbook/settings/versions'
115 113 version = Version.find_by_name('test_add_version')
116 114 assert_not_nil version
117 115 assert_equal 1, version.project_id
118 116 end
119 117
120 118 def test_create_from_issue_form
121 119 @request.session[:user_id] = 2
122 120 assert_difference 'Version.count' do
123 121 xhr :post, :create, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'}
124 122 end
125 123 version = Version.find_by_name('test_add_version_from_issue_form')
126 124 assert_not_nil version
127 125 assert_equal 1, version.project_id
128 126
129 127 assert_response :success
130 assert_select_rjs :replace, 'issue_fixed_version_id' do
131 assert_select "option[value=#{version.id}][selected=selected]"
132 end
128 assert_template 'create'
129 assert_equal 'text/javascript', response.content_type
133 130 end
134 131
135 132 def test_create_from_issue_form_with_failure
136 133 @request.session[:user_id] = 2
137 134 assert_no_difference 'Version.count' do
138 135 xhr :post, :create, :project_id => '1', :version => {:name => ''}
139 136 end
140 137 assert_response :success
141 assert_select_rjs :replace_html, "ajax-modal" do
142 assert_select "div#errorExplanation"
143 end
138 assert_template 'new'
139 assert_equal 'text/javascript', response.content_type
144 140 end
145 141
146 142 def test_get_edit
147 143 @request.session[:user_id] = 2
148 144 get :edit, :id => 2
149 145 assert_response :success
150 146 assert_template 'edit'
151 147 end
152 148
153 149 def test_close_completed
154 150 Version.update_all("status = 'open'")
155 151 @request.session[:user_id] = 2
156 152 put :close_completed, :project_id => 'ecookbook'
157 153 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
158 154 assert_not_nil Version.find_by_status('closed')
159 155 end
160 156
161 157 def test_post_update
162 158 @request.session[:user_id] = 2
163 159 put :update, :id => 2,
164 160 :version => { :name => 'New version name',
165 161 :effective_date => Date.today.strftime("%Y-%m-%d")}
166 162 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
167 163 version = Version.find(2)
168 164 assert_equal 'New version name', version.name
169 165 assert_equal Date.today, version.effective_date
170 166 end
171 167
172 168 def test_post_update_with_validation_failure
173 169 @request.session[:user_id] = 2
174 170 put :update, :id => 2,
175 171 :version => { :name => '',
176 172 :effective_date => Date.today.strftime("%Y-%m-%d")}
177 173 assert_response :success
178 174 assert_template 'edit'
179 175 end
180 176
181 177 def test_destroy
182 178 @request.session[:user_id] = 2
183 179 assert_difference 'Version.count', -1 do
184 180 delete :destroy, :id => 3
185 181 end
186 182 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
187 183 assert_nil Version.find_by_id(3)
188 184 end
189 185
190 186 def test_destroy_version_in_use_should_fail
191 187 @request.session[:user_id] = 2
192 188 assert_no_difference 'Version.count' do
193 189 delete :destroy, :id => 2
194 190 end
195 191 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
196 192 assert flash[:error].match(/Unable to delete version/)
197 193 assert Version.find_by_id(2)
198 194 end
199 195
200 196 def test_issue_status_by
201 197 xhr :get, :status_by, :id => 2
202 198 assert_response :success
203 199 assert_template '_issue_counts'
204 200 end
205 201
206 202 def test_issue_status_by_status
207 203 xhr :get, :status_by, :id => 2, :status_by => 'status'
208 204 assert_response :success
209 205 assert_template '_issue_counts'
210 206 end
211 207 end
General Comments 0
You need to be logged in to leave comments. Login now