##// END OF EJS Templates
code layout clean up test/functional/versions_controller_test.rb...
Toshi MARUYAMA -
r11544:784f33daa7ac
parent child
Show More
@@ -1,232 +1,238
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2013 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
20 20 class VersionsControllerTest < ActionController::TestCase
21 fixtures :projects, :versions, :issues, :users, :roles, :members, :member_roles, :enabled_modules, :issue_statuses, :issue_categories
21 fixtures :projects, :versions, :issues, :users, :roles, :members,
22 :member_roles, :enabled_modules, :issue_statuses,
23 :issue_categories
22 24
23 25 def setup
24 26 User.current = nil
25 27 end
26 28
27 29 def test_index
28 30 get :index, :project_id => 1
29 31 assert_response :success
30 32 assert_template 'index'
31 33 assert_not_nil assigns(:versions)
32 34 # Version with no date set appears
33 35 assert assigns(:versions).include?(Version.find(3))
34 36 # Completed version doesn't appear
35 37 assert !assigns(:versions).include?(Version.find(1))
36 38 # Context menu on issues
37 39 assert_select "script", :text => Regexp.new(Regexp.escape("contextMenuInit('/issues/context_menu')"))
38 40 # Links to versions anchors
39 41 assert_tag 'a', :attributes => {:href => '#2.0'},
40 42 :ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}}
41 43 # Links to completed versions in the sidebar
42 44 assert_tag 'a', :attributes => {:href => '/versions/1'},
43 45 :ancestor => {:tag => 'div', :attributes => {:id => 'sidebar'}}
44 46 end
45 47
46 48 def test_index_with_completed_versions
47 49 get :index, :project_id => 1, :completed => 1
48 50 assert_response :success
49 51 assert_template 'index'
50 52 assert_not_nil assigns(:versions)
51 53 # Version with no date set appears
52 54 assert assigns(:versions).include?(Version.find(3))
53 55 # Completed version appears
54 56 assert assigns(:versions).include?(Version.find(1))
55 57 end
56 58
57 59 def test_index_with_tracker_ids
58 60 get :index, :project_id => 1, :tracker_ids => [1, 3]
59 61 assert_response :success
60 62 assert_template 'index'
61 63 assert_not_nil assigns(:issues_by_version)
62 64 assert_nil assigns(:issues_by_version).values.flatten.detect {|issue| issue.tracker_id == 2}
63 65 end
64 66
65 67 def test_index_showing_subprojects_versions
66 68 @subproject_version = Version.create!(:project => Project.find(3), :name => "Subproject version")
67 69 get :index, :project_id => 1, :with_subprojects => 1
68 70 assert_response :success
69 71 assert_template 'index'
70 72 assert_not_nil assigns(:versions)
71 73
72 74 assert assigns(:versions).include?(Version.find(4)), "Shared version not found"
73 75 assert assigns(:versions).include?(@subproject_version), "Subproject version not found"
74 76 end
75 77
76 78 def test_index_should_prepend_shared_versions
77 79 get :index, :project_id => 1
78 80 assert_response :success
79 81
80 82 assert_select '#sidebar' do
81 83 assert_select 'a[href=?]', '#2.0', :text => '2.0'
82 84 assert_select 'a[href=?]', '#subproject1-2.0', :text => 'eCookbook Subproject 1 - 2.0'
83 85 end
84 86 assert_select '#content' do
85 87 assert_select 'a[name=?]', '2.0', :text => '2.0'
86 88 assert_select 'a[name=?]', 'subproject1-2.0', :text => 'eCookbook Subproject 1 - 2.0'
87 89 end
88 90 end
89 91
90 92 def test_show
91 93 get :show, :id => 2
92 94 assert_response :success
93 95 assert_template 'show'
94 96 assert_not_nil assigns(:version)
95 97
96 98 assert_tag :tag => 'h2', :content => /1.0/
97 99 end
98 100
99 101 def test_show_should_display_nil_counts
100 102 with_settings :default_language => 'en' do
101 103 get :show, :id => 2, :status_by => 'category'
102 104 assert_response :success
103 105 assert_select 'div#status_by' do
104 106 assert_select 'select[name=status_by]' do
105 107 assert_select 'option[value=category][selected=selected]'
106 108 end
107 109 assert_select 'a', :text => 'none'
108 110 end
109 111 end
110 112 end
111 113
112 114 def test_new
113 115 @request.session[:user_id] = 2
114 116 get :new, :project_id => '1'
115 117 assert_response :success
116 118 assert_template 'new'
117 119 end
118 120
119 121 def test_new_from_issue_form
120 122 @request.session[:user_id] = 2
121 123 xhr :get, :new, :project_id => '1'
122 124 assert_response :success
123 125 assert_template 'new'
124 126 assert_equal 'text/javascript', response.content_type
125 127 end
126 128
127 129 def test_create
128 130 @request.session[:user_id] = 2 # manager
129 131 assert_difference 'Version.count' do
130 132 post :create, :project_id => '1', :version => {:name => 'test_add_version'}
131 133 end
132 134 assert_redirected_to '/projects/ecookbook/settings/versions'
133 135 version = Version.find_by_name('test_add_version')
134 136 assert_not_nil version
135 137 assert_equal 1, version.project_id
136 138 end
137 139
138 140 def test_create_from_issue_form
139 141 @request.session[:user_id] = 2
140 142 assert_difference 'Version.count' do
141 143 xhr :post, :create, :project_id => '1', :version => {:name => 'test_add_version_from_issue_form'}
142 144 end
143 145 version = Version.find_by_name('test_add_version_from_issue_form')
144 146 assert_not_nil version
145 147 assert_equal 1, version.project_id
146 148
147 149 assert_response :success
148 150 assert_template 'create'
149 151 assert_equal 'text/javascript', response.content_type
150 152 assert_include 'test_add_version_from_issue_form', response.body
151 153 end
152 154
153 155 def test_create_from_issue_form_with_failure
154 156 @request.session[:user_id] = 2
155 157 assert_no_difference 'Version.count' do
156 158 xhr :post, :create, :project_id => '1', :version => {:name => ''}
157 159 end
158 160 assert_response :success
159 161 assert_template 'new'
160 162 assert_equal 'text/javascript', response.content_type
161 163 end
162 164
163 165 def test_get_edit
164 166 @request.session[:user_id] = 2
165 167 get :edit, :id => 2
166 168 assert_response :success
167 169 assert_template 'edit'
168 170 end
169 171
170 172 def test_close_completed
171 173 Version.update_all("status = 'open'")
172 174 @request.session[:user_id] = 2
173 175 put :close_completed, :project_id => 'ecookbook'
174 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
176 assert_redirected_to :controller => 'projects', :action => 'settings',
177 :tab => 'versions', :id => 'ecookbook'
175 178 assert_not_nil Version.find_by_status('closed')
176 179 end
177 180
178 181 def test_post_update
179 182 @request.session[:user_id] = 2
180 183 put :update, :id => 2,
181 :version => { :name => 'New version name',
182 :effective_date => Date.today.strftime("%Y-%m-%d")}
183 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
184 :version => {:name => 'New version name',
185 :effective_date => Date.today.strftime("%Y-%m-%d")}
186 assert_redirected_to :controller => 'projects', :action => 'settings',
187 :tab => 'versions', :id => 'ecookbook'
184 188 version = Version.find(2)
185 189 assert_equal 'New version name', version.name
186 190 assert_equal Date.today, version.effective_date
187 191 end
188 192
189 193 def test_post_update_with_validation_failure
190 194 @request.session[:user_id] = 2
191 195 put :update, :id => 2,
192 196 :version => { :name => '',
193 197 :effective_date => Date.today.strftime("%Y-%m-%d")}
194 198 assert_response :success
195 199 assert_template 'edit'
196 200 end
197 201
198 202 def test_destroy
199 203 @request.session[:user_id] = 2
200 204 assert_difference 'Version.count', -1 do
201 205 delete :destroy, :id => 3
202 206 end
203 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
207 assert_redirected_to :controller => 'projects', :action => 'settings',
208 :tab => 'versions', :id => 'ecookbook'
204 209 assert_nil Version.find_by_id(3)
205 210 end
206 211
207 212 def test_destroy_version_in_use_should_fail
208 213 @request.session[:user_id] = 2
209 214 assert_no_difference 'Version.count' do
210 215 delete :destroy, :id => 2
211 216 end
212 assert_redirected_to :controller => 'projects', :action => 'settings', :tab => 'versions', :id => 'ecookbook'
217 assert_redirected_to :controller => 'projects', :action => 'settings',
218 :tab => 'versions', :id => 'ecookbook'
213 219 assert flash[:error].match(/Unable to delete version/)
214 220 assert Version.find_by_id(2)
215 221 end
216 222
217 223 def test_issue_status_by
218 224 xhr :get, :status_by, :id => 2
219 225 assert_response :success
220 226 assert_template 'status_by'
221 227 assert_template '_issue_counts'
222 228 end
223 229
224 230 def test_issue_status_by_status
225 231 xhr :get, :status_by, :id => 2, :status_by => 'status'
226 232 assert_response :success
227 233 assert_template 'status_by'
228 234 assert_template '_issue_counts'
229 235 assert_include 'Assigned', response.body
230 236 assert_include 'Closed', response.body
231 237 end
232 238 end
General Comments 0
You need to be logged in to leave comments. Login now