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