kanbanworkflowstimelinescrumrubyroadmapproject-planningproject-managementopenprojectangularissue-trackerifcgantt-chartganttbug-trackerboardsbcf
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
704 lines
27 KiB
704 lines
27 KiB
13 years ago
|
#-- encoding: UTF-8
|
||
14 years ago
|
#-- copyright
|
||
12 years ago
|
# OpenProject is a project management system.
|
||
10 years ago
|
# Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
|
||
14 years ago
|
#
|
||
17 years ago
|
# This program is free software; you can redistribute it and/or
|
||
12 years ago
|
# modify it under the terms of the GNU General Public License version 3.
|
||
14 years ago
|
#
|
||
11 years ago
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
|
||
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
||
|
#
|
||
|
# 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.
|
||
|
#
|
||
|
# 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.
|
||
|
#
|
||
|
# 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.
|
||
|
#
|
||
14 years ago
|
# See doc/COPYRIGHT.rdoc for more details.
|
||
|
#++
|
||
10 years ago
|
require 'legacy_spec_helper'
|
||
17 years ago
|
|
||
11 years ago
|
describe Query, type: :model do
|
||
12 years ago
|
fixtures :all
|
||
17 years ago
|
|
||
11 years ago
|
it 'should custom fields for all projects should be available in global queries' do
|
||
10 years ago
|
query = Query.new(project: nil, name: '_')
|
||
11 years ago
|
assert query.work_package_filter_available?('cf_1')
|
||
|
assert !query.work_package_filter_available?('cf_3')
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should system shared versions should be available in global queries' do
|
||
15 years ago
|
Version.find(2).update_attribute :sharing, 'system'
|
||
10 years ago
|
query = Query.new(project: nil, name: '_')
|
||
11 years ago
|
assert query.work_package_filter_available?('fixed_version_id')
|
||
10 years ago
|
assert query.available_work_package_filters['fixed_version_id'][:values].detect { |v| v.last == '2' }
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should project filter in global queries' do
|
||
11 years ago
|
# User.current should be anonymous here
|
||
10 years ago
|
query = Query.new(project: nil, name: '_')
|
||
10 years ago
|
project_filter = query.available_work_package_filters['project_id']
|
||
9 years ago
|
refute_nil project_filter
|
||
10 years ago
|
project_ids = project_filter[:values].map { |p| p[1] }
|
||
|
assert project_ids.include?('1') # public project
|
||
|
assert !project_ids.include?('2') # private project anonymous user cannot see
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
17 years ago
|
def find_issues_with_query(query)
|
||
10 years ago
|
WorkPackage.includes(:assigned_to, :status, :type, :project, :priority)
|
||
|
.where(query.statement)
|
||
10 years ago
|
.references(:projects)
|
||
17 years ago
|
end
|
||
15 years ago
|
|
||
14 years ago
|
def assert_find_issues_with_query_is_successful(query)
|
||
9 years ago
|
expect {
|
||
14 years ago
|
find_issues_with_query(query)
|
||
9 years ago
|
}.not_to raise_error
|
||
14 years ago
|
end
|
||
|
|
||
|
def assert_query_statement_includes(query, condition)
|
||
|
assert query.statement.include?(condition), "Query statement condition not found in: #{query.statement}"
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should query should allow shared versions for a project query' do
|
||
15 years ago
|
subproject_version = Version.find(4)
|
||
10 years ago
|
query = Query.new(project: Project.find(1), name: '_')
|
||
15 years ago
|
query.add_filter('fixed_version_id', '=', [subproject_version.id.to_s])
|
||
|
|
||
11 years ago
|
assert query.statement.include?("#{WorkPackage.table_name}.fixed_version_id IN ('4')")
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should query with multiple custom fields' do
|
||
17 years ago
|
query = Query.find(1)
|
||
|
assert query.valid?
|
||
17 years ago
|
assert query.statement.include?("#{CustomValue.table_name}.value IN ('MySQL')")
|
||
17 years ago
|
issues = find_issues_with_query(query)
|
||
17 years ago
|
assert_equal 1, issues.length
|
||
11 years ago
|
assert_equal WorkPackage.find(3), issues.first
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should operator none' do
|
||
10 years ago
|
query = Query.new(project: Project.find(1), name: '_')
|
||
17 years ago
|
query.add_filter('fixed_version_id', '!*', [''])
|
||
|
query.add_filter('cf_1', '!*', [''])
|
||
11 years ago
|
assert query.statement.include?("#{WorkPackage.table_name}.fixed_version_id IS NULL")
|
||
17 years ago
|
assert query.statement.include?("#{CustomValue.table_name}.value IS NULL OR #{CustomValue.table_name}.value = ''")
|
||
17 years ago
|
find_issues_with_query(query)
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should operator none for integer' do
|
||
10 years ago
|
query = Query.new(project: Project.find(1), name: '_')
|
||
17 years ago
|
query.add_filter('estimated_hours', '!*', [''])
|
||
|
issues = find_issues_with_query(query)
|
||
|
assert !issues.empty?
|
||
10 years ago
|
assert issues.all? { |i| !i.estimated_hours }
|
||
17 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should operator all' do
|
||
10 years ago
|
query = Query.new(project: Project.find(1), name: '_')
|
||
17 years ago
|
query.add_filter('fixed_version_id', '*', [''])
|
||
|
query.add_filter('cf_1', '*', [''])
|
||
11 years ago
|
assert query.statement.include?("#{WorkPackage.table_name}.fixed_version_id IS NOT NULL")
|
||
17 years ago
|
assert query.statement.include?("#{CustomValue.table_name}.value IS NOT NULL AND #{CustomValue.table_name}.value <> ''")
|
||
17 years ago
|
find_issues_with_query(query)
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should operator greater than' do
|
||
10 years ago
|
query = Query.new(project: Project.find(1), name: '_')
|
||
17 years ago
|
query.add_filter('done_ratio', '>=', ['40'])
|
||
11 years ago
|
assert query.statement.include?("#{WorkPackage.table_name}.done_ratio >= 40")
|
||
17 years ago
|
find_issues_with_query(query)
|
||
17 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should operator in more than' do
|
||
11 years ago
|
WorkPackage.find(7).update_attribute(:due_date, (Date.today + 15))
|
||
10 years ago
|
query = Query.new(project: Project.find(1), name: '_')
|
||
17 years ago
|
query.add_filter('due_date', '>t+', ['15'])
|
||
16 years ago
|
issues = find_issues_with_query(query)
|
||
|
assert !issues.empty?
|
||
10 years ago
|
issues.each { |issue| assert(issue.due_date >= (Date.today + 15)) }
|
||
17 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should operator in less than' do
|
||
10 years ago
|
query = Query.new(project: Project.find(1), name: '_')
|
||
17 years ago
|
query.add_filter('due_date', '<t+', ['15'])
|
||
16 years ago
|
issues = find_issues_with_query(query)
|
||
|
assert !issues.empty?
|
||
10 years ago
|
issues.each { |issue| assert(issue.due_date >= Date.today && issue.due_date <= (Date.today + 15)) }
|
||
16 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should operator less than ago' do
|
||
11 years ago
|
WorkPackage.find(7).update_attribute(:due_date, (Date.today - 3))
|
||
10 years ago
|
query = Query.new(project: Project.find(1), name: '_')
|
||
16 years ago
|
query.add_filter('due_date', '>t-', ['3'])
|
||
|
issues = find_issues_with_query(query)
|
||
|
assert !issues.empty?
|
||
10 years ago
|
issues.each { |issue| assert(issue.due_date >= (Date.today - 3) && issue.due_date <= Date.today) }
|
||
16 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should operator more than ago' do
|
||
11 years ago
|
WorkPackage.find(7).update_attribute(:due_date, (Date.today - 10))
|
||
10 years ago
|
query = Query.new(project: Project.find(1), name: '_')
|
||
16 years ago
|
query.add_filter('due_date', '<t-', ['10'])
|
||
11 years ago
|
assert query.statement.include?("#{WorkPackage.table_name}.due_date <=")
|
||
16 years ago
|
issues = find_issues_with_query(query)
|
||
|
assert !issues.empty?
|
||
10 years ago
|
issues.each { |issue| assert(issue.due_date <= (Date.today - 10)) }
|
||
16 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should operator in' do
|
||
11 years ago
|
WorkPackage.find(7).update_attribute(:due_date, (Date.today + 2))
|
||
10 years ago
|
query = Query.new(project: Project.find(1), name: '_')
|
||
16 years ago
|
query.add_filter('due_date', 't+', ['2'])
|
||
|
issues = find_issues_with_query(query)
|
||
|
assert !issues.empty?
|
||
10 years ago
|
issues.each { |issue| assert_equal((Date.today + 2), issue.due_date) }
|
||
16 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should operator ago' do
|
||
11 years ago
|
WorkPackage.find(7).update_attribute(:due_date, (Date.today - 3))
|
||
10 years ago
|
query = Query.new(project: Project.find(1), name: '_')
|
||
16 years ago
|
query.add_filter('due_date', 't-', ['3'])
|
||
|
issues = find_issues_with_query(query)
|
||
|
assert !issues.empty?
|
||
10 years ago
|
issues.each { |issue| assert_equal((Date.today - 3), issue.due_date) }
|
||
17 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should operator today' do
|
||
10 years ago
|
query = Query.new(project: Project.find(1), name: '_')
|
||
17 years ago
|
query.add_filter('due_date', 't', [''])
|
||
16 years ago
|
issues = find_issues_with_query(query)
|
||
|
assert !issues.empty?
|
||
10 years ago
|
issues.each { |issue| assert_equal Date.today, issue.due_date }
|
||
17 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should operator this week on date' do
|
||
10 years ago
|
query = Query.new(project: Project.find(1), name: '_')
|
||
17 years ago
|
query.add_filter('due_date', 'w', [''])
|
||
17 years ago
|
find_issues_with_query(query)
|
||
17 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should operator this week on datetime' do
|
||
10 years ago
|
query = Query.new(project: Project.find(1), name: '_')
|
||
17 years ago
|
query.add_filter('created_on', 'w', [''])
|
||
17 years ago
|
find_issues_with_query(query)
|
||
17 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should operator contains' do
|
||
10 years ago
|
query = Query.new(project: Project.find(1), name: '_')
|
||
16 years ago
|
query.add_filter('subject', '~', ['uNable'])
|
||
11 years ago
|
assert query.statement.include?("LOWER(#{WorkPackage.table_name}.subject) LIKE '%unable%'")
|
||
16 years ago
|
result = find_issues_with_query(query)
|
||
|
assert result.empty?
|
||
10 years ago
|
result.each { |issue| assert issue.subject.downcase.include?('unable') }
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should operator does not contains' do
|
||
10 years ago
|
query = Query.new(project: Project.find(1), name: '_')
|
||
16 years ago
|
query.add_filter('subject', '!~', ['uNable'])
|
||
11 years ago
|
assert query.statement.include?("LOWER(#{WorkPackage.table_name}.subject) NOT LIKE '%unable%'")
|
||
17 years ago
|
find_issues_with_query(query)
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should filter assigned to me' do
|
||
11 years ago
|
user = User.find(2)
|
||
|
group = Group.find(10)
|
||
11 years ago
|
project = Project.find(1)
|
||
11 years ago
|
User.current = user
|
||
10 years ago
|
i1 = FactoryGirl.create(:work_package, project: project, type: project.types.first, assigned_to: user)
|
||
|
i2 = FactoryGirl.create(:work_package, project: project, type: project.types.first, assigned_to: group)
|
||
|
i3 = FactoryGirl.create(:work_package, project: project, type: project.types.first, assigned_to: Group.find(11))
|
||
11 years ago
|
group.users << user
|
||
|
|
||
10 years ago
|
query = Query.new(name: '_', filters: [Queries::WorkPackages::Filter.new(:assigned_to_id, operator: '=', values: ['me'])])
|
||
11 years ago
|
result = query.results.work_packages
|
||
10 years ago
|
assert_equal WorkPackage.visible.where(assigned_to_id: ([2] + user.reload.group_ids)).sort_by(&:id), result.sort_by(&:id)
|
||
11 years ago
|
|
||
|
assert result.include?(i1)
|
||
|
assert result.include?(i2)
|
||
|
assert !result.include?(i3)
|
||
11 years ago
|
|
||
|
User.current = nil
|
||
11 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should filter watched issues' do
|
||
16 years ago
|
User.current = User.find(1)
|
||
11 years ago
|
query = Query.new(name: '_', filters: [Queries::WorkPackages::Filter.new(:watcher_id, operator: '=', values: ['me'])])
|
||
16 years ago
|
result = find_issues_with_query(query)
|
||
9 years ago
|
refute_nil result
|
||
16 years ago
|
assert !result.empty?
|
||
11 years ago
|
assert_equal WorkPackage.visible.watched_by(User.current).sort_by(&:id), result.sort_by(&:id)
|
||
16 years ago
|
User.current = nil
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should filter unwatched issues' do
|
||
16 years ago
|
User.current = User.find(1)
|
||
11 years ago
|
query = Query.new(name: '_', filters: [Queries::WorkPackages::Filter.new(:watcher_id, operator: '!', values: ['me'])])
|
||
16 years ago
|
result = find_issues_with_query(query)
|
||
9 years ago
|
refute_nil result
|
||
16 years ago
|
assert !result.empty?
|
||
11 years ago
|
assert_equal((WorkPackage.visible - WorkPackage.watched_by(User.current)).sort_by(&:id).size, result.sort_by(&:id).size)
|
||
16 years ago
|
User.current = nil
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should default columns' do
|
||
11 years ago
|
q = Query.new name: '_'
|
||
14 years ago
|
assert !q.columns.empty?
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should set column names' do
|
||
11 years ago
|
q = Query.new name: '_'
|
||
11 years ago
|
q.column_names = ['type', :subject, '', 'unknonw_column']
|
||
10 years ago
|
assert_equal [:type, :subject], q.columns.map(&:name)
|
||
17 years ago
|
c = q.columns.first
|
||
|
assert q.has_column?(c)
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should groupable columns should include custom fields' do
|
||
11 years ago
|
q = Query.new name: '_'
|
||
10 years ago
|
assert q.groupable_columns.detect { |c| c.is_a? QueryCustomFieldColumn }
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should grouped with valid column' do
|
||
10 years ago
|
q = Query.new(group_by: 'status', name: '_')
|
||
14 years ago
|
assert q.grouped?
|
||
9 years ago
|
refute_nil q.group_by_column
|
||
14 years ago
|
assert_equal :status, q.group_by_column.name
|
||
9 years ago
|
refute_nil q.group_by_statement
|
||
14 years ago
|
assert_equal 'status', q.group_by_statement
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should grouped with invalid column' do
|
||
10 years ago
|
q = Query.new(group_by: 'foo', name: '_')
|
||
14 years ago
|
assert !q.grouped?
|
||
|
assert_nil q.group_by_column
|
||
|
assert_nil q.group_by_statement
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should default sort' do
|
||
11 years ago
|
q = Query.new name: '_'
|
||
16 years ago
|
assert_equal [], q.sort_criteria
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should set sort criteria with hash' do
|
||
11 years ago
|
q = Query.new name: '_'
|
||
10 years ago
|
q.sort_criteria = { '0' => ['priority', 'desc'], '2' => ['type'] }
|
||
11 years ago
|
assert_equal [['priority', 'desc'], ['type', 'asc']], q.sort_criteria
|
||
16 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should set sort criteria with array' do
|
||
11 years ago
|
q = Query.new name: '_'
|
||
11 years ago
|
q.sort_criteria = [['priority', 'desc'], 'type']
|
||
|
assert_equal [['priority', 'desc'], ['type', 'asc']], q.sort_criteria
|
||
16 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should create query with sort' do
|
||
10 years ago
|
q = Query.new({ name: 'Sorted' }, initialize_with_default_filter: true)
|
||
11 years ago
|
q.sort_criteria = [['priority', 'desc'], 'type']
|
||
16 years ago
|
assert q.save
|
||
|
q.reload
|
||
11 years ago
|
assert_equal [['priority', 'desc'], ['type', 'asc']], q.sort_criteria
|
||
16 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should sort by string custom field asc' do
|
||
11 years ago
|
q = Query.new name: '_'
|
||
10 years ago
|
c = q.available_columns.find { |col| col.is_a?(QueryCustomFieldColumn) && col.custom_field.field_format == 'string' }
|
||
16 years ago
|
assert c
|
||
|
assert c.sortable
|
||
10 years ago
|
issues = WorkPackage.includes(:assigned_to, :status, :type, :project, :priority)
|
||
9 years ago
|
.where(q.statement)
|
||
|
.order(Array(c.sortable).map { |s| "#{s} ASC" }.join(', '))
|
||
|
.references(:projects)
|
||
10 years ago
|
values = issues.map { |i| i.custom_value_for(c.custom_field).to_s }
|
||
16 years ago
|
assert !values.empty?
|
||
16 years ago
|
assert_equal values.sort, values
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should sort by string custom field desc' do
|
||
11 years ago
|
q = Query.new name: '_'
|
||
10 years ago
|
c = q.available_columns.find { |col| col.is_a?(QueryCustomFieldColumn) && col.custom_field.field_format == 'string' }
|
||
16 years ago
|
assert c
|
||
|
assert c.sortable
|
||
10 years ago
|
issues = WorkPackage.includes(:assigned_to, :status, :type, :project, :priority)
|
||
9 years ago
|
.where(q.statement)
|
||
|
.order(Array(c.sortable).map { |s| "#{s} DESC" }.join(', '))
|
||
|
.references(:projects)
|
||
10 years ago
|
values = issues.map { |i| i.custom_value_for(c.custom_field).to_s }
|
||
16 years ago
|
assert !values.empty?
|
||
16 years ago
|
assert_equal values.sort.reverse, values
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should sort by float custom field asc' do
|
||
11 years ago
|
q = Query.new name: '_'
|
||
10 years ago
|
c = q.available_columns.find { |col| col.is_a?(QueryCustomFieldColumn) && col.custom_field.field_format == 'float' }
|
||
16 years ago
|
assert c
|
||
|
assert c.sortable
|
||
10 years ago
|
issues = WorkPackage.includes(:assigned_to, :status, :type, :project, :priority)
|
||
9 years ago
|
.where(q.statement)
|
||
|
.order(Array(c.sortable).map { |s| "#{s} ASC" }.join(', '))
|
||
|
.references(:projects)
|
||
10 years ago
|
values = issues.map { |i| begin; Kernel.Float(i.custom_value_for(c.custom_field).to_s); rescue; nil; end }.compact
|
||
16 years ago
|
assert !values.empty?
|
||
|
assert_equal values.sort, values
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should invalid query should raise query statement invalid error' do
|
||
11 years ago
|
q = Query.new name: '_'
|
||
9 years ago
|
assert_raises ActiveRecord::StatementInvalid do
|
||
10 years ago
|
q.results(conditions: 'foo = 1').work_packages.to_a
|
||
15 years ago
|
end
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should issue count by association group' do
|
||
10 years ago
|
q = Query.new(name: '_', group_by: 'assigned_to')
|
||
11 years ago
|
count_by_group = q.results.work_package_count_by_group
|
||
15 years ago
|
assert_kind_of Hash, count_by_group
|
||
10 years ago
|
assert_equal %w(NilClass User), count_by_group.keys.map { |k| k.class.name }.uniq.sort
|
||
|
assert_equal %w(Fixnum), count_by_group.values.map { |k| k.class.name }.uniq
|
||
15 years ago
|
assert count_by_group.has_key?(User.find(3))
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should issue count by list custom field group' do
|
||
10 years ago
|
q = Query.new(name: '_', group_by: 'cf_1')
|
||
11 years ago
|
count_by_group = q.results.work_package_count_by_group
|
||
15 years ago
|
assert_kind_of Hash, count_by_group
|
||
10 years ago
|
assert_equal %w(NilClass String), count_by_group.keys.map { |k| k.class.name }.uniq.sort
|
||
|
assert_equal %w(Fixnum), count_by_group.values.map { |k| k.class.name }.uniq
|
||
15 years ago
|
assert count_by_group.has_key?('MySQL')
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should issue count by date custom field group' do
|
||
10 years ago
|
q = Query.new(name: '_', group_by: 'cf_8')
|
||
11 years ago
|
count_by_group = q.results.work_package_count_by_group
|
||
15 years ago
|
assert_kind_of Hash, count_by_group
|
||
10 years ago
|
assert_equal %w(Date NilClass), count_by_group.keys.map { |k| k.class.name }.uniq.sort
|
||
|
assert_equal %w(Fixnum), count_by_group.values.map { |k| k.class.name }.uniq
|
||
15 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should label for' do
|
||
11 years ago
|
q = Query.new name: '_'
|
||
10 years ago
|
assert_equal WorkPackage.human_attribute_name('assigned_to_id'), q.label_for('assigned_to_id')
|
||
17 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should editable by' do
|
||
17 years ago
|
admin = User.find(1)
|
||
|
manager = User.find(2)
|
||
|
developer = User.find(3)
|
||
14 years ago
|
|
||
17 years ago
|
# Public query on project 1
|
||
|
q = Query.find(1)
|
||
|
assert q.editable_by?(admin)
|
||
|
assert q.editable_by?(manager)
|
||
|
assert !q.editable_by?(developer)
|
||
|
|
||
|
# Private query on project 1
|
||
|
q = Query.find(2)
|
||
|
assert q.editable_by?(admin)
|
||
|
assert !q.editable_by?(manager)
|
||
|
assert q.editable_by?(developer)
|
||
|
|
||
|
# Private query for all projects
|
||
|
q = Query.find(3)
|
||
|
assert q.editable_by?(admin)
|
||
|
assert !q.editable_by?(manager)
|
||
|
assert q.editable_by?(developer)
|
||
|
|
||
|
# Public query for all projects
|
||
|
q = Query.find(4)
|
||
|
assert q.editable_by?(admin)
|
||
|
assert !q.editable_by?(manager)
|
||
|
assert !q.editable_by?(developer)
|
||
|
end
|
||
14 years ago
|
|
||
10 years ago
|
context '#available_work_package_filters' do
|
||
11 years ago
|
before do
|
||
10 years ago
|
@query = Query.new(name: '_')
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should include users of visible projects in cross-project view' do
|
||
10 years ago
|
users = @query.available_work_package_filters['assigned_to_id']
|
||
9 years ago
|
refute_nil users
|
||
11 years ago
|
assert users[:values].map { |u| u[1] }.include?('3')
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should include visible projects in cross-project view' do
|
||
10 years ago
|
projects = @query.available_work_package_filters['project_id']
|
||
9 years ago
|
refute_nil projects
|
||
11 years ago
|
assert projects[:values].map { |u| u[1] }.include?('1')
|
||
14 years ago
|
end
|
||
|
|
||
14 years ago
|
context "'member_of_group' filter" do
|
||
11 years ago
|
it 'should be present' do
|
||
10 years ago
|
assert @query.available_work_package_filters.keys.include?('member_of_group')
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should be an optional list' do
|
||
10 years ago
|
assert_equal :list_optional, @query.available_work_package_filters['member_of_group'][:type]
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should have a list of the groups as values' do
|
||
14 years ago
|
Group.destroy_all # No fixtures
|
||
9 years ago
|
group1 = FactoryGirl.create(:group).reload
|
||
|
group2 = FactoryGirl.create(:group).reload
|
||
14 years ago
|
|
||
|
expected_group_list = [
|
||
10 years ago
|
[group1.name, group1.id.to_s],
|
||
|
[group2.name, group2.id.to_s]
|
||
|
]
|
||
|
assert_equal expected_group_list.sort, @query.available_work_package_filters['member_of_group'][:values].sort
|
||
14 years ago
|
end
|
||
|
end
|
||
14 years ago
|
|
||
|
context "'assigned_to_role' filter" do
|
||
11 years ago
|
it 'should be present' do
|
||
10 years ago
|
assert @query.available_work_package_filters.keys.include?('assigned_to_role')
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should be an optional list' do
|
||
10 years ago
|
assert_equal :list_optional, @query.available_work_package_filters['assigned_to_role'][:type]
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should have a list of the Roles as values' do
|
||
10 years ago
|
assert @query.available_work_package_filters['assigned_to_role'][:values].include?(['Manager', '1'])
|
||
|
assert @query.available_work_package_filters['assigned_to_role'][:values].include?(['Developer', '2'])
|
||
|
assert @query.available_work_package_filters['assigned_to_role'][:values].include?(['Reporter', '3'])
|
||
14 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should not include the built in Roles as values' do
|
||
10 years ago
|
assert ! @query.available_work_package_filters['assigned_to_role'][:values].include?(['Non member', '4'])
|
||
|
assert ! @query.available_work_package_filters['assigned_to_role'][:values].include?(['Anonymous', '5'])
|
||
14 years ago
|
end
|
||
|
end
|
||
|
|
||
13 years ago
|
context "'watcher_id' filter" do
|
||
10 years ago
|
context 'globally' do
|
||
|
context 'for an anonymous user' do
|
||
11 years ago
|
it 'should not be present' do
|
||
10 years ago
|
assert ! @query.available_work_package_filters.keys.include?('watcher_id')
|
||
13 years ago
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
context 'for a logged in user' do
|
||
11 years ago
|
before do
|
||
13 years ago
|
User.current = User.find 1
|
||
|
end
|
||
|
|
||
11 years ago
|
after do
|
||
13 years ago
|
User.current = nil
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should be present' do
|
||
10 years ago
|
assert @query.available_work_package_filters.keys.include?('watcher_id')
|
||
13 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should be a list' do
|
||
10 years ago
|
assert_equal :list, @query.available_work_package_filters['watcher_id'][:type]
|
||
13 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should have a list of active users as values' do
|
||
10 years ago
|
assert @query.available_work_package_filters['watcher_id'][:values].include?(['<< me >>', 'me'])
|
||
|
assert @query.available_work_package_filters['watcher_id'][:values].include?(['John Smith', '2'])
|
||
|
assert @query.available_work_package_filters['watcher_id'][:values].include?(['Dave Lopper', '3'])
|
||
|
assert @query.available_work_package_filters['watcher_id'][:values].include?(['redMine Admin', '1'])
|
||
|
assert @query.available_work_package_filters['watcher_id'][:values].include?(['User Misc', '8'])
|
||
13 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should not include active users not member of any project' do
|
||
10 years ago
|
assert ! @query.available_work_package_filters['watcher_id'][:values].include?(['Robert Hill', '4'])
|
||
13 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should not include locked users as values' do
|
||
10 years ago
|
assert ! @query.available_work_package_filters['watcher_id'][:values].include?(['Dave2 Lopper2', '5'])
|
||
13 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should not include the anonymous user as values' do
|
||
10 years ago
|
assert ! @query.available_work_package_filters['watcher_id'][:values].include?(['Anonymous', '6'])
|
||
13 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
context 'in a project' do
|
||
11 years ago
|
before do
|
||
13 years ago
|
@query.project = Project.find(1)
|
||
|
end
|
||
|
|
||
10 years ago
|
context 'for an anonymous user' do
|
||
11 years ago
|
it 'should not be present' do
|
||
10 years ago
|
assert ! @query.available_work_package_filters.keys.include?('watcher_id')
|
||
13 years ago
|
end
|
||
|
end
|
||
|
|
||
10 years ago
|
context 'for a logged in user' do
|
||
11 years ago
|
before do
|
||
13 years ago
|
User.current = User.find 1
|
||
|
end
|
||
|
|
||
11 years ago
|
after do
|
||
13 years ago
|
User.current = nil
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should be present' do
|
||
10 years ago
|
assert @query.available_work_package_filters.keys.include?('watcher_id')
|
||
13 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should be a list' do
|
||
10 years ago
|
assert_equal :list, @query.available_work_package_filters['watcher_id'][:type]
|
||
13 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should have a list of the project members as values' do
|
||
10 years ago
|
assert @query.available_work_package_filters['watcher_id'][:values].include?(['<< me >>', 'me'])
|
||
|
assert @query.available_work_package_filters['watcher_id'][:values].include?(['John Smith', '2'])
|
||
|
assert @query.available_work_package_filters['watcher_id'][:values].include?(['Dave Lopper', '3'])
|
||
13 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should not include non-project members as values' do
|
||
10 years ago
|
assert ! @query.available_work_package_filters['watcher_id'][:values].include?(['redMine Admin', '1'])
|
||
13 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should not include locked project members as values' do
|
||
10 years ago
|
assert ! @query.available_work_package_filters['watcher_id'][:values].include?(['Dave2 Lopper2', '5'])
|
||
13 years ago
|
end
|
||
|
|
||
11 years ago
|
it 'should not include the anonymous user as values' do
|
||
10 years ago
|
assert ! @query.available_work_package_filters['watcher_id'][:values].include?(['Anonymous', '6'])
|
||
13 years ago
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
10 years ago
|
context '#statement' do
|
||
14 years ago
|
context "with 'member_of_group' filter" do
|
||
11 years ago
|
before do
|
||
14 years ago
|
Group.destroy_all # No fixtures
|
||
9 years ago
|
@user_in_group = FactoryGirl.create(:user)
|
||
|
@second_user_in_group = FactoryGirl.create(:user)
|
||
|
@user_in_group2 = FactoryGirl.create(:user)
|
||
|
@user_not_in_group = FactoryGirl.create(:user)
|
||
14 years ago
|
|
||
9 years ago
|
@group = FactoryGirl.create(:group).reload
|
||
14 years ago
|
@group.users << @user_in_group
|
||
|
@group.users << @second_user_in_group
|
||
14 years ago
|
|
||
9 years ago
|
@group2 = FactoryGirl.create(:group).reload
|
||
14 years ago
|
@group2.users << @user_in_group2
|
||
14 years ago
|
|
||
9 years ago
|
@empty_group = FactoryGirl.create(:group).reload
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should search assigned to for users in the group' do
|
||
10 years ago
|
@query = Query.new(name: '_')
|
||
14 years ago
|
@query.add_filter('member_of_group', '=', [@group.id.to_s])
|
||
|
|
||
11 years ago
|
assert_query_statement_includes @query, "#{WorkPackage.table_name}.assigned_to_id IN ('#{@user_in_group.id}','#{@second_user_in_group.id}')"
|
||
14 years ago
|
assert_find_issues_with_query_is_successful @query
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should search not assigned to any group member (none)' do
|
||
10 years ago
|
@query = Query.new(name: '_')
|
||
14 years ago
|
@query.add_filter('member_of_group', '!*', [''])
|
||
|
|
||
|
# Users not in a group
|
||
11 years ago
|
assert_query_statement_includes @query, "#{WorkPackage.table_name}.assigned_to_id IS NULL OR #{WorkPackage.table_name}.assigned_to_id NOT IN ('#{@user_in_group.id}','#{@second_user_in_group.id}','#{@user_in_group2.id}')"
|
||
14 years ago
|
assert_find_issues_with_query_is_successful @query
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should search assigned to any group member (all)' do
|
||
10 years ago
|
@query = Query.new(name: '_')
|
||
14 years ago
|
@query.add_filter('member_of_group', '*', [''])
|
||
|
|
||
|
# Only users in a group
|
||
11 years ago
|
assert_query_statement_includes @query, "#{WorkPackage.table_name}.assigned_to_id IN ('#{@user_in_group.id}','#{@second_user_in_group.id}','#{@user_in_group2.id}')"
|
||
14 years ago
|
assert_find_issues_with_query_is_successful @query
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should return no results on empty set' do
|
||
10 years ago
|
@query = Query.new(name: '_')
|
||
14 years ago
|
@query.add_filter('member_of_group', '=', [@empty_group.id.to_s])
|
||
14 years ago
|
|
||
10 years ago
|
assert_query_statement_includes @query, '(0=1)'
|
||
14 years ago
|
assert find_issues_with_query(@query).empty?
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should return results on disallowed empty set' do
|
||
10 years ago
|
@query = Query.new(name: '_')
|
||
14 years ago
|
@query.add_filter('member_of_group', '!', [@empty_group.id.to_s])
|
||
14 years ago
|
|
||
10 years ago
|
assert_query_statement_includes @query, '(1=1)'
|
||
14 years ago
|
assert_find_issues_with_query_is_successful @query
|
||
14 years ago
|
end
|
||
|
end
|
||
14 years ago
|
|
||
|
context "with 'assigned_to_role' filter" do
|
||
11 years ago
|
before do
|
||
14 years ago
|
# No fixtures
|
||
|
MemberRole.delete_all
|
||
|
Member.delete_all
|
||
|
Role.delete_all
|
||
14 years ago
|
|
||
9 years ago
|
@manager_role = FactoryGirl.create(:role, name: 'Manager')
|
||
|
@developer_role = FactoryGirl.create(:role, name: 'Developer')
|
||
|
@empty_role = FactoryGirl.create(:role, name: 'Empty')
|
||
|
|
||
|
@project = FactoryGirl.create(:project)
|
||
|
@manager = FactoryGirl.create(:user)
|
||
|
@developer = FactoryGirl.create(:user)
|
||
|
@boss = FactoryGirl.create(:user)
|
||
|
FactoryGirl.create(:member, user: @manager, project: @project, role_ids: [@manager_role.id])
|
||
|
FactoryGirl.create(:member, user: @developer, project: @project, role_ids: [@developer_role.id])
|
||
|
FactoryGirl.create(:member, user: @boss, project: @project, role_ids: [@manager_role, @developer_role].map(&:id))
|
||
14 years ago
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should search assigned to for users with the Role' do
|
||
10 years ago
|
@query = Query.new(name: '_')
|
||
14 years ago
|
@query.add_filter('assigned_to_role', '=', [@manager_role.id.to_s])
|
||
|
|
||
11 years ago
|
assert_query_statement_includes @query, "#{WorkPackage.table_name}.assigned_to_id IN ('#{@manager.id}','#{@boss.id}')"
|
||
14 years ago
|
assert_find_issues_with_query_is_successful @query
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should search assigned to for users not assigned to any Role (none)' do
|
||
10 years ago
|
@query = Query.new(name: '_')
|
||
14 years ago
|
@query.add_filter('assigned_to_role', '!*', [''])
|
||
|
|
||
11 years ago
|
assert_query_statement_includes @query, "#{WorkPackage.table_name}.assigned_to_id IS NULL OR #{WorkPackage.table_name}.assigned_to_id NOT IN ('#{@manager.id}','#{@developer.id}','#{@boss.id}')"
|
||
14 years ago
|
assert_find_issues_with_query_is_successful @query
|
||
|
end
|
||
|
|
||
11 years ago
|
it 'should search assigned to for users assigned to any Role (all)' do
|
||
10 years ago
|
@query = Query.new(name: '_')
|
||
14 years ago
|
@query.add_filter('assigned_to_role', '*', [''])
|
||
|
|
||
11 years ago
|
assert_query_statement_includes @query, "#{WorkPackage.table_name}.assigned_to_id IN ('#{@manager.id}','#{@developer.id}','#{@boss.id}')"
|
||
14 years ago
|
assert_find_issues_with_query_is_successful @query
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should return no results on empty set' do
|
||
10 years ago
|
@query = Query.new(name: '_')
|
||
14 years ago
|
@query.add_filter('assigned_to_role', '=', [@empty_role.id.to_s])
|
||
14 years ago
|
|
||
10 years ago
|
assert_query_statement_includes @query, '(0=1)'
|
||
14 years ago
|
assert find_issues_with_query(@query).empty?
|
||
|
end
|
||
14 years ago
|
|
||
11 years ago
|
it 'should return results on disallowed empty set' do
|
||
10 years ago
|
@query = Query.new(name: '_')
|
||
14 years ago
|
@query.add_filter('assigned_to_role', '!', [@empty_role.id.to_s])
|
||
14 years ago
|
|
||
10 years ago
|
assert_query_statement_includes @query, '(1=1)'
|
||
14 years ago
|
assert_find_issues_with_query_is_successful @query
|
||
|
end
|
||
14 years ago
|
end
|
||
14 years ago
|
end
|
||
17 years ago
|
end
|