To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / test / functional / queries_controller_test.rb @ 441:cbce1fd3b1b7
History | View | Annotate | Download (10.3 KB)
| 1 | 0:513646585e45 | Chris | # redMine - project management software
|
|---|---|---|---|
| 2 | # Copyright (C) 2006-2008 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 | 119:8661b858af72 | Chris | require File.expand_path('../../test_helper', __FILE__) |
| 19 | 0:513646585e45 | Chris | 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 :new,
|
||
| 64 | :project_id => 'ecookbook', |
||
| 65 | :confirm => '1', |
||
| 66 | :default_columns => '1', |
||
| 67 | 441:cbce1fd3b1b7 | Chris | :f => ["status_id", "assigned_to_id"], |
| 68 | :op => {"assigned_to_id" => "=", "status_id" => "o"}, |
||
| 69 | :v => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
||
| 70 | 0:513646585e45 | Chris | :query => {"name" => "test_new_project_public_query", "is_public" => "1"} |
| 71 | |||
| 72 | q = Query.find_by_name('test_new_project_public_query') |
||
| 73 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
||
| 74 | assert q.is_public? |
||
| 75 | assert q.has_default_columns? |
||
| 76 | assert q.valid? |
||
| 77 | end
|
||
| 78 | |||
| 79 | def test_new_project_private_query |
||
| 80 | @request.session[:user_id] = 3 |
||
| 81 | post :new,
|
||
| 82 | :project_id => 'ecookbook', |
||
| 83 | :confirm => '1', |
||
| 84 | :default_columns => '1', |
||
| 85 | :fields => ["status_id", "assigned_to_id"], |
||
| 86 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
||
| 87 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
||
| 88 | :query => {"name" => "test_new_project_private_query", "is_public" => "1"} |
||
| 89 | |||
| 90 | q = Query.find_by_name('test_new_project_private_query') |
||
| 91 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q |
||
| 92 | assert !q.is_public? |
||
| 93 | assert q.has_default_columns? |
||
| 94 | assert q.valid? |
||
| 95 | end
|
||
| 96 | |||
| 97 | def test_new_global_private_query_with_custom_columns |
||
| 98 | @request.session[:user_id] = 3 |
||
| 99 | post :new,
|
||
| 100 | :confirm => '1', |
||
| 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 | 441:cbce1fd3b1b7 | Chris | :query => {"name" => "test_new_global_private_query", "is_public" => "1"}, |
| 105 | :c => ["", "tracker", "subject", "priority", "category"] |
||
| 106 | 0:513646585e45 | Chris | |
| 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_new_with_sort |
||
| 116 | @request.session[:user_id] = 1 |
||
| 117 | post :new,
|
||
| 118 | :confirm => '1', |
||
| 119 | :default_columns => '1', |
||
| 120 | :operators => {"status_id" => "o"}, |
||
| 121 | :values => {"status_id" => ["1"]}, |
||
| 122 | :query => {:name => "test_new_with_sort", |
||
| 123 | :is_public => "1", |
||
| 124 | :sort_criteria => {"0" => ["due_date", "desc"], "1" => ["tracker", ""]}} |
||
| 125 | |||
| 126 | query = Query.find_by_name("test_new_with_sort") |
||
| 127 | assert_not_nil query |
||
| 128 | assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria |
||
| 129 | end
|
||
| 130 | |||
| 131 | def test_get_edit_global_public_query |
||
| 132 | @request.session[:user_id] = 1 |
||
| 133 | get :edit, :id => 4 |
||
| 134 | assert_response :success
|
||
| 135 | assert_template 'edit'
|
||
| 136 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
||
| 137 | :name => 'query[is_public]', |
||
| 138 | :checked => 'checked' } |
||
| 139 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
||
| 140 | :name => 'query_is_for_all', |
||
| 141 | :checked => 'checked', |
||
| 142 | :disabled => 'disabled' } |
||
| 143 | end
|
||
| 144 | |||
| 145 | def test_edit_global_public_query |
||
| 146 | @request.session[:user_id] = 1 |
||
| 147 | post :edit,
|
||
| 148 | :id => 4, |
||
| 149 | :confirm => '1', |
||
| 150 | :default_columns => '1', |
||
| 151 | :fields => ["status_id", "assigned_to_id"], |
||
| 152 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
||
| 153 | :values => { "assigned_to_id" => ["1"], "status_id" => ["1"]}, |
||
| 154 | :query => {"name" => "test_edit_global_public_query", "is_public" => "1"} |
||
| 155 | |||
| 156 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4 |
||
| 157 | q = Query.find_by_name('test_edit_global_public_query') |
||
| 158 | assert q.is_public? |
||
| 159 | assert q.has_default_columns? |
||
| 160 | assert q.valid? |
||
| 161 | end
|
||
| 162 | |||
| 163 | def test_get_edit_global_private_query |
||
| 164 | @request.session[:user_id] = 3 |
||
| 165 | get :edit, :id => 3 |
||
| 166 | assert_response :success
|
||
| 167 | assert_template 'edit'
|
||
| 168 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
||
| 169 | :name => 'query[is_public]' } |
||
| 170 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
||
| 171 | :name => 'query_is_for_all', |
||
| 172 | :checked => 'checked', |
||
| 173 | :disabled => 'disabled' } |
||
| 174 | end
|
||
| 175 | |||
| 176 | def test_edit_global_private_query |
||
| 177 | @request.session[:user_id] = 3 |
||
| 178 | post :edit,
|
||
| 179 | :id => 3, |
||
| 180 | :confirm => '1', |
||
| 181 | :default_columns => '1', |
||
| 182 | :fields => ["status_id", "assigned_to_id"], |
||
| 183 | :operators => {"assigned_to_id" => "=", "status_id" => "o"}, |
||
| 184 | :values => { "assigned_to_id" => ["me"], "status_id" => ["1"]}, |
||
| 185 | :query => {"name" => "test_edit_global_private_query", "is_public" => "1"} |
||
| 186 | |||
| 187 | assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3 |
||
| 188 | q = Query.find_by_name('test_edit_global_private_query') |
||
| 189 | assert !q.is_public? |
||
| 190 | assert q.has_default_columns? |
||
| 191 | assert q.valid? |
||
| 192 | end
|
||
| 193 | |||
| 194 | def test_get_edit_project_private_query |
||
| 195 | @request.session[:user_id] = 3 |
||
| 196 | get :edit, :id => 2 |
||
| 197 | assert_response :success
|
||
| 198 | assert_template 'edit'
|
||
| 199 | assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox', |
||
| 200 | :name => 'query[is_public]' } |
||
| 201 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
||
| 202 | :name => 'query_is_for_all', |
||
| 203 | :checked => nil, |
||
| 204 | :disabled => nil } |
||
| 205 | end
|
||
| 206 | |||
| 207 | def test_get_edit_project_public_query |
||
| 208 | @request.session[:user_id] = 2 |
||
| 209 | get :edit, :id => 1 |
||
| 210 | assert_response :success
|
||
| 211 | assert_template 'edit'
|
||
| 212 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
||
| 213 | :name => 'query[is_public]', |
||
| 214 | :checked => 'checked' |
||
| 215 | } |
||
| 216 | assert_tag :tag => 'input', :attributes => { :type => 'checkbox', |
||
| 217 | :name => 'query_is_for_all', |
||
| 218 | :checked => nil, |
||
| 219 | :disabled => 'disabled' } |
||
| 220 | end
|
||
| 221 | |||
| 222 | def test_get_edit_sort_criteria |
||
| 223 | @request.session[:user_id] = 1 |
||
| 224 | get :edit, :id => 5 |
||
| 225 | assert_response :success
|
||
| 226 | assert_template 'edit'
|
||
| 227 | assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' }, |
||
| 228 | :child => { :tag => 'option', :attributes => { :value => 'priority', |
||
| 229 | :selected => 'selected' } } |
||
| 230 | assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' }, |
||
| 231 | :child => { :tag => 'option', :attributes => { :value => 'desc', |
||
| 232 | :selected => 'selected' } } |
||
| 233 | end
|
||
| 234 | |||
| 235 | def test_destroy |
||
| 236 | @request.session[:user_id] = 2 |
||
| 237 | post :destroy, :id => 1 |
||
| 238 | assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil |
||
| 239 | assert_nil Query.find_by_id(1) |
||
| 240 | end
|
||
| 241 | end |