2019-03-16 15:03:47 +00:00
|
|
|
# frozen_string_literal: true
|
2019-03-15 01:32:57 +00:00
|
|
|
|
2011-08-31 22:58:10 +00:00
|
|
|
# Redmine - project management software
|
2024-02-26 22:55:54 +00:00
|
|
|
# Copyright (C) 2006- Jean-Philippe Lang
|
2008-03-30 12:29:07 +00: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-08-31 22:58:10 +00:00
|
|
|
#
|
2008-03-30 12:29:07 +00: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-08-31 22:58:10 +00:00
|
|
|
#
|
2008-03-30 12:29:07 +00: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.
|
|
|
|
|
|
2023-01-01 07:13:39 +00:00
|
|
|
require_relative '../test_helper'
|
2008-03-30 12:29:07 +00:00
|
|
|
|
2016-07-14 09:35:49 +00:00
|
|
|
class QueriesControllerTest < Redmine::ControllerTest
|
2017-01-09 19:59:54 +00:00
|
|
|
fixtures :projects, :enabled_modules,
|
|
|
|
|
:users, :email_addresses,
|
|
|
|
|
:members, :member_roles, :roles,
|
|
|
|
|
:trackers, :issue_statuses, :issue_categories, :enumerations, :versions,
|
|
|
|
|
:issues, :custom_fields, :custom_values,
|
|
|
|
|
:queries
|
2011-08-31 22:58:10 +00:00
|
|
|
|
2008-03-30 12:29:07 +00:00
|
|
|
def setup
|
|
|
|
|
User.current = nil
|
|
|
|
|
end
|
2011-08-31 22:58:10 +00:00
|
|
|
|
2012-12-11 20:38:26 +00:00
|
|
|
def test_index
|
|
|
|
|
get :index
|
|
|
|
|
# HTML response not implemented
|
2024-05-18 05:56:55 +00:00
|
|
|
assert_response :not_acceptable
|
2012-12-11 20:38:26 +00:00
|
|
|
end
|
|
|
|
|
|
2011-12-17 17:54:52 +00:00
|
|
|
def test_new_project_query
|
2008-03-30 12:29:07 +00:00
|
|
|
@request.session[:user_id] = 2
|
2020-10-24 14:40:03 +00:00
|
|
|
get(:new, :params => {:project_id => 1})
|
2008-03-30 12:29:07 +00:00
|
|
|
assert_response :success
|
2016-07-19 20:06:01 +00:00
|
|
|
|
2014-11-20 19:38:40 +00:00
|
|
|
assert_select 'input[name=?][value="0"][checked=checked]', 'query[visibility]'
|
2014-11-22 09:38:21 +00:00
|
|
|
assert_select 'input[name=query_is_for_all][type=checkbox]:not([checked]):not([disabled])'
|
2012-05-21 16:55:48 +00:00
|
|
|
assert_select 'select[name=?]', 'c[]' do
|
|
|
|
|
assert_select 'option[value=tracker]'
|
|
|
|
|
assert_select 'option[value=subject]'
|
|
|
|
|
end
|
2008-03-30 12:29:07 +00:00
|
|
|
end
|
2011-08-31 22:58:10 +00:00
|
|
|
|
2011-12-17 17:54:52 +00:00
|
|
|
def test_new_global_query
|
2008-03-30 14:20:07 +00:00
|
|
|
@request.session[:user_id] = 2
|
|
|
|
|
get :new
|
|
|
|
|
assert_response :success
|
2016-07-19 20:06:01 +00:00
|
|
|
|
2013-07-11 17:45:10 +00:00
|
|
|
assert_select 'input[name=?]', 'query[visibility]', 0
|
2014-11-22 09:38:21 +00:00
|
|
|
assert_select 'input[name=query_is_for_all][type=checkbox][checked]:not([disabled])'
|
2008-03-30 14:20:07 +00:00
|
|
|
end
|
2011-08-31 22:58:10 +00:00
|
|
|
|
2011-12-17 17:54:52 +00:00
|
|
|
def test_new_on_invalid_project
|
|
|
|
|
@request.session[:user_id] = 2
|
2020-10-24 14:40:03 +00:00
|
|
|
get(:new, :params => {:project_id => 'invalid'})
|
2024-05-18 05:56:55 +00:00
|
|
|
assert_response :not_found
|
2011-12-17 17:54:52 +00:00
|
|
|
end
|
|
|
|
|
|
2019-10-19 11:36:13 +00:00
|
|
|
def test_new_should_not_render_show_inline_columns_option_for_query_without_available_inline_columns
|
|
|
|
|
@request.session[:user_id] = 1
|
2020-10-24 14:40:03 +00:00
|
|
|
get(:new, :params => {:type => 'ProjectQuery'})
|
2019-10-19 11:36:13 +00:00
|
|
|
assert_response :success
|
|
|
|
|
assert_select 'p[class=?]', 'block_columns', 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_new_should_not_render_show_totals_option_for_query_without_totable_columns
|
|
|
|
|
@request.session[:user_id] = 1
|
2020-10-24 14:40:03 +00:00
|
|
|
get(:new, :params => {:type => 'ProjectQuery'})
|
2019-10-19 11:36:13 +00:00
|
|
|
assert_response :success
|
|
|
|
|
assert_select 'p[class=?]', 'totables_columns', 0
|
|
|
|
|
end
|
|
|
|
|
|
2016-07-12 17:40:19 +00:00
|
|
|
def test_new_time_entry_query
|
|
|
|
|
@request.session[:user_id] = 2
|
2020-10-24 14:40:03 +00:00
|
|
|
get(:new, :params => {:project_id => 1, :type => 'TimeEntryQuery'})
|
2016-07-12 17:40:19 +00:00
|
|
|
assert_response :success
|
|
|
|
|
assert_select 'input[name=type][value=?]', 'TimeEntryQuery'
|
2019-10-19 11:36:13 +00:00
|
|
|
assert_select 'p[class=?]', 'totable_columns', 1
|
|
|
|
|
assert_select 'p[class=?]', 'block_columns', 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_new_project_query_for_projects
|
|
|
|
|
@request.session[:user_id] = 1
|
2020-10-24 14:40:03 +00:00
|
|
|
get(:new, :params => {:type => 'ProjectQuery'})
|
2019-10-19 11:36:13 +00:00
|
|
|
assert_response :success
|
|
|
|
|
assert_select 'input[name=type][value=?]', 'ProjectQuery'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_new_project_query_should_not_render_roles_visibility_options
|
|
|
|
|
@request.session[:user_id] = 1
|
2020-10-24 14:40:03 +00:00
|
|
|
get(:new, :params => {:type => 'ProjectQuery'})
|
2019-10-19 11:36:13 +00:00
|
|
|
assert_response :success
|
|
|
|
|
assert_select 'input[id=?]', 'query_visibility_0', 1
|
|
|
|
|
assert_select 'input[id=?]', 'query_visibility_2', 1
|
|
|
|
|
assert_select 'input[id=?]', 'query_visibility_1', 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_new_project_query_should_not_render_for_all_projects_option
|
|
|
|
|
@request.session[:user_id] = 1
|
2020-10-24 14:40:03 +00:00
|
|
|
get(:new, :params => {:type => 'ProjectQuery'})
|
2019-10-19 11:36:13 +00:00
|
|
|
assert_response :success
|
|
|
|
|
assert_select 'input[name=?]', 'for_all_projects', 0
|
2016-07-12 17:40:19 +00:00
|
|
|
end
|
|
|
|
|
|
2018-06-17 08:29:05 +00:00
|
|
|
def test_new_time_entry_query_should_select_spent_time_from_main_menu
|
|
|
|
|
@request.session[:user_id] = 2
|
2020-10-24 14:40:03 +00:00
|
|
|
get(
|
|
|
|
|
:new,
|
|
|
|
|
:params => {
|
2018-06-17 08:29:05 +00:00
|
|
|
:project_id => 1,
|
|
|
|
|
:type => 'TimeEntryQuery'
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2018-06-17 08:29:05 +00:00
|
|
|
assert_response :success
|
|
|
|
|
assert_select '#main-menu a.time-entries.selected'
|
|
|
|
|
end
|
|
|
|
|
|
2017-06-26 19:30:36 +00:00
|
|
|
def test_new_time_entry_query_with_issue_tracking_module_disabled_should_be_allowed
|
|
|
|
|
Project.find(1).disable_module! :issue_tracking
|
|
|
|
|
@request.session[:user_id] = 2
|
2020-10-24 14:40:03 +00:00
|
|
|
get(
|
|
|
|
|
:new,
|
|
|
|
|
:params => {
|
2017-06-26 19:30:36 +00:00
|
|
|
:project_id => 1,
|
|
|
|
|
:type => 'TimeEntryQuery'
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2017-06-26 19:30:36 +00:00
|
|
|
assert_response :success
|
|
|
|
|
end
|
|
|
|
|
|
2019-11-30 00:58:45 +00:00
|
|
|
def test_new_with_gantt_params
|
|
|
|
|
@request.session[:user_id] = 2
|
2020-11-12 12:32:06 +00:00
|
|
|
get :new, :params => {:gantt => 1}
|
2019-11-30 00:58:45 +00:00
|
|
|
assert_response :success
|
|
|
|
|
|
|
|
|
|
assert_select 'input[type="hidden"]#gantt', 1
|
|
|
|
|
assert_select 'fieldset#options'
|
|
|
|
|
assert_select 'fieldset#filters'
|
2020-11-12 12:32:06 +00:00
|
|
|
assert_select 'fieldset legend', {:text => 'Sort', :count => 0}
|
2019-11-30 00:58:45 +00:00
|
|
|
assert_select 'fieldset#columns'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_new_with_calendar_params
|
|
|
|
|
@request.session[:user_id] = 2
|
2020-11-12 12:32:06 +00:00
|
|
|
get :new, :params => {:calendar => 1}
|
2019-11-30 00:58:45 +00:00
|
|
|
assert_response :success
|
|
|
|
|
|
|
|
|
|
assert_select 'input[type="hidden"]#calendar', 1
|
|
|
|
|
assert_select 'fieldset#options', :count => 0
|
|
|
|
|
assert_select 'fieldset#filters'
|
2020-11-12 12:32:06 +00:00
|
|
|
assert_select 'fieldset legend', {:text => 'Sort', :count => 0}
|
2019-11-30 00:58:45 +00:00
|
|
|
assert_select 'fieldset#columns', :count => 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_new_without_gantt_and_calendar_params
|
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
|
get :new
|
|
|
|
|
assert_response :success
|
|
|
|
|
|
|
|
|
|
assert_select 'fieldset#options'
|
|
|
|
|
assert_select 'fieldset#filters'
|
2020-11-12 12:32:06 +00:00
|
|
|
assert_select 'fieldset legend', {:text => 'Sort'}
|
2019-11-30 00:58:45 +00:00
|
|
|
assert_select 'fieldset#columns'
|
|
|
|
|
end
|
|
|
|
|
|
2011-12-17 17:54:52 +00:00
|
|
|
def test_create_project_public_query
|
2008-03-30 12:29:07 +00:00
|
|
|
@request.session[:user_id] = 2
|
2020-10-24 14:40:03 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:project_id => 'ecookbook',
|
|
|
|
|
:default_columns => '1',
|
|
|
|
|
:f => ["status_id", "assigned_to_id"],
|
|
|
|
|
:op => {
|
|
|
|
|
"assigned_to_id" => "=", "status_id" => "o"
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:v => {
|
|
|
|
|
"assigned_to_id" => ["1"], "status_id" => ["1"]
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:query => {
|
|
|
|
|
"name" => "test_new_project_public_query", "visibility" => "2"
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2008-03-30 12:29:07 +00:00
|
|
|
q = Query.find_by_name('test_new_project_public_query')
|
2009-09-13 17:14:35 +00:00
|
|
|
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q
|
2008-03-30 12:29:07 +00:00
|
|
|
assert q.is_public?
|
|
|
|
|
assert q.has_default_columns?
|
|
|
|
|
assert q.valid?
|
|
|
|
|
end
|
2011-08-31 22:58:10 +00:00
|
|
|
|
2011-12-17 17:54:52 +00:00
|
|
|
def test_create_project_private_query
|
2008-03-30 12:29:07 +00:00
|
|
|
@request.session[:user_id] = 3
|
2020-10-24 14:40:03 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:project_id => 'ecookbook',
|
|
|
|
|
:default_columns => '1',
|
|
|
|
|
:fields => ["status_id", "assigned_to_id"],
|
|
|
|
|
:operators => {
|
|
|
|
|
"assigned_to_id" => "=", "status_id" => "o"
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:values => {
|
|
|
|
|
"assigned_to_id" => ["1"], "status_id" => ["1"]
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:query => {
|
|
|
|
|
"name" => "test_new_project_private_query", "visibility" => "0"
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2008-03-30 12:29:07 +00:00
|
|
|
q = Query.find_by_name('test_new_project_private_query')
|
2009-09-13 17:14:35 +00:00
|
|
|
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q
|
2008-03-30 12:29:07 +00:00
|
|
|
assert !q.is_public?
|
|
|
|
|
assert q.has_default_columns?
|
|
|
|
|
assert q.valid?
|
|
|
|
|
end
|
2011-08-31 22:58:10 +00:00
|
|
|
|
2015-08-02 07:02:44 +00:00
|
|
|
def test_create_project_roles_query
|
|
|
|
|
@request.session[:user_id] = 2
|
2020-10-24 14:40:03 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:project_id => 'ecookbook',
|
|
|
|
|
:default_columns => '1',
|
|
|
|
|
:fields => ["status_id", "assigned_to_id"],
|
|
|
|
|
:operators => {
|
|
|
|
|
"assigned_to_id" => "=", "status_id" => "o"
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:values => {
|
|
|
|
|
"assigned_to_id" => ["1"], "status_id" => ["1"]
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:query => {
|
2020-10-24 14:40:03 +00:00
|
|
|
"name" => "test_create_project_roles_query",
|
|
|
|
|
"visibility" => "1",
|
|
|
|
|
"role_ids" => ["1", "2", ""]
|
2017-05-31 17:32:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2015-08-02 07:02:44 +00:00
|
|
|
q = Query.find_by_name('test_create_project_roles_query')
|
|
|
|
|
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook', :query_id => q
|
|
|
|
|
assert_equal Query::VISIBILITY_ROLES, q.visibility
|
|
|
|
|
assert_equal [1, 2], q.roles.ids.sort
|
|
|
|
|
end
|
|
|
|
|
|
2011-12-17 17:54:52 +00:00
|
|
|
def test_create_global_private_query_with_custom_columns
|
2008-03-30 14:20:07 +00:00
|
|
|
@request.session[:user_id] = 3
|
2020-10-24 14:40:03 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:fields => ["status_id", "assigned_to_id"],
|
|
|
|
|
:operators => {
|
|
|
|
|
"assigned_to_id" => "=", "status_id" => "o"
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:values => {
|
|
|
|
|
"assigned_to_id" => ["me"], "status_id" => ["1"]
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:query => {
|
|
|
|
|
"name" => "test_new_global_private_query", "visibility" => "0"
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:c => ["", "tracker", "subject", "priority", "category"]
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2008-03-30 14:20:07 +00:00
|
|
|
q = Query.find_by_name('test_new_global_private_query')
|
2009-09-13 17:14:35 +00:00
|
|
|
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q
|
2008-03-30 14:20:07 +00:00
|
|
|
assert !q.is_public?
|
|
|
|
|
assert !q.has_default_columns?
|
2013-02-23 10:53:21 +00:00
|
|
|
assert_equal [:id, :tracker, :subject, :priority, :category], q.columns.collect {|c| c.name}
|
2008-03-30 14:20:07 +00:00
|
|
|
assert q.valid?
|
|
|
|
|
end
|
2011-08-31 22:58:10 +00:00
|
|
|
|
2011-12-17 17:54:52 +00:00
|
|
|
def test_create_global_query_with_custom_filters
|
2011-10-24 20:19:26 +00:00
|
|
|
@request.session[:user_id] = 3
|
2020-10-24 14:40:03 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:fields => ["assigned_to_id"],
|
|
|
|
|
:operators => {
|
|
|
|
|
"assigned_to_id" => "="
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:values => {
|
|
|
|
|
"assigned_to_id" => ["me"]
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:query => {
|
|
|
|
|
"name" => "test_new_global_query"
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2011-10-24 20:19:26 +00:00
|
|
|
q = Query.find_by_name('test_new_global_query')
|
|
|
|
|
assert_redirected_to :controller => 'issues', :action => 'index', :project_id => nil, :query_id => q
|
2015-06-29 16:06:37 +00:00
|
|
|
assert !q.is_public?
|
2011-10-24 20:19:26 +00:00
|
|
|
assert !q.has_filter?(:status_id)
|
|
|
|
|
assert_equal ['assigned_to_id'], q.filters.keys
|
|
|
|
|
assert q.valid?
|
|
|
|
|
end
|
|
|
|
|
|
2011-12-17 17:54:52 +00:00
|
|
|
def test_create_with_sort
|
2009-03-12 18:06:54 +00:00
|
|
|
@request.session[:user_id] = 1
|
2020-10-24 14:40:03 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:default_columns => '1',
|
|
|
|
|
:operators => {
|
|
|
|
|
"status_id" => "o"
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:values => {
|
|
|
|
|
"status_id" => ["1"]
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:query => {
|
|
|
|
|
:name => "test_new_with_sort",
|
|
|
|
|
:visibility => "2",
|
|
|
|
|
:sort_criteria => {
|
2020-10-24 14:40:03 +00:00
|
|
|
"0" => ["due_date", "desc"], "1" => ["tracker", ""]
|
|
|
|
|
}
|
2017-05-31 17:32:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2009-03-12 18:06:54 +00: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-08-31 22:58:10 +00:00
|
|
|
|
2011-12-17 17:54:52 +00:00
|
|
|
def test_create_with_failure
|
|
|
|
|
@request.session[:user_id] = 2
|
2012-04-25 17:17:49 +00:00
|
|
|
assert_no_difference '::Query.count' do
|
2020-10-24 14:40:03 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:project_id => 'ecookbook',
|
|
|
|
|
:query => {
|
|
|
|
|
:name => ''
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2011-12-17 17:54:52 +00:00
|
|
|
end
|
|
|
|
|
assert_response :success
|
2016-07-19 20:06:01 +00:00
|
|
|
|
2012-05-25 16:50:25 +00:00
|
|
|
assert_select 'input[name=?]', 'query[name]'
|
2011-12-17 17:54:52 +00:00
|
|
|
end
|
|
|
|
|
|
2017-06-26 19:40:16 +00:00
|
|
|
def test_create_query_without_permission_should_fail
|
|
|
|
|
Role.all.each {|r| r.remove_permission! :save_queries, :manage_public_queries}
|
|
|
|
|
|
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
|
assert_no_difference '::Query.count' do
|
2020-10-24 14:40:03 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2017-06-26 19:40:16 +00:00
|
|
|
:project_id => 'ecookbook',
|
|
|
|
|
:query => {:name => 'Foo'}
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2017-06-26 19:40:16 +00:00
|
|
|
end
|
2024-05-18 05:56:55 +00:00
|
|
|
assert_response :forbidden
|
2017-06-26 19:40:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_create_global_query_without_permission_should_fail
|
|
|
|
|
Role.all.each {|r| r.remove_permission! :save_queries, :manage_public_queries}
|
|
|
|
|
|
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
|
assert_no_difference '::Query.count' do
|
2020-10-24 14:40:03 +00:00
|
|
|
post(:create, :params => {:query => {:name => 'Foo'}})
|
2017-06-26 19:40:16 +00:00
|
|
|
end
|
2024-05-18 05:56:55 +00:00
|
|
|
assert_response :forbidden
|
2017-06-26 19:40:16 +00:00
|
|
|
end
|
|
|
|
|
|
2013-07-14 13:41:30 +00:00
|
|
|
def test_create_global_query_from_gantt
|
|
|
|
|
@request.session[:user_id] = 1
|
|
|
|
|
assert_difference 'IssueQuery.count' do
|
2020-10-24 14:40:03 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:gantt => 1,
|
|
|
|
|
:operators => {
|
|
|
|
|
"status_id" => "o"
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:values => {
|
|
|
|
|
"status_id" => ["1"]
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:query => {
|
|
|
|
|
:name => "test_create_from_gantt",
|
|
|
|
|
:draw_relations => '1',
|
2019-05-16 21:54:33 +00:00
|
|
|
:draw_progress_line => '1',
|
|
|
|
|
:draw_selected_columns => '1'
|
2017-05-31 17:32:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2024-05-18 05:56:55 +00:00
|
|
|
assert_response :found
|
2013-07-14 13:41:30 +00:00
|
|
|
end
|
|
|
|
|
query = IssueQuery.order('id DESC').first
|
|
|
|
|
assert_redirected_to "/issues/gantt?query_id=#{query.id}"
|
|
|
|
|
assert_equal true, query.draw_relations
|
|
|
|
|
assert_equal true, query.draw_progress_line
|
2019-05-16 21:54:33 +00:00
|
|
|
assert_equal true, query.draw_selected_columns
|
2013-07-14 13:41:30 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_create_project_query_from_gantt
|
|
|
|
|
@request.session[:user_id] = 1
|
|
|
|
|
assert_difference 'IssueQuery.count' do
|
2020-10-24 14:40:03 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:project_id => 'ecookbook',
|
|
|
|
|
:gantt => 1,
|
|
|
|
|
:operators => {
|
|
|
|
|
"status_id" => "o"
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:values => {
|
|
|
|
|
"status_id" => ["1"]
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:query => {
|
|
|
|
|
:name => "test_create_from_gantt",
|
|
|
|
|
:draw_relations => '0',
|
2019-05-16 21:54:33 +00:00
|
|
|
:draw_progress_line => '0',
|
|
|
|
|
:draw_selected_columns => '0'
|
2017-05-31 17:32:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2024-05-18 05:56:55 +00:00
|
|
|
assert_response :found
|
2013-07-14 13:41:30 +00:00
|
|
|
end
|
|
|
|
|
query = IssueQuery.order('id DESC').first
|
|
|
|
|
assert_redirected_to "/projects/ecookbook/issues/gantt?query_id=#{query.id}"
|
|
|
|
|
assert_equal false, query.draw_relations
|
|
|
|
|
assert_equal false, query.draw_progress_line
|
2019-05-16 21:54:33 +00:00
|
|
|
assert_equal false, query.draw_selected_columns
|
2013-07-14 13:41:30 +00:00
|
|
|
end
|
|
|
|
|
|
2015-06-29 16:06:37 +00:00
|
|
|
def test_create_project_public_query_should_force_private_without_manage_public_queries_permission
|
|
|
|
|
@request.session[:user_id] = 3
|
|
|
|
|
query = new_record(Query) do
|
2020-10-24 14:40:03 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:project_id => 'ecookbook',
|
|
|
|
|
:query => {
|
|
|
|
|
"name" => "name", "visibility" => "2"
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2024-05-18 05:56:55 +00:00
|
|
|
assert_response :found
|
2015-06-29 16:06:37 +00:00
|
|
|
end
|
|
|
|
|
assert_not_nil query.project
|
|
|
|
|
assert_equal Query::VISIBILITY_PRIVATE, query.visibility
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_create_global_public_query_should_force_private_without_manage_public_queries_permission
|
|
|
|
|
@request.session[:user_id] = 3
|
|
|
|
|
query = new_record(Query) do
|
2020-10-24 14:40:03 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:project_id => 'ecookbook',
|
|
|
|
|
:query_is_for_all => '1',
|
|
|
|
|
:query => {
|
|
|
|
|
"name" => "name", "visibility" => "2"
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2024-05-18 05:56:55 +00:00
|
|
|
assert_response :found
|
2015-06-29 16:06:37 +00:00
|
|
|
end
|
|
|
|
|
assert_nil query.project
|
|
|
|
|
assert_equal Query::VISIBILITY_PRIVATE, query.visibility
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_create_project_public_query_with_manage_public_queries_permission
|
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
|
query = new_record(Query) do
|
2020-10-24 14:40:03 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:project_id => 'ecookbook',
|
|
|
|
|
:query => {
|
|
|
|
|
"name" => "name", "visibility" => "2"
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2024-05-18 05:56:55 +00:00
|
|
|
assert_response :found
|
2015-06-29 16:06:37 +00:00
|
|
|
end
|
|
|
|
|
assert_not_nil query.project
|
|
|
|
|
assert_equal Query::VISIBILITY_PUBLIC, query.visibility
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_create_global_public_query_should_force_private_with_manage_public_queries_permission
|
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
|
query = new_record(Query) do
|
2020-10-24 14:40:03 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:project_id => 'ecookbook',
|
|
|
|
|
:query_is_for_all => '1',
|
|
|
|
|
:query => {
|
|
|
|
|
"name" => "name", "visibility" => "2"
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2024-05-18 05:56:55 +00:00
|
|
|
assert_response :found
|
2015-06-29 16:06:37 +00:00
|
|
|
end
|
|
|
|
|
assert_nil query.project
|
|
|
|
|
assert_equal Query::VISIBILITY_PRIVATE, query.visibility
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_create_global_public_query_by_admin
|
|
|
|
|
@request.session[:user_id] = 1
|
|
|
|
|
query = new_record(Query) do
|
2020-10-24 14:40:03 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:project_id => 'ecookbook',
|
|
|
|
|
:query_is_for_all => '1',
|
|
|
|
|
:query => {
|
|
|
|
|
"name" => "name", "visibility" => "2"
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2024-05-18 05:56:55 +00:00
|
|
|
assert_response :found
|
2015-06-29 16:06:37 +00:00
|
|
|
end
|
|
|
|
|
assert_nil query.project
|
|
|
|
|
assert_equal Query::VISIBILITY_PUBLIC, query.visibility
|
|
|
|
|
end
|
|
|
|
|
|
2016-07-12 17:40:19 +00:00
|
|
|
def test_create_project_public_time_entry_query
|
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
|
|
|
|
|
|
q = new_record(TimeEntryQuery) do
|
2020-10-24 14:40:03 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:project_id => 'ecookbook',
|
|
|
|
|
:type => 'TimeEntryQuery',
|
|
|
|
|
:default_columns => '1',
|
|
|
|
|
:f => ["spent_on"],
|
|
|
|
|
:op => {
|
|
|
|
|
"spent_on" => "="
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:v => {
|
|
|
|
|
"spent_on" => ["2016-07-14"]
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:query => {
|
|
|
|
|
"name" => "test_new_project_public_query", "visibility" => "2"
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2016-07-12 17:40:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => 'ecookbook', :query_id => q.id
|
|
|
|
|
assert q.is_public?
|
|
|
|
|
assert q.has_default_columns?
|
|
|
|
|
assert q.valid?
|
|
|
|
|
end
|
|
|
|
|
|
2019-10-19 11:36:13 +00:00
|
|
|
def test_create_public_project_query
|
2019-11-20 15:01:24 +00:00
|
|
|
@request.session[:user_id] = 1
|
2019-10-19 11:36:13 +00:00
|
|
|
|
|
|
|
|
q = new_record(ProjectQuery) do
|
2020-10-24 14:40:03 +00:00
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
2019-10-19 11:36:13 +00:00
|
|
|
:type => 'ProjectQuery',
|
|
|
|
|
:default_columns => '1',
|
|
|
|
|
:f => ["status"],
|
|
|
|
|
:op => {
|
|
|
|
|
"status" => "="
|
|
|
|
|
},
|
|
|
|
|
:v => {
|
|
|
|
|
"status" => ['1']
|
|
|
|
|
},
|
|
|
|
|
:query => {
|
|
|
|
|
"name" => "test_new_project_public_query", "visibility" => "2"
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2019-10-19 11:36:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
assert_redirected_to :controller => 'projects', :action => 'index', :query_id => q.id
|
|
|
|
|
|
|
|
|
|
assert q.is_public?
|
|
|
|
|
assert q.valid?
|
|
|
|
|
end
|
|
|
|
|
|
2022-04-01 15:08:52 +00:00
|
|
|
def test_create_admin_projects_query_should_redirect_to_admin_projects
|
|
|
|
|
@request.session[:user_id] = 1
|
|
|
|
|
|
|
|
|
|
q = new_record(ProjectQuery) do
|
|
|
|
|
post(
|
|
|
|
|
:create,
|
|
|
|
|
:params => {
|
|
|
|
|
:type => 'ProjectQuery',
|
|
|
|
|
:default_columns => '1',
|
|
|
|
|
:f => ["status"],
|
|
|
|
|
:op => {
|
|
|
|
|
"status" => "="
|
|
|
|
|
},
|
|
|
|
|
:v => {
|
|
|
|
|
"status" => ['1']
|
|
|
|
|
},
|
|
|
|
|
:query => {
|
|
|
|
|
"name" => "test_new_project_public_query", "visibility" => "2"
|
|
|
|
|
},
|
|
|
|
|
:admin_projects => 1
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
assert_redirected_to :controller => 'admin', :action => 'projects', :query_id => q.id, :admin_projects => 1
|
|
|
|
|
end
|
|
|
|
|
|
2011-12-17 17:54:52 +00:00
|
|
|
def test_edit_global_public_query
|
2008-03-30 12:29:07 +00:00
|
|
|
@request.session[:user_id] = 1
|
2020-10-24 14:40:03 +00:00
|
|
|
get(:edit, :params => {:id => 4})
|
2008-03-30 12:29:07 +00:00
|
|
|
assert_response :success
|
2016-07-19 20:06:01 +00:00
|
|
|
|
2014-11-20 19:38:40 +00:00
|
|
|
assert_select 'input[name=?][value="2"][checked=checked]', 'query[visibility]'
|
2015-06-29 16:06:37 +00:00
|
|
|
assert_select 'input[name=query_is_for_all][type=checkbox][checked=checked]'
|
2008-03-30 12:29:07 +00:00
|
|
|
end
|
|
|
|
|
|
2011-12-17 17:54:52 +00:00
|
|
|
def test_edit_global_private_query
|
2008-03-30 12:29:07 +00:00
|
|
|
@request.session[:user_id] = 3
|
2020-10-24 14:40:03 +00:00
|
|
|
get(:edit, :params => {:id => 3})
|
2008-03-30 12:29:07 +00:00
|
|
|
assert_response :success
|
2016-07-19 20:06:01 +00:00
|
|
|
|
2013-07-11 17:45:10 +00:00
|
|
|
assert_select 'input[name=?]', 'query[visibility]', 0
|
2015-06-29 16:06:37 +00:00
|
|
|
assert_select 'input[name=query_is_for_all][type=checkbox][checked=checked]'
|
2008-03-30 12:29:07 +00:00
|
|
|
end
|
2011-08-31 22:58:10 +00:00
|
|
|
|
2011-12-17 17:54:52 +00:00
|
|
|
def test_edit_project_private_query
|
2008-03-30 12:29:07 +00:00
|
|
|
@request.session[:user_id] = 3
|
2020-10-24 14:40:03 +00:00
|
|
|
get(:edit, :params => {:id => 2})
|
2008-03-30 12:29:07 +00:00
|
|
|
assert_response :success
|
2016-07-19 20:06:01 +00:00
|
|
|
|
2013-07-11 17:45:10 +00:00
|
|
|
assert_select 'input[name=?]', 'query[visibility]', 0
|
2015-06-29 16:06:37 +00:00
|
|
|
assert_select 'input[name=query_is_for_all][type=checkbox]:not([checked])'
|
2008-03-30 12:29:07 +00:00
|
|
|
end
|
2011-08-31 22:58:10 +00:00
|
|
|
|
2011-12-17 17:54:52 +00:00
|
|
|
def test_edit_project_public_query
|
2008-03-30 12:29:07 +00:00
|
|
|
@request.session[:user_id] = 2
|
2020-10-24 14:40:03 +00:00
|
|
|
get(:edit, :params => {:id => 1})
|
2008-03-30 12:29:07 +00:00
|
|
|
assert_response :success
|
2016-07-19 20:06:01 +00:00
|
|
|
|
2014-11-20 19:38:40 +00:00
|
|
|
assert_select 'input[name=?][value="2"][checked=checked]', 'query[visibility]'
|
2015-06-29 16:06:37 +00:00
|
|
|
assert_select 'input[name=query_is_for_all][type=checkbox]:not([checked])'
|
2008-03-30 12:29:07 +00:00
|
|
|
end
|
2011-08-31 22:58:10 +00:00
|
|
|
|
2011-12-17 17:54:52 +00:00
|
|
|
def test_edit_sort_criteria
|
2009-03-12 18:06:54 +00:00
|
|
|
@request.session[:user_id] = 1
|
2020-10-24 14:40:03 +00:00
|
|
|
get(:edit, :params => {:id => 5})
|
2009-03-12 18:06:54 +00:00
|
|
|
assert_response :success
|
2016-07-19 20:06:01 +00:00
|
|
|
|
2014-11-22 09:38:21 +00:00
|
|
|
assert_select 'select[name=?]', 'query[sort_criteria][0][]' do
|
|
|
|
|
assert_select 'option[value=priority][selected=selected]'
|
|
|
|
|
assert_select 'option[value=desc][selected=selected]'
|
|
|
|
|
end
|
2009-03-12 18:06:54 +00:00
|
|
|
end
|
2011-08-31 22:58:10 +00:00
|
|
|
|
2011-12-17 17:54:52 +00:00
|
|
|
def test_edit_invalid_query
|
|
|
|
|
@request.session[:user_id] = 2
|
2020-10-24 14:40:03 +00:00
|
|
|
get(:edit, :params => {:id => 99})
|
2024-05-18 05:56:55 +00:00
|
|
|
assert_response :not_found
|
2011-12-17 17:54:52 +00:00
|
|
|
end
|
|
|
|
|
|
2018-03-01 05:10:44 +00:00
|
|
|
def test_update_global_private_query
|
2011-12-17 17:54:52 +00:00
|
|
|
@request.session[:user_id] = 3
|
2020-10-24 14:40:03 +00:00
|
|
|
put(
|
|
|
|
|
:update,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:id => 3,
|
|
|
|
|
:default_columns => '1',
|
|
|
|
|
:fields => ["status_id", "assigned_to_id"],
|
|
|
|
|
:operators => {
|
|
|
|
|
"assigned_to_id" => "=", "status_id" => "o"
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:values => {
|
|
|
|
|
"assigned_to_id" => ["me"], "status_id" => ["1"]
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:query => {
|
|
|
|
|
"name" => "test_edit_global_private_query", "visibility" => "2"
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2011-12-17 17:54:52 +00:00
|
|
|
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
|
2020-10-24 14:40:03 +00:00
|
|
|
put(
|
|
|
|
|
:update,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:id => 4,
|
|
|
|
|
:default_columns => '1',
|
|
|
|
|
:fields => ["status_id", "assigned_to_id"],
|
|
|
|
|
:operators => {
|
|
|
|
|
"assigned_to_id" => "=", "status_id" => "o"
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:values => {
|
|
|
|
|
"assigned_to_id" => ["1"], "status_id" => ["1"]
|
2017-09-15 04:49:32 +00:00
|
|
|
},
|
2017-05-31 17:32:34 +00:00
|
|
|
:query => {
|
|
|
|
|
"name" => "test_edit_global_public_query", "visibility" => "2"
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2011-12-17 17:54:52 +00:00
|
|
|
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
|
|
|
|
|
|
2022-04-01 15:08:52 +00:00
|
|
|
def test_update_admin_projects_query
|
|
|
|
|
q = ProjectQuery.create(:name => 'project_query')
|
|
|
|
|
@request.session[:user_id] = 1
|
|
|
|
|
|
|
|
|
|
put(
|
|
|
|
|
:update,
|
|
|
|
|
:params => {
|
|
|
|
|
:id => q.id,
|
|
|
|
|
:default_columns => '1',
|
|
|
|
|
:fields => ["status"],
|
|
|
|
|
:operators => {
|
|
|
|
|
"status" => "="
|
|
|
|
|
},
|
|
|
|
|
:values => {
|
|
|
|
|
"status" => ['1']
|
|
|
|
|
},
|
|
|
|
|
:query => {
|
|
|
|
|
"name" => "test_project_query_updated", "visibility" => "2"
|
|
|
|
|
},
|
|
|
|
|
:admin_projects => 1
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
assert_redirected_to :controller => 'admin', :action => 'projects', :query_id => q.id, :admin_projects => 1
|
|
|
|
|
assert Query.find_by_name('test_project_query_updated')
|
|
|
|
|
end
|
|
|
|
|
|
2011-12-17 17:54:52 +00:00
|
|
|
def test_update_with_failure
|
|
|
|
|
@request.session[:user_id] = 1
|
2020-10-24 14:40:03 +00:00
|
|
|
put(
|
|
|
|
|
:update,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:id => 4,
|
|
|
|
|
:query => {
|
|
|
|
|
:name => ''
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2011-12-17 17:54:52 +00:00
|
|
|
assert_response :success
|
2016-07-19 20:06:01 +00:00
|
|
|
assert_select_error /Name cannot be blank/
|
2011-12-17 17:54:52 +00:00
|
|
|
end
|
|
|
|
|
|
2008-03-30 12:29:07 +00:00
|
|
|
def test_destroy
|
|
|
|
|
@request.session[:user_id] = 2
|
2020-10-24 14:40:03 +00:00
|
|
|
delete(:destroy, :params => {:id => 1})
|
2008-03-30 12:29:07 +00: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 18:23:11 +00:00
|
|
|
|
|
|
|
|
def test_backslash_should_be_escaped_in_filters
|
|
|
|
|
@request.session[:user_id] = 2
|
2020-10-24 14:40:03 +00:00
|
|
|
get(:new, :params => {:subject => 'foo/bar'})
|
2012-09-25 18:23:11 +00:00
|
|
|
assert_response :success
|
|
|
|
|
assert_include 'addFilter("subject", "=", ["foo\/bar"]);', response.body
|
|
|
|
|
end
|
2017-01-09 19:59:54 +00:00
|
|
|
|
|
|
|
|
def test_filter_with_project_id_should_return_filter_values
|
|
|
|
|
@request.session[:user_id] = 2
|
2020-10-24 14:40:03 +00:00
|
|
|
get(
|
|
|
|
|
:filter,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:project_id => 1,
|
|
|
|
|
:name => 'fixed_version_id'
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2017-01-09 19:59:54 +00:00
|
|
|
assert_response :success
|
2020-01-27 03:54:25 +00:00
|
|
|
assert_equal 'application/json', response.media_type
|
2017-10-15 11:53:49 +00:00
|
|
|
json = ActiveSupport::JSON.decode(response.body)
|
|
|
|
|
assert_include ["eCookbook - 2.0", "3", "open"], json
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_version_filter_time_entries_with_project_id_should_return_filter_values
|
|
|
|
|
@request.session[:user_id] = 2
|
2020-10-24 14:40:03 +00:00
|
|
|
get(
|
|
|
|
|
:filter,
|
|
|
|
|
:params => {
|
2017-10-15 11:53:49 +00:00
|
|
|
:project_id => 1,
|
|
|
|
|
:type => 'TimeEntryQuery',
|
|
|
|
|
:name => 'issue.fixed_version_id'
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2017-10-15 11:53:49 +00:00
|
|
|
assert_response :success
|
2020-01-27 03:54:25 +00:00
|
|
|
assert_equal 'application/json', response.media_type
|
2017-01-09 19:59:54 +00:00
|
|
|
json = ActiveSupport::JSON.decode(response.body)
|
|
|
|
|
assert_include ["eCookbook - 2.0", "3", "open"], json
|
|
|
|
|
end
|
|
|
|
|
|
2018-06-30 00:24:59 +00:00
|
|
|
def test_version_filter_without_project_id_should_return_all_visible_fixed_versions
|
2018-06-29 07:11:56 +00:00
|
|
|
# Remove "jsmith" user from "Private child of eCookbook" project
|
|
|
|
|
Project.find(5).memberships.find_by(:user_id => 2).destroy
|
2017-01-09 19:59:54 +00:00
|
|
|
@request.session[:user_id] = 2
|
2020-10-24 14:40:03 +00:00
|
|
|
get(
|
|
|
|
|
:filter,
|
|
|
|
|
:params => {
|
2017-05-31 17:32:34 +00:00
|
|
|
:name => 'fixed_version_id'
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2017-01-09 19:59:54 +00:00
|
|
|
assert_response :success
|
2020-01-27 03:54:25 +00:00
|
|
|
assert_equal 'application/json', response.media_type
|
2017-01-09 19:59:54 +00:00
|
|
|
json = ActiveSupport::JSON.decode(response.body)
|
2018-06-29 07:11:56 +00:00
|
|
|
|
|
|
|
|
# response includes visible version
|
|
|
|
|
assert_include ["eCookbook Subproject 1 - 2.0", "4", "open"], json
|
|
|
|
|
assert_include ["eCookbook - 0.1", "1", "closed"], json
|
|
|
|
|
# response includes systemwide visible version
|
2017-01-09 19:59:54 +00:00
|
|
|
assert_include ["OnlineStore - Systemwide visible version", "7", "open"], json
|
2018-06-29 07:11:56 +00:00
|
|
|
# response doesn't include non visible version
|
2018-10-02 02:12:39 +00:00
|
|
|
assert_not_include ["Private child of eCookbook - Private Version of public subproject", "6", "open"], json
|
2017-01-09 19:59:54 +00:00
|
|
|
end
|
2017-10-15 11:42:00 +00:00
|
|
|
|
|
|
|
|
def test_subproject_filter_time_entries_with_project_id_should_return_filter_values
|
|
|
|
|
@request.session[:user_id] = 2
|
2020-10-24 14:40:03 +00:00
|
|
|
get(
|
|
|
|
|
:filter,
|
|
|
|
|
:params => {
|
2017-10-15 11:42:00 +00:00
|
|
|
:project_id => 1,
|
|
|
|
|
:type => 'TimeEntryQuery',
|
|
|
|
|
:name => 'subproject_id'
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2017-10-15 11:42:00 +00:00
|
|
|
assert_response :success
|
2020-01-27 03:54:25 +00:00
|
|
|
assert_equal 'application/json', response.media_type
|
2017-10-15 11:42:00 +00:00
|
|
|
json = ActiveSupport::JSON.decode(response.body)
|
|
|
|
|
assert_equal 4, json.count
|
2020-11-04 14:43:34 +00:00
|
|
|
assert_include ["Private child of eCookbook", "5"], json
|
2017-10-15 11:42:00 +00:00
|
|
|
end
|
2018-06-09 08:07:08 +00:00
|
|
|
|
|
|
|
|
def test_assignee_filter_should_return_active_and_locked_users_grouped_by_status
|
|
|
|
|
@request.session[:user_id] = 1
|
2020-10-24 14:40:03 +00:00
|
|
|
get(
|
|
|
|
|
:filter,
|
|
|
|
|
:params => {
|
2018-06-09 08:07:08 +00:00
|
|
|
:project_id => 1,
|
|
|
|
|
:type => 'IssueQuery',
|
|
|
|
|
:name => 'assigned_to_id'
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2018-06-09 08:07:08 +00:00
|
|
|
assert_response :success
|
2020-01-27 03:54:25 +00:00
|
|
|
assert_equal 'application/json', response.media_type
|
2018-06-09 08:07:08 +00:00
|
|
|
json = ActiveSupport::JSON.decode(response.body)
|
|
|
|
|
|
|
|
|
|
assert_equal 6, json.count
|
|
|
|
|
# "me" value should not be grouped
|
|
|
|
|
assert_include ["<< me >>", "me"], json
|
|
|
|
|
assert_include ["Dave Lopper", "3", "active"], json
|
|
|
|
|
assert_include ["Dave2 Lopper2", "5", "locked"], json
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_author_filter_should_return_active_and_locked_users_grouped_by_status
|
|
|
|
|
@request.session[:user_id] = 1
|
2020-10-24 14:40:03 +00:00
|
|
|
get(
|
|
|
|
|
:filter,
|
|
|
|
|
:params => {
|
2018-06-09 08:07:08 +00:00
|
|
|
:project_id => 1,
|
|
|
|
|
:type => 'IssueQuery',
|
|
|
|
|
:name => 'author_id'
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2018-06-09 08:07:08 +00:00
|
|
|
assert_response :success
|
2020-01-27 03:54:25 +00:00
|
|
|
assert_equal 'application/json', response.media_type
|
2018-06-09 08:07:08 +00:00
|
|
|
json = ActiveSupport::JSON.decode(response.body)
|
|
|
|
|
|
2019-11-10 07:58:57 +00:00
|
|
|
assert_equal 7, json.count
|
2018-06-09 08:07:08 +00:00
|
|
|
# "me" value should not be grouped
|
|
|
|
|
assert_include ["<< me >>", "me"], json
|
|
|
|
|
assert_include ["Dave Lopper", "3", "active"], json
|
|
|
|
|
assert_include ["Dave2 Lopper2", "5", "locked"], json
|
2019-11-13 13:22:05 +00:00
|
|
|
assert_include ["Anonymous", User.anonymous.id.to_s], json
|
2018-06-09 08:07:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_user_filter_should_return_active_and_locked_users_grouped_by_status
|
|
|
|
|
@request.session[:user_id] = 1
|
2020-10-24 14:40:03 +00:00
|
|
|
get(
|
|
|
|
|
:filter,
|
|
|
|
|
:params => {
|
2018-06-09 08:07:08 +00:00
|
|
|
:project_id => 1,
|
|
|
|
|
:type => 'TimeEntryQuery',
|
|
|
|
|
:name => 'user_id'
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2018-06-09 08:07:08 +00:00
|
|
|
assert_response :success
|
2020-01-27 03:54:25 +00:00
|
|
|
assert_equal 'application/json', response.media_type
|
2018-06-09 08:07:08 +00:00
|
|
|
json = ActiveSupport::JSON.decode(response.body)
|
|
|
|
|
|
2019-11-13 09:49:52 +00:00
|
|
|
assert_equal 7, json.count
|
2018-06-09 08:07:08 +00:00
|
|
|
# "me" value should not be grouped
|
|
|
|
|
assert_include ["<< me >>", "me"], json
|
|
|
|
|
assert_include ["Dave Lopper", "3", "active"], json
|
|
|
|
|
assert_include ["Dave2 Lopper2", "5", "locked"], json
|
|
|
|
|
end
|
2018-07-09 06:07:26 +00:00
|
|
|
|
|
|
|
|
def test_watcher_filter_without_permission_should_show_only_me
|
|
|
|
|
# This user does not have view_issue_watchers permission
|
|
|
|
|
@request.session[:user_id] = 7
|
2020-10-24 14:40:03 +00:00
|
|
|
get(
|
|
|
|
|
:filter,
|
|
|
|
|
:params => {
|
2018-07-09 06:07:26 +00:00
|
|
|
:project_id => 1,
|
|
|
|
|
:type => 'IssueQuery',
|
|
|
|
|
:name => 'watcher_id'
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2018-07-09 06:07:26 +00:00
|
|
|
assert_response :success
|
2020-01-27 03:54:25 +00:00
|
|
|
assert_equal 'application/json', response.media_type
|
2018-07-09 06:07:26 +00:00
|
|
|
json = ActiveSupport::JSON.decode(response.body)
|
|
|
|
|
|
|
|
|
|
assert_equal 1, json.count
|
|
|
|
|
assert_equal [["<< me >>", "me"]], json
|
|
|
|
|
end
|
|
|
|
|
|
2020-02-06 08:19:13 +00:00
|
|
|
def test_watcher_filter_with_permission_should_show_members_and_groups
|
2018-07-09 06:07:26 +00:00
|
|
|
# This user has view_issue_watchers permission
|
|
|
|
|
@request.session[:user_id] = 1
|
2020-10-24 14:40:03 +00:00
|
|
|
get(
|
|
|
|
|
:filter,
|
|
|
|
|
:params => {
|
2018-07-09 06:07:26 +00:00
|
|
|
:project_id => 1,
|
|
|
|
|
:type => 'IssueQuery',
|
|
|
|
|
:name => 'watcher_id'
|
|
|
|
|
}
|
2020-10-24 14:40:03 +00:00
|
|
|
)
|
2018-07-09 06:07:26 +00:00
|
|
|
assert_response :success
|
2020-01-27 03:54:25 +00:00
|
|
|
assert_equal 'application/json', response.media_type
|
2018-07-09 06:07:26 +00:00
|
|
|
json = ActiveSupport::JSON.decode(response.body)
|
|
|
|
|
|
2020-02-06 08:19:13 +00:00
|
|
|
assert_equal 7, json.count
|
2018-07-09 06:07:26 +00:00
|
|
|
# "me" value should not be grouped
|
|
|
|
|
assert_include ["<< me >>", "me"], json
|
|
|
|
|
assert_include ["Dave Lopper", "3", "active"], json
|
|
|
|
|
assert_include ["Dave2 Lopper2", "5", "locked"], json
|
2020-02-06 08:19:13 +00:00
|
|
|
assert_include ["A Team", "10", "active"], json
|
2018-07-09 06:07:26 +00:00
|
|
|
end
|
2021-02-11 06:48:29 +00:00
|
|
|
|
|
|
|
|
def test_watcher_filter_with_permission_should_show_members_and_groups_globally
|
|
|
|
|
# This user has view_issue_watchers permission
|
|
|
|
|
@request.session[:user_id] = 1
|
|
|
|
|
get(
|
|
|
|
|
:filter,
|
|
|
|
|
:params => {
|
|
|
|
|
:type => 'IssueQuery',
|
|
|
|
|
:name => 'watcher_id'
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_equal 'application/json', response.media_type
|
|
|
|
|
json = ActiveSupport::JSON.decode(response.body)
|
|
|
|
|
|
|
|
|
|
assert_equal 8, json.count
|
|
|
|
|
# "me" value should not be grouped
|
|
|
|
|
assert_include ['<< me >>', 'me'], json
|
|
|
|
|
assert_include ['Dave Lopper', '3', 'active'], json
|
|
|
|
|
assert_include ['Dave2 Lopper2', '5', 'locked'], json
|
|
|
|
|
assert_include ['A Team', '10', 'active'], json
|
|
|
|
|
end
|
2022-02-20 18:50:22 +00:00
|
|
|
|
|
|
|
|
def test_activity_filter_should_return_active_and_system_activity_ids
|
|
|
|
|
TimeEntryActivity.create!(:name => 'Design', :parent_id => 9, :project_id => 1)
|
|
|
|
|
TimeEntryActivity.create!(:name => 'QA', :active => false, :parent_id => 11, :project_id => 1)
|
|
|
|
|
TimeEntryActivity.create!(:name => 'Inactive Activity', :active => true, :parent_id => 14, :project_id => 1)
|
|
|
|
|
|
|
|
|
|
@request.session[:user_id] = 2
|
|
|
|
|
get(
|
|
|
|
|
:filter,
|
|
|
|
|
:params => {
|
|
|
|
|
:project_id => 1,
|
|
|
|
|
:type => 'TimeEntryQuery',
|
|
|
|
|
:name => 'activity_id'
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
assert_response :success
|
|
|
|
|
assert_equal 'application/json', response.media_type
|
|
|
|
|
json = ActiveSupport::JSON.decode(response.body)
|
|
|
|
|
|
|
|
|
|
assert_equal 3, json.count
|
|
|
|
|
assert_include ["Design", "9"], json
|
|
|
|
|
assert_include ["Development", "10"], json
|
|
|
|
|
assert_include ["Inactive Activity", "14"], json
|
|
|
|
|
end
|
2008-03-30 12:29:07 +00:00
|
|
|
end
|