commit
716500f876
@ -0,0 +1,75 @@ |
||||
#-- 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::FilterForWpMixin |
||||
def type |
||||
:list |
||||
end |
||||
|
||||
def allowed_values |
||||
raise NotImplementedError, 'There would be too many candidates' |
||||
end |
||||
|
||||
def value_objects |
||||
scope.find(values) |
||||
end |
||||
|
||||
def allowed_objects |
||||
raise NotImplementedError, 'There would be too many candidates' |
||||
end |
||||
|
||||
def available? |
||||
scope.exists? |
||||
end |
||||
|
||||
def ar_object_filter? |
||||
true |
||||
end |
||||
|
||||
def allowed_values_subset |
||||
scope.where(id: values).pluck(:id).map(&:to_s) |
||||
end |
||||
|
||||
private |
||||
|
||||
def scope |
||||
if context.project |
||||
WorkPackage |
||||
.visible |
||||
.for_projects(context.project.self_and_descendants) |
||||
else |
||||
WorkPackage.visible |
||||
end |
||||
end |
||||
|
||||
def type_strategy |
||||
@type_strategy ||= Queries::Filters::Strategies::HugeList.new(self) |
||||
end |
||||
end |
@ -0,0 +1,47 @@ |
||||
#-- 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. |
||||
#++ |
||||
|
||||
require_relative './filter_for_wp_mixing' |
||||
|
||||
class Queries::WorkPackages::Filter::ParentFilter < |
||||
Queries::WorkPackages::Filter::WorkPackageFilter |
||||
|
||||
include ::Queries::WorkPackages::Filter::FilterForWpMixin |
||||
|
||||
def includes |
||||
:parent_relation |
||||
end |
||||
|
||||
def where |
||||
operator_strategy.sql_for_field(values, |
||||
Relation.table_name, |
||||
'from_id') |
||||
end |
||||
end |
@ -0,0 +1,143 @@ |
||||
#!/usr/bin/env puma |
||||
|
||||
# Load "path" as a rackup file. |
||||
# |
||||
# The default is "config.ru". |
||||
# |
||||
# rackup '/u/apps/lolcat/config.ru' |
||||
|
||||
# Set the port on which puma binds |
||||
port ENV['PORT'] || 3000 |
||||
|
||||
# Set the environment in which the rack's app will run. The value must be a string. |
||||
# |
||||
# The default is "development". |
||||
# |
||||
# environment 'production' |
||||
environment ENV['RAILS_ENV'] || 'development' |
||||
|
||||
# Disable request logging. |
||||
# |
||||
# The default is "false". |
||||
# |
||||
# quiet |
||||
|
||||
# Configure "min" to be the minimum number of threads to use to answer |
||||
# requests and "max" the maximum. |
||||
# |
||||
# The default is "0, 16". |
||||
# |
||||
threads 1, 1 |
||||
|
||||
# Code to run before doing a restart. This code should |
||||
# close log files, database connections, etc. |
||||
# |
||||
# This can be called multiple times to add code each time. |
||||
# |
||||
# on_restart do |
||||
# puts 'On restart...' |
||||
# end |
||||
|
||||
|
||||
# Command to use to restart puma. This should be just how to |
||||
# load puma itself (ie. 'ruby -Ilib bin/puma'), not the arguments |
||||
# to puma, as those are the same as the original process. |
||||
# |
||||
# restart_command '/u/app/lolcat/bin/restart_puma' |
||||
|
||||
# === Cluster mode === |
||||
|
||||
# How many worker processes to run. Typically this is set to |
||||
# to the number of available cores. |
||||
# |
||||
# The default is "0". |
||||
# |
||||
workers ENV['WEB_CONCURRENCY'] || 4 |
||||
|
||||
# Code to run immediately before the master starts workers. |
||||
# |
||||
# before_fork do |
||||
# puts "Starting workers..." |
||||
# end |
||||
|
||||
# Code to run in a worker before it starts serving requests. |
||||
# |
||||
# This is called everytime a worker is to be started. |
||||
# |
||||
on_worker_boot do |
||||
ActiveRecord::Base.establish_connection |
||||
end |
||||
|
||||
# Code to run in a worker right before it exits. |
||||
# |
||||
# This is called everytime a worker is to about to shutdown. |
||||
# |
||||
# on_worker_shutdown do |
||||
# puts 'On worker shutdown...' |
||||
# end |
||||
|
||||
# Code to run in the master right before a worker is started. The worker's |
||||
# index is passed as an argument. |
||||
# |
||||
# This is called everytime a worker is to be started. |
||||
# |
||||
# on_worker_fork do |
||||
# puts 'Before worker fork...' |
||||
# end |
||||
|
||||
# Code to run in the master after a worker has been started. The worker's |
||||
# index is passed as an argument. |
||||
# |
||||
# This is called everytime a worker is to be started. |
||||
# |
||||
# after_worker_fork do |
||||
# puts 'After worker fork...' |
||||
# end |
||||
|
||||
# Allow workers to reload bundler context when master process is issued |
||||
# a USR1 signal. This allows proper reloading of gems while the master |
||||
# is preserved across a phased-restart. (incompatible with preload_app) |
||||
# (off by default) |
||||
|
||||
# prune_bundler |
||||
|
||||
# Preload the application before starting the workers; this conflicts with |
||||
# phased restart feature. (off by default) |
||||
|
||||
preload_app! if ENV['RAILS_ENV'] == 'production' |
||||
|
||||
# Additional text to display in process listing |
||||
# |
||||
# tag 'app name' |
||||
# |
||||
# If you do not specify a tag, Puma will infer it. If you do not want Puma |
||||
# to add a tag, use an empty string. |
||||
|
||||
# Verifies that all workers have checked in to the master process within |
||||
# the given timeout. If not the worker process will be restarted. This is |
||||
# not a request timeout, it is to protect against a hung or dead process. |
||||
# Setting this value will not protect against slow requests. |
||||
# Default value is 60 seconds. |
||||
# |
||||
# worker_timeout 60 |
||||
|
||||
# Change the default worker timeout for booting |
||||
# |
||||
# If unspecified, this defaults to the value of worker_timeout. |
||||
# |
||||
# worker_boot_timeout 60 |
||||
|
||||
# === Puma control rack application === |
||||
|
||||
# Start the puma control rack application on "url". This application can |
||||
# be communicated with to control the main server. Additionally, you can |
||||
# provide an authentication token, so all requests to the control server |
||||
# will need to include that token as a query parameter. This allows for |
||||
# simple authentication. |
||||
# |
||||
# Check out https://github.com/puma/puma/blob/master/lib/puma/app/status.rb |
||||
# to see what the app has available. |
||||
# |
||||
# activate_control_app 'unix:///var/run/pumactl.sock' |
||||
# activate_control_app 'unix:///var/run/pumactl.sock', { auth_token: '12345' } |
||||
# activate_control_app 'unix:///var/run/pumactl.sock', { no_token: true } |
@ -0,0 +1,59 @@ |
||||
#-- 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 ByWorkPackageFilterDependencyRepresenter < |
||||
FilterDependencyRepresenter |
||||
|
||||
def json_cache_key |
||||
super + (filter.project.present? ? [filter.project.id] : []) |
||||
end |
||||
|
||||
def href_callback |
||||
if filter.project |
||||
api_v3_paths.work_packages_by_project(filter.project.id) |
||||
else |
||||
api_v3_paths.work_packages |
||||
end |
||||
end |
||||
|
||||
private |
||||
|
||||
def type |
||||
'[]WorkPackage' |
||||
end |
||||
end |
||||
end |
||||
end |
||||
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 ParentFilterDependencyRepresenter < ByWorkPackageFilterDependencyRepresenter; end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,133 @@ |
||||
#-- 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 ::API::V3::Queries::Schemas::ParentFilterDependencyRepresenter, clear_cache: true do |
||||
include ::API::V3::Utilities::PathHelper |
||||
|
||||
let(:project) { FactoryGirl.build_stubbed(:project) } |
||||
let(:query) { FactoryGirl.build_stubbed(:query, project: project) } |
||||
let(:filter) { Queries::WorkPackages::Filter::ParentFilter.create!(context: query) } |
||||
let(:form_embedded) { false } |
||||
|
||||
let(:instance) do |
||||
described_class.new(filter, |
||||
operator, |
||||
form_embedded: form_embedded) |
||||
end |
||||
|
||||
subject(:generated) { instance.to_json } |
||||
|
||||
context 'generation' do |
||||
context 'properties' do |
||||
describe 'values' do |
||||
context 'within project' do |
||||
let(:path) { 'values' } |
||||
let(:type) { '[]WorkPackage' } |
||||
let(:href) { api_v3_paths.work_packages_by_project(project.id) } |
||||
|
||||
context "for operator 'Queries::Operators::Equals'" do |
||||
let(:operator) { Queries::Operators::Equals } |
||||
|
||||
it_behaves_like 'filter dependency with allowed link' |
||||
end |
||||
|
||||
context "for operator 'Queries::Operators::NotEquals'" do |
||||
let(:operator) { Queries::Operators::NotEquals } |
||||
|
||||
it_behaves_like 'filter dependency with allowed link' |
||||
end |
||||
end |
||||
|
||||
context 'outside of a project' do |
||||
let(:project) { nil } |
||||
let(:path) { 'values' } |
||||
let(:type) { '[]WorkPackage' } |
||||
let(:href) { api_v3_paths.work_packages } |
||||
|
||||
context "for operator 'Queries::Operators::Equals'" do |
||||
let(:operator) { Queries::Operators::Equals } |
||||
|
||||
it_behaves_like 'filter dependency with allowed link' |
||||
end |
||||
|
||||
context "for operator 'Queries::Operators::NotEquals'" do |
||||
let(:operator) { Queries::Operators::NotEquals } |
||||
|
||||
it_behaves_like 'filter dependency with allowed link' |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe 'caching' do |
||||
let(:operator) { Queries::Operators::Equals } |
||||
let(:other_project) { FactoryGirl.build_stubbed(:project) } |
||||
|
||||
before do |
||||
# fill the cache |
||||
instance.to_json |
||||
end |
||||
|
||||
it 'is cached' do |
||||
expect(instance) |
||||
.not_to receive(:to_hash) |
||||
|
||||
instance.to_json |
||||
end |
||||
|
||||
it 'busts the cache on a different operator' do |
||||
instance.send(:operator=, Queries::Operators::NotEquals) |
||||
|
||||
expect(instance) |
||||
.to receive(:to_hash) |
||||
|
||||
instance.to_json |
||||
end |
||||
|
||||
it 'busts the cache on a different project' do |
||||
query.project = other_project |
||||
|
||||
expect(instance) |
||||
.to receive(:to_hash) |
||||
|
||||
instance.to_json |
||||
end |
||||
|
||||
it 'busts the cache on changes to the locale' do |
||||
expect(instance) |
||||
.to receive(:to_hash) |
||||
|
||||
I18n.with_locale(:de) do |
||||
instance.to_json |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,259 @@ |
||||
#-- 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. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe Queries::WorkPackages::Filter::ParentFilter, type: :model do |
||||
let(:project) { FactoryGirl.build_stubbed(:project) } |
||||
let(:query) do |
||||
FactoryGirl.build_stubbed(:query, project: project) |
||||
end |
||||
|
||||
it_behaves_like 'basic query filter' do |
||||
let(:class_key) { :parent } |
||||
let(:type) { :list } |
||||
|
||||
before do |
||||
instance.context = query |
||||
end |
||||
|
||||
describe '#available?' do |
||||
context 'within a project' do |
||||
it 'is true if any work package exists and is visible' do |
||||
allow(WorkPackage) |
||||
.to receive_message_chain(:visible, :for_projects, :exists?) |
||||
.with(no_args) |
||||
.with(project) |
||||
.with(no_args) |
||||
.and_return true |
||||
|
||||
expect(instance).to be_available |
||||
end |
||||
|
||||
it 'is false if no work package exists/ is visible' do |
||||
allow(WorkPackage) |
||||
.to receive_message_chain(:visible, :for_projects, :exists?) |
||||
.with(no_args) |
||||
.with(project) |
||||
.with(no_args) |
||||
.and_return false |
||||
|
||||
expect(instance).not_to be_available |
||||
end |
||||
end |
||||
|
||||
context 'outside of a project' do |
||||
let(:project) { nil } |
||||
|
||||
it 'is true if any work package exists and is visible' do |
||||
allow(WorkPackage) |
||||
.to receive_message_chain(:visible, :exists?) |
||||
.with(no_args) |
||||
.and_return true |
||||
|
||||
expect(instance).to be_available |
||||
end |
||||
|
||||
it 'is false if no work package exists/ is visible' do |
||||
allow(WorkPackage) |
||||
.to receive_message_chain(:visible, :exists?) |
||||
.with(no_args) |
||||
.and_return false |
||||
|
||||
expect(instance).not_to be_available |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe '#ar_object_filter?' do |
||||
it 'is true' do |
||||
expect(instance).to be_ar_object_filter |
||||
end |
||||
end |
||||
|
||||
describe '#allowed_values' do |
||||
it 'raises an error' do |
||||
expect { instance.allowed_values }.to raise_error NotImplementedError |
||||
end |
||||
end |
||||
|
||||
describe '#value_object' do |
||||
let(:visible_wp) { FactoryGirl.build_stubbed(:work_package) } |
||||
|
||||
it 'returns the work package for the values' do |
||||
allow(WorkPackage) |
||||
.to receive_message_chain(:visible, :for_projects, :find) |
||||
.with(no_args) |
||||
.with(project) |
||||
.with(instance.values) |
||||
.and_return([visible_wp]) |
||||
|
||||
expect(instance.value_objects) |
||||
.to match_array [visible_wp] |
||||
end |
||||
end |
||||
|
||||
describe '#allowed_objects' do |
||||
it 'raises an error' do |
||||
expect { instance.allowed_objects }.to raise_error NotImplementedError |
||||
end |
||||
end |
||||
|
||||
describe '#valid_values!' do |
||||
let(:visible_wp) { FactoryGirl.build_stubbed(:work_package) } |
||||
let(:invisible_wp) { FactoryGirl.build_stubbed(:work_package) } |
||||
|
||||
context 'within a project' do |
||||
it 'removes all non existing/non visible ids' do |
||||
instance.values = [visible_wp.id.to_s, invisible_wp.id.to_s, '999999'] |
||||
|
||||
allow(WorkPackage) |
||||
.to receive_message_chain(:visible, :for_projects, :where, :pluck) |
||||
.with(no_args) |
||||
.with(project) |
||||
.with(id: instance.values) |
||||
.with(:id) |
||||
.and_return([visible_wp.id]) |
||||
|
||||
instance.valid_values! |
||||
|
||||
expect(instance.values) |
||||
.to match_array [visible_wp.id.to_s] |
||||
end |
||||
end |
||||
|
||||
context 'outside of a project' do |
||||
let(:project) { nil } |
||||
|
||||
it 'removes all non existing/non visible ids' do |
||||
instance.values = [visible_wp.id.to_s, invisible_wp.id.to_s, '999999'] |
||||
|
||||
allow(WorkPackage) |
||||
.to receive_message_chain(:visible, :where, :pluck) |
||||
.with(no_args) |
||||
.with(id: instance.values) |
||||
.with(:id) |
||||
.and_return([visible_wp.id]) |
||||
|
||||
instance.valid_values! |
||||
|
||||
expect(instance.values) |
||||
.to match_array [visible_wp.id.to_s] |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe '#validate' do |
||||
let(:visible_wp) { FactoryGirl.build_stubbed(:work_package) } |
||||
let(:invisible_wp) { FactoryGirl.build_stubbed(:work_package) } |
||||
|
||||
context 'within a project' do |
||||
it 'is valid if only visible wps are values' do |
||||
instance.values = [visible_wp.id.to_s] |
||||
|
||||
allow(WorkPackage) |
||||
.to receive_message_chain(:visible, :for_projects, :where, :pluck) |
||||
.with(no_args) |
||||
.with(project) |
||||
.with(id: instance.values) |
||||
.with(:id) |
||||
.and_return([visible_wp.id]) |
||||
|
||||
expect(instance).to be_valid |
||||
end |
||||
|
||||
it 'is invalid if invisible wps are values' do |
||||
instance.values = [invisible_wp.id.to_s, visible_wp.id.to_s] |
||||
|
||||
allow(WorkPackage) |
||||
.to receive_message_chain(:visible, :for_projects, :where, :pluck) |
||||
.with(no_args) |
||||
.with(project) |
||||
.with(id: instance.values) |
||||
.with(:id) |
||||
.and_return([visible_wp.id]) |
||||
|
||||
expect(instance).not_to be_valid |
||||
end |
||||
end |
||||
|
||||
context 'outside of a project' do |
||||
let(:project) { nil } |
||||
|
||||
it 'is valid if only visible wps are values' do |
||||
instance.values = [visible_wp.id.to_s] |
||||
|
||||
allow(WorkPackage) |
||||
.to receive_message_chain(:visible, :where, :pluck) |
||||
.with(no_args) |
||||
.with(id: instance.values) |
||||
.with(:id) |
||||
.and_return([visible_wp.id]) |
||||
|
||||
expect(instance).to be_valid |
||||
end |
||||
|
||||
it 'is invalid if invisible wps are values' do |
||||
instance.values = [invisible_wp.id.to_s, visible_wp.id.to_s] |
||||
|
||||
allow(WorkPackage) |
||||
.to receive_message_chain(:visible, :where, :pluck) |
||||
.with(no_args) |
||||
.with(id: instance.values) |
||||
.with(:id) |
||||
.and_return([visible_wp.id]) |
||||
|
||||
expect(instance).not_to be_valid |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe '#where and #includes' do |
||||
let(:parent) { FactoryGirl.create(:work_package) } |
||||
let(:visible_wp) { FactoryGirl.create(:work_package, parent: parent) } |
||||
|
||||
before do |
||||
visible_wp |
||||
instance.values = [parent.id.to_s] |
||||
instance.operator = '=' |
||||
end |
||||
|
||||
it 'filters' do |
||||
scope = WorkPackage |
||||
.references(instance.includes) |
||||
.includes(instance.includes) |
||||
.where(instance.where) |
||||
|
||||
expect(scope) |
||||
.to match_array [visible_wp] |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue