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 / 64 / 64036c3be2c819ccb0429f69ed2813c1f8f00a12.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (10.6 KB)
| 1 |
# Redmine - project management software |
|---|---|
| 2 |
# Copyright (C) 2006-2011 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 |
require 'queries_controller' |
| 20 |
|
| 21 |
# Re-raise errors caught by the controller. |
| 22 |
class QueriesController; def rescue_action(e) raise e end; end |
| 23 |
|
| 24 |
class QueriesControllerTest < ActionController::TestCase |
| 25 |
fixtures :projects, :users, :members, :member_roles, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries |
| 26 |
|
| 27 |
def setup |
| 28 |
@controller = QueriesController.new |
| 29 |
@request = ActionController::TestRequest.new |
| 30 |
@response = ActionController::TestResponse.new |
| 31 |
User.current = nil |
| 32 |
end |
| 33 |
|
| 34 |
def test_get_new_project_query |
| 35 |
@request.session[:user_id] = 2 |
| 36 |
get :new, :project_id => 1 |
| 37 |
assert_response :success |
| 38 |
assert_template 'new' |
| 39 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 40 |
:name => 'query[is_public]', |
| 41 |
:checked => nil } |
| 42 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 43 |
:name => 'query_is_for_all', |
| 44 |
:checked => nil, |
| 45 |
:disabled => nil } |
| 46 |
end |
| 47 |
|
| 48 |
def test_get_new_global_query |
| 49 |
@request.session[:user_id] = 2 |
| 50 |
get :new |
| 51 |
assert_response :success |
| 52 |
assert_template 'new' |
| 53 |
assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 54 |
:name => 'query[is_public]' } |
| 55 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 56 |
:name => 'query_is_for_all', |
| 57 |
:checked => 'checked', |
| 58 |
:disabled => nil } |
| 59 |
end |
| 60 |
|
| 61 |
def test_new_project_public_query |
| 62 |
@request.session[:user_id] = 2 |
| 63 |
post :create, |
| 64 |
:project_id => 'ecookbook', |
| 65 |
:default_columns => '1', |
| 66 |
:f => ["status_id", "assigned_to_id"], |
| 67 |
:op => {"assigned_to_id" => "=", "status_id" => "o"},
|
| 68 |
:v => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
|
| 69 |
:query => {"name" => "test_new_project_public_query", "is_public" => "1"}
|
| 70 |
|
| 71 |
q = Query.find_by_name('test_new_project_public_query')
|
| 72 |
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
| 73 |
assert q.is_public? |
| 74 |
assert q.has_default_columns? |
| 75 |
assert q.valid? |
| 76 |
end |
| 77 |
|
| 78 |
def test_new_project_private_query |
| 79 |
@request.session[:user_id] = 3 |
| 80 |
post :create, |
| 81 |
:project_id => 'ecookbook', |
| 82 |
:default_columns => '1', |
| 83 |
:fields => ["status_id", "assigned_to_id"], |
| 84 |
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
| 85 |
:values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
|
| 86 |
:query => {"name" => "test_new_project_private_query", "is_public" => "1"}
|
| 87 |
|
| 88 |
q = Query.find_by_name('test_new_project_private_query')
|
| 89 |
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
| 90 |
assert !q.is_public? |
| 91 |
assert q.has_default_columns? |
| 92 |
assert q.valid? |
| 93 |
end |
| 94 |
|
| 95 |
def test_new_global_private_query_with_custom_columns |
| 96 |
@request.session[:user_id] = 3 |
| 97 |
post :create, |
| 98 |
:fields => ["status_id", "assigned_to_id"], |
| 99 |
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
| 100 |
:values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
|
| 101 |
:query => {"name" => "test_new_global_private_query", "is_public" => "1"},
|
| 102 |
:c => ["", "tracker", "subject", "priority", "category"] |
| 103 |
|
| 104 |
q = Query.find_by_name('test_new_global_private_query')
|
| 105 |
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q |
| 106 |
assert !q.is_public? |
| 107 |
assert !q.has_default_columns? |
| 108 |
assert_equal [:tracker, :subject, :priority, :category], q.columns.collect {|c| c.name}
|
| 109 |
assert q.valid? |
| 110 |
end |
| 111 |
|
| 112 |
def test_new_global_query_with_custom_filters |
| 113 |
@request.session[:user_id] = 3 |
| 114 |
post :create, |
| 115 |
:fields => ["assigned_to_id"], |
| 116 |
:operators => {"assigned_to_id" => "="},
|
| 117 |
:values => { "assigned_to_id" => ["me"]},
|
| 118 |
:query => {"name" => "test_new_global_query"}
|
| 119 |
|
| 120 |
q = Query.find_by_name('test_new_global_query')
|
| 121 |
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q |
| 122 |
assert !q.has_filter?(:status_id) |
| 123 |
assert_equal ['assigned_to_id'], q.filters.keys |
| 124 |
assert q.valid? |
| 125 |
end |
| 126 |
|
| 127 |
def test_new_with_sort |
| 128 |
@request.session[:user_id] = 1 |
| 129 |
post :create, |
| 130 |
:default_columns => '1', |
| 131 |
:operators => {"status_id" => "o"},
|
| 132 |
:values => {"status_id" => ["1"]},
|
| 133 |
:query => {:name => "test_new_with_sort",
|
| 134 |
:is_public => "1", |
| 135 |
:sort_criteria => {"0" => ["due_date", "desc"], "1" => ["tracker", ""]}}
|
| 136 |
|
| 137 |
query = Query.find_by_name("test_new_with_sort")
|
| 138 |
assert_not_nil query |
| 139 |
assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria |
| 140 |
end |
| 141 |
|
| 142 |
def test_get_edit_global_public_query |
| 143 |
@request.session[:user_id] = 1 |
| 144 |
get :edit, :id => 4 |
| 145 |
assert_response :success |
| 146 |
assert_template 'edit' |
| 147 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 148 |
:name => 'query[is_public]', |
| 149 |
:checked => 'checked' } |
| 150 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 151 |
:name => 'query_is_for_all', |
| 152 |
:checked => 'checked', |
| 153 |
:disabled => 'disabled' } |
| 154 |
end |
| 155 |
|
| 156 |
def test_edit_global_public_query |
| 157 |
@request.session[:user_id] = 1 |
| 158 |
put :update, |
| 159 |
:id => 4, |
| 160 |
:default_columns => '1', |
| 161 |
:fields => ["status_id", "assigned_to_id"], |
| 162 |
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
| 163 |
:values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
|
| 164 |
:query => {"name" => "test_edit_global_public_query", "is_public" => "1"}
|
| 165 |
|
| 166 |
assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4 |
| 167 |
q = Query.find_by_name('test_edit_global_public_query')
|
| 168 |
assert q.is_public? |
| 169 |
assert q.has_default_columns? |
| 170 |
assert q.valid? |
| 171 |
end |
| 172 |
|
| 173 |
def test_get_edit_global_private_query |
| 174 |
@request.session[:user_id] = 3 |
| 175 |
get :edit, :id => 3 |
| 176 |
assert_response :success |
| 177 |
assert_template 'edit' |
| 178 |
assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 179 |
:name => 'query[is_public]' } |
| 180 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 181 |
:name => 'query_is_for_all', |
| 182 |
:checked => 'checked', |
| 183 |
:disabled => 'disabled' } |
| 184 |
end |
| 185 |
|
| 186 |
def test_edit_global_private_query |
| 187 |
@request.session[:user_id] = 3 |
| 188 |
put :update, |
| 189 |
:id => 3, |
| 190 |
:default_columns => '1', |
| 191 |
:fields => ["status_id", "assigned_to_id"], |
| 192 |
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
| 193 |
:values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
|
| 194 |
:query => {"name" => "test_edit_global_private_query", "is_public" => "1"}
|
| 195 |
|
| 196 |
assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3 |
| 197 |
q = Query.find_by_name('test_edit_global_private_query')
|
| 198 |
assert !q.is_public? |
| 199 |
assert q.has_default_columns? |
| 200 |
assert q.valid? |
| 201 |
end |
| 202 |
|
| 203 |
def test_get_edit_project_private_query |
| 204 |
@request.session[:user_id] = 3 |
| 205 |
get :edit, :id => 2 |
| 206 |
assert_response :success |
| 207 |
assert_template 'edit' |
| 208 |
assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 209 |
:name => 'query[is_public]' } |
| 210 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 211 |
:name => 'query_is_for_all', |
| 212 |
:checked => nil, |
| 213 |
:disabled => nil } |
| 214 |
end |
| 215 |
|
| 216 |
def test_get_edit_project_public_query |
| 217 |
@request.session[:user_id] = 2 |
| 218 |
get :edit, :id => 1 |
| 219 |
assert_response :success |
| 220 |
assert_template 'edit' |
| 221 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 222 |
:name => 'query[is_public]', |
| 223 |
:checked => 'checked' |
| 224 |
} |
| 225 |
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
| 226 |
:name => 'query_is_for_all', |
| 227 |
:checked => nil, |
| 228 |
:disabled => 'disabled' } |
| 229 |
end |
| 230 |
|
| 231 |
def test_get_edit_sort_criteria |
| 232 |
@request.session[:user_id] = 1 |
| 233 |
get :edit, :id => 5 |
| 234 |
assert_response :success |
| 235 |
assert_template 'edit' |
| 236 |
assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' },
|
| 237 |
:child => { :tag => 'option', :attributes => { :value => 'priority',
|
| 238 |
:selected => 'selected' } } |
| 239 |
assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' },
|
| 240 |
:child => { :tag => 'option', :attributes => { :value => 'desc',
|
| 241 |
:selected => 'selected' } } |
| 242 |
end |
| 243 |
|
| 244 |
def test_destroy |
| 245 |
@request.session[:user_id] = 2 |
| 246 |
delete :destroy, :id => 1 |
| 247 |
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil |
| 248 |
assert_nil Query.find_by_id(1) |
| 249 |
end |
| 250 |
end |