To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 4e / 4ed99aa85a5cef8603d38788ee6606bb9b047f2c.svn-base @ 1298:4f746d8966dd
History | View | Annotate | Download (11.5 KB)
| 1 |
# Redmine - project management software |
|---|---|
| 2 |
# Copyright (C) 2006-2012 Jean-Philippe Lang |
| 3 |
# |
| 4 |
# This program is free software; you can redistribute it and/or |
| 5 |
# modify it under the terms of the GNU General Public License |
| 6 |
# as published by the Free Software Foundation; either version 2 |
| 7 |
# of the License, or (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 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 |
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 |
|
| 18 |
require File.expand_path('../../test_helper', __FILE__)
|
| 19 |
|
| 20 |
class QueriesControllerTest < ActionController::TestCase |
| 21 |
fixtures :projects, :users, :members, :member_roles, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries, :enabled_modules |
| 22 |
|
| 23 |
def setup |
| 24 |
User.current = nil |
| 25 |
end |
| 26 |
|
| 27 |
def test_new_project_query |
| 28 |
@request.session[:user_id] = 2 |
| 29 |
get :new, :project_id => 1 |
| 30 |
assert_response :success |
| 31 |
assert_template 'new' |
| 32 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 33 |
:name => 'query[is_public]', |
| 34 |
:checked => nil } |
| 35 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 36 |
:name => 'query_is_for_all', |
| 37 |
:checked => nil, |
| 38 |
:disabled => nil } |
| 39 |
assert_select 'select[name=?]', 'c[]' do |
| 40 |
assert_select 'option[value=tracker]' |
| 41 |
assert_select 'option[value=subject]' |
| 42 |
end |
| 43 |
end |
| 44 |
|
| 45 |
def test_new_global_query |
| 46 |
@request.session[:user_id] = 2 |
| 47 |
get :new |
| 48 |
assert_response :success |
| 49 |
assert_template 'new' |
| 50 |
assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 51 |
:name => 'query[is_public]' } |
| 52 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 53 |
:name => 'query_is_for_all', |
| 54 |
:checked => 'checked', |
| 55 |
:disabled => nil } |
| 56 |
end |
| 57 |
|
| 58 |
def test_new_on_invalid_project |
| 59 |
@request.session[:user_id] = 2 |
| 60 |
get :new, :project_id => 'invalid' |
| 61 |
assert_response 404 |
| 62 |
end |
| 63 |
|
| 64 |
def test_create_project_public_query |
| 65 |
@request.session[:user_id] = 2 |
| 66 |
post :create, |
| 67 |
:project_id => 'ecookbook', |
| 68 |
:default_columns => '1', |
| 69 |
:f => ["status_id", "assigned_to_id"], |
| 70 |
:op => {"assigned_to_id" => "=", "status_id" => "o"},
|
| 71 |
:v => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
|
| 72 |
:query => {"name" => "test_new_project_public_query", "is_public" => "1"}
|
| 73 |
|
| 74 |
q = Query.find_by_name('test_new_project_public_query')
|
| 75 |
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
| 76 |
assert q.is_public? |
| 77 |
assert q.has_default_columns? |
| 78 |
assert q.valid? |
| 79 |
end |
| 80 |
|
| 81 |
def test_create_project_private_query |
| 82 |
@request.session[:user_id] = 3 |
| 83 |
post :create, |
| 84 |
:project_id => 'ecookbook', |
| 85 |
:default_columns => '1', |
| 86 |
:fields => ["status_id", "assigned_to_id"], |
| 87 |
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
| 88 |
:values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
|
| 89 |
:query => {"name" => "test_new_project_private_query", "is_public" => "1"}
|
| 90 |
|
| 91 |
q = Query.find_by_name('test_new_project_private_query')
|
| 92 |
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
| 93 |
assert !q.is_public? |
| 94 |
assert q.has_default_columns? |
| 95 |
assert q.valid? |
| 96 |
end |
| 97 |
|
| 98 |
def test_create_global_private_query_with_custom_columns |
| 99 |
@request.session[:user_id] = 3 |
| 100 |
post :create, |
| 101 |
:fields => ["status_id", "assigned_to_id"], |
| 102 |
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
| 103 |
:values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
|
| 104 |
:query => {"name" => "test_new_global_private_query", "is_public" => "1"},
|
| 105 |
:c => ["", "tracker", "subject", "priority", "category"] |
| 106 |
|
| 107 |
q = Query.find_by_name('test_new_global_private_query')
|
| 108 |
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q |
| 109 |
assert !q.is_public? |
| 110 |
assert !q.has_default_columns? |
| 111 |
assert_equal [:tracker, :subject, :priority, :category], q.columns.collect {|c| c.name}
|
| 112 |
assert q.valid? |
| 113 |
end |
| 114 |
|
| 115 |
def test_create_global_query_with_custom_filters |
| 116 |
@request.session[:user_id] = 3 |
| 117 |
post :create, |
| 118 |
:fields => ["assigned_to_id"], |
| 119 |
:operators => {"assigned_to_id" => "="},
|
| 120 |
:values => { "assigned_to_id" => ["me"]},
|
| 121 |
:query => {"name" => "test_new_global_query"}
|
| 122 |
|
| 123 |
q = Query.find_by_name('test_new_global_query')
|
| 124 |
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q |
| 125 |
assert !q.has_filter?(:status_id) |
| 126 |
assert_equal ['assigned_to_id'], q.filters.keys |
| 127 |
assert q.valid? |
| 128 |
end |
| 129 |
|
| 130 |
def test_create_with_sort |
| 131 |
@request.session[:user_id] = 1 |
| 132 |
post :create, |
| 133 |
:default_columns => '1', |
| 134 |
:operators => {"status_id" => "o"},
|
| 135 |
:values => {"status_id" => ["1"]},
|
| 136 |
:query => {:name => "test_new_with_sort",
|
| 137 |
:is_public => "1", |
| 138 |
:sort_criteria => {"0" => ["due_date", "desc"], "1" => ["tracker", ""]}}
|
| 139 |
|
| 140 |
query = Query.find_by_name("test_new_with_sort")
|
| 141 |
assert_not_nil query |
| 142 |
assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria |
| 143 |
end |
| 144 |
|
| 145 |
def test_create_with_failure |
| 146 |
@request.session[:user_id] = 2 |
| 147 |
assert_no_difference '::Query.count' do |
| 148 |
post :create, :project_id => 'ecookbook', :query => {:name => ''}
|
| 149 |
end |
| 150 |
assert_response :success |
| 151 |
assert_template 'new' |
| 152 |
assert_select 'input[name=?]', 'query[name]' |
| 153 |
end |
| 154 |
|
| 155 |
def test_edit_global_public_query |
| 156 |
@request.session[:user_id] = 1 |
| 157 |
get :edit, :id => 4 |
| 158 |
assert_response :success |
| 159 |
assert_template 'edit' |
| 160 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 161 |
:name => 'query[is_public]', |
| 162 |
:checked => 'checked' } |
| 163 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 164 |
:name => 'query_is_for_all', |
| 165 |
:checked => 'checked', |
| 166 |
:disabled => 'disabled' } |
| 167 |
end |
| 168 |
|
| 169 |
def test_edit_global_private_query |
| 170 |
@request.session[:user_id] = 3 |
| 171 |
get :edit, :id => 3 |
| 172 |
assert_response :success |
| 173 |
assert_template 'edit' |
| 174 |
assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 175 |
:name => 'query[is_public]' } |
| 176 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 177 |
:name => 'query_is_for_all', |
| 178 |
:checked => 'checked', |
| 179 |
:disabled => 'disabled' } |
| 180 |
end |
| 181 |
|
| 182 |
def test_edit_project_private_query |
| 183 |
@request.session[:user_id] = 3 |
| 184 |
get :edit, :id => 2 |
| 185 |
assert_response :success |
| 186 |
assert_template 'edit' |
| 187 |
assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 188 |
:name => 'query[is_public]' } |
| 189 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 190 |
:name => 'query_is_for_all', |
| 191 |
:checked => nil, |
| 192 |
:disabled => nil } |
| 193 |
end |
| 194 |
|
| 195 |
def test_edit_project_public_query |
| 196 |
@request.session[:user_id] = 2 |
| 197 |
get :edit, :id => 1 |
| 198 |
assert_response :success |
| 199 |
assert_template 'edit' |
| 200 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 201 |
:name => 'query[is_public]', |
| 202 |
:checked => 'checked' |
| 203 |
} |
| 204 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 205 |
:name => 'query_is_for_all', |
| 206 |
:checked => nil, |
| 207 |
:disabled => 'disabled' } |
| 208 |
end |
| 209 |
|
| 210 |
def test_edit_sort_criteria |
| 211 |
@request.session[:user_id] = 1 |
| 212 |
get :edit, :id => 5 |
| 213 |
assert_response :success |
| 214 |
assert_template 'edit' |
| 215 |
assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' },
|
| 216 |
:child => { :tag => 'option', :attributes => { :value => 'priority',
|
| 217 |
:selected => 'selected' } } |
| 218 |
assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' },
|
| 219 |
:child => { :tag => 'option', :attributes => { :value => 'desc',
|
| 220 |
:selected => 'selected' } } |
| 221 |
end |
| 222 |
|
| 223 |
def test_edit_invalid_query |
| 224 |
@request.session[:user_id] = 2 |
| 225 |
get :edit, :id => 99 |
| 226 |
assert_response 404 |
| 227 |
end |
| 228 |
|
| 229 |
def test_udpate_global_private_query |
| 230 |
@request.session[:user_id] = 3 |
| 231 |
put :update, |
| 232 |
:id => 3, |
| 233 |
:default_columns => '1', |
| 234 |
:fields => ["status_id", "assigned_to_id"], |
| 235 |
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
| 236 |
:values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
|
| 237 |
:query => {"name" => "test_edit_global_private_query", "is_public" => "1"}
|
| 238 |
|
| 239 |
assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3 |
| 240 |
q = Query.find_by_name('test_edit_global_private_query')
|
| 241 |
assert !q.is_public? |
| 242 |
assert q.has_default_columns? |
| 243 |
assert q.valid? |
| 244 |
end |
| 245 |
|
| 246 |
def test_update_global_public_query |
| 247 |
@request.session[:user_id] = 1 |
| 248 |
put :update, |
| 249 |
:id => 4, |
| 250 |
:default_columns => '1', |
| 251 |
:fields => ["status_id", "assigned_to_id"], |
| 252 |
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
| 253 |
:values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
|
| 254 |
:query => {"name" => "test_edit_global_public_query", "is_public" => "1"}
|
| 255 |
|
| 256 |
assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4 |
| 257 |
q = Query.find_by_name('test_edit_global_public_query')
|
| 258 |
assert q.is_public? |
| 259 |
assert q.has_default_columns? |
| 260 |
assert q.valid? |
| 261 |
end |
| 262 |
|
| 263 |
def test_update_with_failure |
| 264 |
@request.session[:user_id] = 1 |
| 265 |
put :update, :id => 4, :query => {:name => ''}
|
| 266 |
assert_response :success |
| 267 |
assert_template 'edit' |
| 268 |
end |
| 269 |
|
| 270 |
def test_destroy |
| 271 |
@request.session[:user_id] = 2 |
| 272 |
delete :destroy, :id => 1 |
| 273 |
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil |
| 274 |
assert_nil Query.find_by_id(1) |
| 275 |
end |
| 276 |
|
| 277 |
def test_backslash_should_be_escaped_in_filters |
| 278 |
@request.session[:user_id] = 2 |
| 279 |
get :new, :subject => 'foo/bar' |
| 280 |
assert_response :success |
| 281 |
assert_template 'new' |
| 282 |
assert_include 'addFilter("subject", "=", ["foo\/bar"]);', response.body
|
| 283 |
end |
| 284 |
end |