2011-09-01 02:58:10 +04:00
|
|
|
# Redmine - project management software
|
2013-01-12 13:29:31 +04:00
|
|
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
2008-03-30 16:29:07 +04:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-09-01 02:58:10 +04:00
|
|
|
#
|
2008-03-30 16:29:07 +04:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2011-09-01 02:58:10 +04:00
|
|
|
#
|
2008-03-30 16:29:07 +04:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
2010-12-13 02:24:34 +03:00
|
|
|
require File.expand_path('../../test_helper', __FILE__)
|
2008-03-30 16:29:07 +04:00
|
|
|
|
2009-09-13 21:14:35 +04:00
|
|
|
class QueriesControllerTest < ActionController::TestCase
|
2012-11-02 02:47:44 +04:00
|
|
|
fixtures :projects, :users, :members, :member_roles, :roles, :trackers, :issue_statuses, :issue_categories, :enumerations, :issues, :custom_fields, :custom_values, :queries, :enabled_modules
|
2011-09-01 02:58:10 +04:00
|
|
|
|
2008-03-30 16:29:07 +04:00
|
|
|
def setup
|
|
|
|
User.current = nil
|
|
|
|
end
|
2011-09-01 02:58:10 +04:00
|
|
|
|
2012-12-12 00:38:26 +04:00
|
|
|
def test_index
|
|
|
|
get :index
|
|
|
|
# HTML response not implemented
|
|
|
|
assert_response 406
|
|
|
|
end
|
|
|
|
|
2011-12-17 21:54:52 +04:00
|
|
|
def test_new_project_query
|
2008-03-30 16:29:07 +04:00
|
|
|
@request.session[:user_id] = 2
|
|
|
|
get :new, :project_id => 1
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'new'
|
|
|
|
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
|
|
:name => 'query[is_public]',
|
2011-09-01 02:58:10 +04:00
|
|
|
:checked => nil }
|
2008-03-30 16:29:07 +04:00
|
|
|
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
|
|
:name => 'query_is_for_all',
|
|
|
|
:checked => nil,
|
|
|
|
:disabled => nil }
|
2012-05-21 20:55:48 +04:00
|
|
|
assert_select 'select[name=?]', 'c[]' do
|
|
|
|
assert_select 'option[value=tracker]'
|
|
|
|
assert_select 'option[value=subject]'
|
|
|
|
end
|
2008-03-30 16:29:07 +04:00
|
|
|
end
|
2011-09-01 02:58:10 +04:00
|
|
|
|
2011-12-17 21:54:52 +04:00
|
|
|
def test_new_global_query
|
2008-03-30 18:20:07 +04:00
|
|
|
@request.session[:user_id] = 2
|
|
|
|
get :new
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'new'
|
|
|
|
assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
2011-09-01 02:58:10 +04:00
|
|
|
:name => 'query[is_public]' }
|
2008-03-30 18:20:07 +04:00
|
|
|
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
|
|
:name => 'query_is_for_all',
|
|
|
|
:checked => 'checked',
|
|
|
|
:disabled => nil }
|
|
|
|
end
|
2011-09-01 02:58:10 +04:00
|
|
|
|
2011-12-17 21:54:52 +04:00
|
|
|
def test_new_on_invalid_project
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
get :new, :project_id => 'invalid'
|
|
|
|
assert_response 404
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_create_project_public_query
|
2008-03-30 16:29:07 +04:00
|
|
|
@request.session[:user_id] = 2
|
2011-10-25 00:19:26 +04:00
|
|
|
post :create,
|
2011-09-01 02:58:10 +04:00
|
|
|
:project_id => 'ecookbook',
|
2008-03-30 16:29:07 +04:00
|
|
|
:default_columns => '1',
|
2011-04-01 19:00:23 +04:00
|
|
|
:f => ["status_id", "assigned_to_id"],
|
|
|
|
:op => {"assigned_to_id" => "=", "status_id" => "o"},
|
|
|
|
:v => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
|
2008-03-30 18:20:07 +04:00
|
|
|
:query => {"name" => "test_new_project_public_query", "is_public" => "1"}
|
2011-09-01 02:58:10 +04:00
|
|
|
|
2008-03-30 16:29:07 +04:00
|
|
|
q = Query.find_by_name('test_new_project_public_query')
|
2009-09-13 21:14:35 +04:00
|
|
|
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q
|
2008-03-30 16:29:07 +04:00
|
|
|
assert q.is_public?
|
|
|
|
assert q.has_default_columns?
|
|
|
|
assert q.valid?
|
|
|
|
end
|
2011-09-01 02:58:10 +04:00
|
|
|
|
2011-12-17 21:54:52 +04:00
|
|
|
def test_create_project_private_query
|
2008-03-30 16:29:07 +04:00
|
|
|
@request.session[:user_id] = 3
|
2011-10-25 00:19:26 +04:00
|
|
|
post :create,
|
2011-09-01 02:58:10 +04:00
|
|
|
:project_id => 'ecookbook',
|
2008-03-30 16:29:07 +04:00
|
|
|
:default_columns => '1',
|
|
|
|
:fields => ["status_id", "assigned_to_id"],
|
|
|
|
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
|
|
|
:values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
|
2008-03-30 18:20:07 +04:00
|
|
|
:query => {"name" => "test_new_project_private_query", "is_public" => "1"}
|
2011-09-01 02:58:10 +04:00
|
|
|
|
2008-03-30 16:29:07 +04:00
|
|
|
q = Query.find_by_name('test_new_project_private_query')
|
2009-09-13 21:14:35 +04:00
|
|
|
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q
|
2008-03-30 16:29:07 +04:00
|
|
|
assert !q.is_public?
|
|
|
|
assert q.has_default_columns?
|
|
|
|
assert q.valid?
|
|
|
|
end
|
2011-09-01 02:58:10 +04:00
|
|
|
|
2011-12-17 21:54:52 +04:00
|
|
|
def test_create_global_private_query_with_custom_columns
|
2008-03-30 18:20:07 +04:00
|
|
|
@request.session[:user_id] = 3
|
2011-10-25 00:19:26 +04:00
|
|
|
post :create,
|
2008-03-30 18:20:07 +04:00
|
|
|
:fields => ["status_id", "assigned_to_id"],
|
|
|
|
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
|
|
|
:values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
|
2011-04-03 18:31:32 +04:00
|
|
|
:query => {"name" => "test_new_global_private_query", "is_public" => "1"},
|
|
|
|
:c => ["", "tracker", "subject", "priority", "category"]
|
2011-09-01 02:58:10 +04:00
|
|
|
|
2008-03-30 18:20:07 +04:00
|
|
|
q = Query.find_by_name('test_new_global_private_query')
|
2009-09-13 21:14:35 +04:00
|
|
|
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q
|
2008-03-30 18:20:07 +04:00
|
|
|
assert !q.is_public?
|
|
|
|
assert !q.has_default_columns?
|
2013-02-23 14:53:21 +04:00
|
|
|
assert_equal [:id, :tracker, :subject, :priority, :category], q.columns.collect {|c| c.name}
|
2008-03-30 18:20:07 +04:00
|
|
|
assert q.valid?
|
|
|
|
end
|
2011-09-01 02:58:10 +04:00
|
|
|
|
2011-12-17 21:54:52 +04:00
|
|
|
def test_create_global_query_with_custom_filters
|
2011-10-25 00:19:26 +04:00
|
|
|
@request.session[:user_id] = 3
|
|
|
|
post :create,
|
|
|
|
:fields => ["assigned_to_id"],
|
|
|
|
:operators => {"assigned_to_id" => "="},
|
|
|
|
:values => { "assigned_to_id" => ["me"]},
|
|
|
|
:query => {"name" => "test_new_global_query"}
|
|
|
|
|
|
|
|
q = Query.find_by_name('test_new_global_query')
|
|
|
|
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q
|
|
|
|
assert !q.has_filter?(:status_id)
|
|
|
|
assert_equal ['assigned_to_id'], q.filters.keys
|
|
|
|
assert q.valid?
|
|
|
|
end
|
|
|
|
|
2011-12-17 21:54:52 +04:00
|
|
|
def test_create_with_sort
|
2009-03-12 21:06:54 +03:00
|
|
|
@request.session[:user_id] = 1
|
2011-10-25 00:19:26 +04:00
|
|
|
post :create,
|
2009-03-12 21:06:54 +03:00
|
|
|
:default_columns => '1',
|
|
|
|
:operators => {"status_id" => "o"},
|
|
|
|
:values => {"status_id" => ["1"]},
|
|
|
|
:query => {:name => "test_new_with_sort",
|
2011-09-01 02:58:10 +04:00
|
|
|
:is_public => "1",
|
2009-03-12 21:06:54 +03:00
|
|
|
:sort_criteria => {"0" => ["due_date", "desc"], "1" => ["tracker", ""]}}
|
2011-09-01 02:58:10 +04:00
|
|
|
|
2009-03-12 21:06:54 +03:00
|
|
|
query = Query.find_by_name("test_new_with_sort")
|
|
|
|
assert_not_nil query
|
|
|
|
assert_equal [['due_date', 'desc'], ['tracker', 'asc']], query.sort_criteria
|
|
|
|
end
|
2011-09-01 02:58:10 +04:00
|
|
|
|
2011-12-17 21:54:52 +04:00
|
|
|
def test_create_with_failure
|
|
|
|
@request.session[:user_id] = 2
|
2012-04-25 21:17:49 +04:00
|
|
|
assert_no_difference '::Query.count' do
|
2011-12-17 21:54:52 +04:00
|
|
|
post :create, :project_id => 'ecookbook', :query => {:name => ''}
|
|
|
|
end
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'new'
|
2012-05-25 20:50:25 +04:00
|
|
|
assert_select 'input[name=?]', 'query[name]'
|
2011-12-17 21:54:52 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_edit_global_public_query
|
2008-03-30 16:29:07 +04:00
|
|
|
@request.session[:user_id] = 1
|
|
|
|
get :edit, :id => 4
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'edit'
|
|
|
|
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
|
|
:name => 'query[is_public]',
|
2011-09-01 02:58:10 +04:00
|
|
|
:checked => 'checked' }
|
2008-03-30 16:29:07 +04:00
|
|
|
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
|
|
:name => 'query_is_for_all',
|
|
|
|
:checked => 'checked',
|
|
|
|
:disabled => 'disabled' }
|
|
|
|
end
|
|
|
|
|
2011-12-17 21:54:52 +04:00
|
|
|
def test_edit_global_private_query
|
2008-03-30 16:29:07 +04:00
|
|
|
@request.session[:user_id] = 3
|
|
|
|
get :edit, :id => 3
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'edit'
|
|
|
|
assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
2011-09-01 02:58:10 +04:00
|
|
|
:name => 'query[is_public]' }
|
2008-03-30 16:29:07 +04:00
|
|
|
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
|
|
:name => 'query_is_for_all',
|
|
|
|
:checked => 'checked',
|
|
|
|
:disabled => 'disabled' }
|
|
|
|
end
|
2011-09-01 02:58:10 +04:00
|
|
|
|
2011-12-17 21:54:52 +04:00
|
|
|
def test_edit_project_private_query
|
2008-03-30 16:29:07 +04:00
|
|
|
@request.session[:user_id] = 3
|
|
|
|
get :edit, :id => 2
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'edit'
|
|
|
|
assert_no_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
2011-09-01 02:58:10 +04:00
|
|
|
:name => 'query[is_public]' }
|
2008-03-30 16:29:07 +04:00
|
|
|
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
|
|
:name => 'query_is_for_all',
|
|
|
|
:checked => nil,
|
|
|
|
:disabled => nil }
|
|
|
|
end
|
2011-09-01 02:58:10 +04:00
|
|
|
|
2011-12-17 21:54:52 +04:00
|
|
|
def test_edit_project_public_query
|
2008-03-30 16:29:07 +04:00
|
|
|
@request.session[:user_id] = 2
|
|
|
|
get :edit, :id => 1
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'edit'
|
|
|
|
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
|
|
:name => 'query[is_public]',
|
|
|
|
:checked => 'checked'
|
2011-09-01 02:58:10 +04:00
|
|
|
}
|
2008-03-30 16:29:07 +04:00
|
|
|
assert_tag :tag => 'input', :attributes => { :type => 'checkbox',
|
|
|
|
:name => 'query_is_for_all',
|
|
|
|
:checked => nil,
|
|
|
|
:disabled => 'disabled' }
|
|
|
|
end
|
2011-09-01 02:58:10 +04:00
|
|
|
|
2011-12-17 21:54:52 +04:00
|
|
|
def test_edit_sort_criteria
|
2009-03-12 21:06:54 +03:00
|
|
|
@request.session[:user_id] = 1
|
|
|
|
get :edit, :id => 5
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'edit'
|
|
|
|
assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' },
|
|
|
|
:child => { :tag => 'option', :attributes => { :value => 'priority',
|
|
|
|
:selected => 'selected' } }
|
|
|
|
assert_tag :tag => 'select', :attributes => { :name => 'query[sort_criteria][0][]' },
|
|
|
|
:child => { :tag => 'option', :attributes => { :value => 'desc',
|
|
|
|
:selected => 'selected' } }
|
|
|
|
end
|
2011-09-01 02:58:10 +04:00
|
|
|
|
2011-12-17 21:54:52 +04:00
|
|
|
def test_edit_invalid_query
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
get :edit, :id => 99
|
|
|
|
assert_response 404
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_udpate_global_private_query
|
|
|
|
@request.session[:user_id] = 3
|
|
|
|
put :update,
|
|
|
|
:id => 3,
|
|
|
|
:default_columns => '1',
|
|
|
|
:fields => ["status_id", "assigned_to_id"],
|
|
|
|
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
|
|
|
:values => { "assigned_to_id" => ["me"], "status_id" => ["1"]},
|
|
|
|
:query => {"name" => "test_edit_global_private_query", "is_public" => "1"}
|
|
|
|
|
|
|
|
assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 3
|
|
|
|
q = Query.find_by_name('test_edit_global_private_query')
|
|
|
|
assert !q.is_public?
|
|
|
|
assert q.has_default_columns?
|
|
|
|
assert q.valid?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_update_global_public_query
|
|
|
|
@request.session[:user_id] = 1
|
|
|
|
put :update,
|
|
|
|
:id => 4,
|
|
|
|
:default_columns => '1',
|
|
|
|
:fields => ["status_id", "assigned_to_id"],
|
|
|
|
:operators => {"assigned_to_id" => "=", "status_id" => "o"},
|
|
|
|
:values => { "assigned_to_id" => ["1"], "status_id" => ["1"]},
|
|
|
|
:query => {"name" => "test_edit_global_public_query", "is_public" => "1"}
|
|
|
|
|
|
|
|
assert_redirected_to :controller => 'issues', :action => 'index', :query_id => 4
|
|
|
|
q = Query.find_by_name('test_edit_global_public_query')
|
|
|
|
assert q.is_public?
|
|
|
|
assert q.has_default_columns?
|
|
|
|
assert q.valid?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_update_with_failure
|
|
|
|
@request.session[:user_id] = 1
|
|
|
|
put :update, :id => 4, :query => {:name => ''}
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'edit'
|
|
|
|
end
|
|
|
|
|
2008-03-30 16:29:07 +04:00
|
|
|
def test_destroy
|
|
|
|
@request.session[:user_id] = 2
|
2011-10-25 00:19:26 +04:00
|
|
|
delete :destroy, :id => 1
|
2008-03-30 16:29:07 +04:00
|
|
|
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :set_filter => 1, :query_id => nil
|
|
|
|
assert_nil Query.find_by_id(1)
|
|
|
|
end
|
2012-09-25 22:23:11 +04:00
|
|
|
|
|
|
|
def test_backslash_should_be_escaped_in_filters
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
get :new, :subject => 'foo/bar'
|
|
|
|
assert_response :success
|
|
|
|
assert_template 'new'
|
|
|
|
assert_include 'addFilter("subject", "=", ["foo\/bar"]);', response.body
|
|
|
|
end
|
2008-03-30 16:29:07 +04:00
|
|
|
end
|