Merge pull request #6879 from opf/feature/29116/search-filter-for-work-packages
Create SearchFilter on work packagespull/6949/head
commit
b23dceab63
@ -0,0 +1,36 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 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. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Queries::Filters::Strategies |
||||
class Search < BaseStrategy |
||||
self.supported_operators = ['**'] |
||||
self.default_operator = '**' |
||||
end |
||||
end |
@ -0,0 +1,36 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 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. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Queries::Operators |
||||
class Everywhere < Base |
||||
label 'everywhere' |
||||
set_symbol '**' |
||||
end |
||||
end |
@ -0,0 +1,43 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 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. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class Queries::WorkPackages::Filter::CommentFilter < Queries::WorkPackages::Filter::WorkPackageFilter |
||||
def type |
||||
:text |
||||
end |
||||
|
||||
def includes |
||||
%i{journals} |
||||
end |
||||
|
||||
def where |
||||
operator_strategy.sql_for_field(values, Journal.table_name, 'notes') |
||||
end |
||||
end |
@ -0,0 +1,35 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 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. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class Queries::WorkPackages::Filter::DescriptionFilter < Queries::WorkPackages::Filter::WorkPackageFilter |
||||
def type |
||||
:text |
||||
end |
||||
end |
@ -0,0 +1,40 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 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. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
|
||||
class Queries::WorkPackages::Filter::FilterConfiguration |
||||
attr_accessor(:filter_class, :filter_name, :operator) |
||||
|
||||
def initialize(filter_class, filter_name, operator) |
||||
@filter_class = filter_class |
||||
@filter_name = filter_name |
||||
@operator = operator |
||||
end |
||||
end |
@ -0,0 +1,40 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 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. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Queries::WorkPackages::Filter::FilterOnTsvMixin |
||||
def concatenation |
||||
case operator |
||||
when '~' |
||||
:and |
||||
when '!~' |
||||
:and_not |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,75 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 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. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module Queries::WorkPackages::Filter::OrFilterForWpMixin |
||||
def filters |
||||
if @filters |
||||
update_instances |
||||
else |
||||
@filters = create_instances |
||||
end |
||||
|
||||
@filters.keep_if(&:validate) |
||||
end |
||||
|
||||
def includes |
||||
filters.map(&:includes).flatten.uniq.reject(&:blank?) |
||||
end |
||||
|
||||
def where |
||||
filters.map(&:where).join(' OR ') |
||||
end |
||||
|
||||
def filter_configurations |
||||
raise NotImplementedError |
||||
end |
||||
|
||||
def create_instances |
||||
filter_configurations.map do |conf| |
||||
conf.filter_class.create!(name: conf.filter_name, |
||||
context: context, |
||||
operator: conf.operator, |
||||
values: values) |
||||
end |
||||
end |
||||
|
||||
def update_instances |
||||
configurations = filter_configurations |
||||
|
||||
@filters.each_with_index do |filter, index| |
||||
filter.operator = configurations[index].operator |
||||
filter.values = values |
||||
end |
||||
end |
||||
|
||||
def ar_object_filter? |
||||
false |
||||
end |
||||
end |
@ -0,0 +1,90 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 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. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
class Queries::WorkPackages::Filter::SearchFilter < |
||||
Queries::WorkPackages::Filter::WorkPackageFilter |
||||
|
||||
include Queries::WorkPackages::Filter::OrFilterForWpMixin |
||||
include Queries::WorkPackages::Filter::FilterOnTsvMixin |
||||
CONTAINS_OPERATOR = '~'.freeze |
||||
|
||||
CE_FILTERS = [ |
||||
Queries::WorkPackages::Filter::FilterConfiguration.new( |
||||
Queries::WorkPackages::Filter::SubjectFilter, |
||||
:subject, |
||||
CONTAINS_OPERATOR |
||||
), |
||||
Queries::WorkPackages::Filter::FilterConfiguration.new( |
||||
Queries::WorkPackages::Filter::DescriptionFilter, |
||||
:subject, |
||||
CONTAINS_OPERATOR |
||||
), |
||||
Queries::WorkPackages::Filter::FilterConfiguration.new( |
||||
Queries::WorkPackages::Filter::CommentFilter, |
||||
:subject, |
||||
CONTAINS_OPERATOR |
||||
) |
||||
].freeze |
||||
|
||||
EE_TSV_FILTERS = [ |
||||
Queries::WorkPackages::Filter::FilterConfiguration.new( |
||||
Queries::WorkPackages::Filter::AttachmentContentFilter, |
||||
:subject, |
||||
CONTAINS_OPERATOR |
||||
), |
||||
Queries::WorkPackages::Filter::FilterConfiguration.new( |
||||
Queries::WorkPackages::Filter::AttachmentFileNameFilter, |
||||
:subject, |
||||
CONTAINS_OPERATOR |
||||
) |
||||
].freeze |
||||
|
||||
def self.key |
||||
:search |
||||
end |
||||
|
||||
def name |
||||
:search |
||||
end |
||||
|
||||
def type |
||||
:search |
||||
end |
||||
|
||||
def human_name |
||||
I18n.t('label_search') |
||||
end |
||||
|
||||
def filter_configurations |
||||
list = CE_FILTERS |
||||
list += EE_TSV_FILTERS if EnterpriseToken.allows_to?(:attachment_filters) && OpenProject::Database.allows_tsv? |
||||
list |
||||
end |
||||
end |
@ -0,0 +1,39 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 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. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
module API |
||||
module V3 |
||||
module Queries |
||||
module Schemas |
||||
class SearchFilterDependencyRepresenter < TextFilterDependencyRepresenter; end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,61 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 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. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe Queries::WorkPackages::Filter::CommentFilter, type: :model do |
||||
it_behaves_like 'basic query filter' do |
||||
let(:type) { :text } |
||||
let(:class_key) { :comment } |
||||
|
||||
describe '#available?' do |
||||
it 'is available' do |
||||
expect(instance).to be_available |
||||
end |
||||
end |
||||
|
||||
describe '#allowed_values' do |
||||
it 'is nil' do |
||||
expect(instance.allowed_values).to be_nil |
||||
end |
||||
end |
||||
|
||||
describe '#valid_values!' do |
||||
it 'is a noop' do |
||||
instance.values = ['none', 'is', 'changed'] |
||||
|
||||
instance.valid_values! |
||||
|
||||
expect(instance.values) |
||||
.to match_array ['none', 'is', 'changed'] |
||||
end |
||||
end |
||||
|
||||
it_behaves_like 'non ar filter' |
||||
end |
||||
end |
@ -0,0 +1,61 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 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. |
||||
# |
||||
# See docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe Queries::WorkPackages::Filter::DescriptionFilter, type: :model do |
||||
it_behaves_like 'basic query filter' do |
||||
let(:type) { :text } |
||||
let(:class_key) { :description } |
||||
|
||||
describe '#available?' do |
||||
it 'is available' do |
||||
expect(instance).to be_available |
||||
end |
||||
end |
||||
|
||||
describe '#allowed_values' do |
||||
it 'is nil' do |
||||
expect(instance.allowed_values).to be_nil |
||||
end |
||||
end |
||||
|
||||
describe '#valid_values!' do |
||||
it 'is a noop' do |
||||
instance.values = ['none', 'is', 'changed'] |
||||
|
||||
instance.valid_values! |
||||
|
||||
expect(instance.values) |
||||
.to match_array ['none', 'is', 'changed'] |
||||
end |
||||
end |
||||
|
||||
it_behaves_like 'non ar filter' |
||||
end |
||||
end |
@ -0,0 +1,143 @@ |
||||
#-- copyright |
||||
|
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF) |
||||
# |
||||
# This program is free software; you can redistribute it and/or |
||||
# modify it under the terms of the GNU General Public License version 3. |
||||
# |
||||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||
# Copyright (C) 2006-2017 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. |
||||
# |
||||
# See doc/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe Queries::WorkPackages::Filter::SearchFilter, type: :model do |
||||
let(:context) { nil } |
||||
let(:value) { 'bogus' } |
||||
let(:operator) { '**' } |
||||
let(:subject) { 'Some subject' } |
||||
let(:work_package) { FactoryBot.create(:work_package, subject: subject) } |
||||
let(:journal) { work_package.journals.last } |
||||
let(:instance) do |
||||
described_class.create!(name: :search, context: context, operator: operator, values: [value]) |
||||
end |
||||
|
||||
shared_examples "subject, description, and comment filter" do |
||||
context '' do |
||||
let!(:work_package) { FactoryBot.create(:work_package, subject: "A bogus subject", description: "And a short description") } |
||||
|
||||
it 'finds in subject' do |
||||
instance.values = ['bogus subject'] |
||||
expect(WorkPackage.eager_load(instance.includes).where(instance.where)) |
||||
.to match_array [work_package] |
||||
end |
||||
|
||||
it 'finds in description' do |
||||
instance.values = ['short description'] |
||||
expect(WorkPackage.eager_load(instance.includes).where(instance.where)) |
||||
.to match_array [work_package] |
||||
end |
||||
|
||||
it 'finds in comments' do |
||||
journal.notes = "bogus comment" |
||||
journal.save |
||||
|
||||
instance.values = [journal.notes] |
||||
expect(WorkPackage.eager_load(instance.includes).where(instance.where)) |
||||
.to match_array [work_package] |
||||
end |
||||
end |
||||
end |
||||
|
||||
if OpenProject::Database.allows_tsv? |
||||
context 'DB allows tsv' do |
||||
context 'with EE' do |
||||
before do |
||||
allow(EnterpriseToken).to receive(:allows_to?).and_return(false) |
||||
allow(EnterpriseToken).to receive(:allows_to?).with(:attachment_filters).and_return(true) |
||||
end |
||||
|
||||
it_behaves_like 'subject, description, and comment filter' |
||||
|
||||
context 'WP with attachment' do |
||||
let(:text) { 'lorem ipsum' } |
||||
let(:filename) { 'plaintext-file.txt' } |
||||
let(:attachment) { FactoryBot.create(:attachment, container: work_package, filename: filename) } |
||||
|
||||
before do |
||||
allow_any_instance_of(Plaintext::Resolver).to receive(:text).and_return(text) |
||||
allow(attachment).to receive(:readable?).and_return(true) |
||||
attachment.reload |
||||
work_package.reload |
||||
end |
||||
|
||||
it "finds in attachment content" do |
||||
instance.values = ['ipsum'] |
||||
expect(WorkPackage.eager_load(instance.includes).where(instance.where)) |
||||
.to match_array [work_package] |
||||
end |
||||
|
||||
it "finds in attachment file name" do |
||||
instance.values = [filename] |
||||
expect(WorkPackage.eager_load(instance.includes).where(instance.where)) |
||||
.to match_array [work_package] |
||||
end |
||||
end |
||||
end |
||||
|
||||
it_behaves_like 'basic query filter' do |
||||
let(:type) { :search } |
||||
let(:class_key) { :search } |
||||
|
||||
describe '#available?' do |
||||
it 'is available' do |
||||
expect(instance).to be_available |
||||
end |
||||
end |
||||
|
||||
describe '#allowed_values' do |
||||
it 'is nil' do |
||||
expect(instance.allowed_values).to be_nil |
||||
end |
||||
end |
||||
|
||||
describe '#valid_values!' do |
||||
it 'is a noop' do |
||||
instance.values = ['none', 'is', 'changed'] |
||||
|
||||
instance.valid_values! |
||||
|
||||
expect(instance.values) |
||||
.to match_array ['none', 'is', 'changed'] |
||||
end |
||||
end |
||||
|
||||
it_behaves_like 'non ar filter' |
||||
end |
||||
end |
||||
else |
||||
context 'DB does not support TSV' do |
||||
context 'WP without attachment' do |
||||
it_behaves_like 'subject, description, and comment filter' |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue