parent
fbe56b9e98
commit
c19cdada66
@ -0,0 +1,48 @@ |
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||
# |
||||
# 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-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. |
||||
# |
||||
# See COPYRIGHT and LICENSE files for more details. |
||||
#++ |
||||
|
||||
class Queries::Views::Filters::TypeFilter < Queries::Views::Filters::ViewFilter |
||||
def type |
||||
:list_optional |
||||
end |
||||
|
||||
def where |
||||
operator_strategy.sql_for_field(transformed_values, View.table_name, 'type') |
||||
end |
||||
|
||||
def transformed_values |
||||
values.map { |value| value[/Views::(?<name>.*?)$/, "name"].underscore } |
||||
end |
||||
|
||||
def allowed_values |
||||
Constants::Views.registered_types.map do |type| |
||||
long_name = "Views::#{type}" |
||||
[long_name, long_name] |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,60 @@ |
||||
#-- copyright |
||||
# OpenProject is an open source project management software. |
||||
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||
# |
||||
# 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-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. |
||||
# |
||||
# See COPYRIGHT and LICENSE files for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe Queries::Views::Filters::TypeFilter, type: :model do |
||||
let(:current_user) { FactoryBot.create(:user) } |
||||
|
||||
before do |
||||
login_as(current_user) |
||||
end |
||||
|
||||
it_behaves_like 'basic query filter' do |
||||
let(:class_key) { :type } |
||||
let(:type) { :list_optional } |
||||
|
||||
describe '#allowed_values' do |
||||
it 'is a list of the possible values' do |
||||
expected = [ |
||||
%w[Views::TeamPlanner Views::TeamPlanner], |
||||
%w[Views::WorkPackagesTable Views::WorkPackagesTable] |
||||
] |
||||
|
||||
expect(instance.allowed_values).to match_array(expected) |
||||
end |
||||
end |
||||
end |
||||
|
||||
it_behaves_like 'list_optional query filter' do |
||||
let(:attribute) { :type } |
||||
let(:model) { View } |
||||
let(:valid_values) { %w[Views::TeamPlanner Views::WorkPackagesTable] } |
||||
let(:transformed_values) { %w[team_planner work_packages_table] } |
||||
end |
||||
end |
Loading…
Reference in new issue