OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
rework filters to changed phase structure
ulferts1b197c267298
diff --git a/app/components/projects/projects_filters_component.rb b/app/components/projects/projects_filters_component.rbindex 5be79dba483..e9e7993e15c 100644--- a/app/components/projects/projects_filters_component.rb+++ b/app/components/projects/projects_filters_component.rb@@ -51,9 +51,9 @@ class Projects::ProjectsFiltersComponent < Filter::FilterComponentQueries::Projects::Filters::FavoredFilter,Queries::Projects::Filters::IdFilter,Queries::Projects::Filters::LatestActivityAtFilter,- Queries::Projects::Filters::LifeCycleAnyFilter,- Queries::Projects::Filters::LifeCycleGateFilter,- Queries::Projects::Filters::LifeCycleStageFilter,+ Queries::Projects::Filters::ProjectPhaseAnyFilter,+ Queries::Projects::Filters::ProjectPhaseGateFilter,+ Queries::Projects::Filters::ProjectPhaseFilter,Queries::Projects::Filters::MemberOfFilter,Queries::Projects::Filters::NameAndIdentifierFilter,Queries::Projects::Filters::ProjectStatusFilter,diff --git a/app/models/queries/projects.rb b/app/models/queries/projects.rbindex 66fd6e1357f..44f7e2ccf6c 100644--- a/app/models/queries/projects.rb+++ b/app/models/queries/projects.rb@@ -37,9 +37,9 @@ module Queries::Projectsfilter Filters::FavoredFilterfilter Filters::IdFilterfilter Filters::LatestActivityAtFilter- filter Filters::LifeCycleAnyFilter- filter Filters::LifeCycleGateFilter- filter Filters::LifeCycleStageFilter+ filter Filters::ProjectPhaseAnyFilter+ filter Filters::ProjectPhaseGateFilter+ filter Filters::ProjectPhaseFilterfilter Filters::MemberOfFilterfilter Filters::NameAndIdentifierFilterfilter Filters::NameFilterdiff --git a/app/models/queries/projects/filters/dynamically_from_life_cycle.rb b/app/models/queries/projects/filters/dynamically_from_project_phase.rbsimilarity index 60%rename from app/models/queries/projects/filters/dynamically_from_life_cycle.rbrename to app/models/queries/projects/filters/dynamically_from_project_phase.rbindex 7c264742aa0..1b27413f406 100644--- a/app/models/queries/projects/filters/dynamically_from_life_cycle.rb+++ b/app/models/queries/projects/filters/dynamically_from_project_phase.rb@@ -28,66 +28,66 @@# See COPYRIGHT and LICENSE files for more details.# ++-module Queries::Projects::Filters::DynamicallyFromLifeCycle+module Queries::Projects::Filters::DynamicallyFromProjectPhaseextend ActiveSupport::Concernincluded do- def initialize(name, options = {})- @life_cycle_step_definition = options[:life_cycle_step_definition]-- super- end-private- attr_accessor :life_cycle_step_definition+ attr_accessor :project_phase_definitionendclass_methods dodef all_for(context = nil)- all_step_definitions- .map do |step|- create!(name: name_for_step(step), context:)+ all_phase_definitions+ .flat_map do |phase|+ create_from_phase(phase, context)rescue ::Queries::Filters::InvalidError- Rails.logger.error "Failed to map life cycle step definition filter for #{step.name} (CF##{step.id})."+ Rails.logger.error "Failed to map phase definition filter for #{phase.name} (CF##{phase.id})."nilendenddef create!(name:, **options)- life_cycle_step_definition = find_by_accessor(name)- raise ::Queries::Filters::InvalidError if life_cycle_step_definition.nil?+ project_phase_definition = find_by_accessor(name)+ raise ::Queries::Filters::InvalidError if project_phase_definition.nil?- new(name, options.merge(life_cycle_step_definition:))+ new(name, options.merge(project_phase_definition:))enddef keyraise NotImplementedErrorend- def all_step_definitions- key = %w[Queries::Projects::Filters::LifeCycleStepFilter all_step_definitions]+ private++ def all_phase_definitions+ key = %w[Queries::Projects::Filters::DynamicallyFromProjectPhase all_phase_definitions]- RequestStore- .fetch(key) { Project::PhaseDefinition.all.to_a }- .select { |lcsd| lcsd.is_a?(step_subclass) }+ RequestStore.fetch(key) { Project::PhaseDefinition.all.to_a }enddef find_by_accessor(name)match = name.match key- if match.present? && match[1].to_i > 0- all_step_definitions- .detect { |lcsd| lcsd.id == match[1].to_i }+ if match.present? && match[:id].to_i > 0+ all_phase_definitions+ .detect { |definition| accessor_matches?(definition, match) }endend- def name_for_step(_step)+ def create_from_phase(_phase, _context)raise NotImplementedErrorend- def step_subclass- raise NotImplementedError+ def accessor_matches?(definition, match)+ definition.id == match[:id].to_iendend++ def initialize(name, options = {})+ @project_phase_definition = options[:project_phase_definition]++ super+ endenddiff --git a/app/models/queries/projects/filters/filter_on_life_cycle.rb b/app/models/queries/projects/filters/filter_on_project_phase.rbsimilarity index 81%rename from app/models/queries/projects/filters/filter_on_life_cycle.rbrename to app/models/queries/projects/filters/filter_on_project_phase.rbindex 6165a97ba97..fd3e4819d51 100644--- a/app/models/queries/projects/filters/filter_on_life_cycle.rb+++ b/app/models/queries/projects/filters/filter_on_project_phase.rb@@ -28,7 +28,7 @@# See COPYRIGHT and LICENSE files for more details.# ++-module Queries::Projects::Filters::FilterOnLifeCycle+module Queries::Projects::Filters::FilterOnProjectPhaseextend ActiveSupport::Concerninclude Queries::Operators::DateRangeClauses@@ -94,24 +94,24 @@ module Queries::Projects::Filters::FilterOnLifeCycleraise NotImplementedErrorend- def life_cycle_scope_limit(scope)+ def project_phase_scope_limit(scope)scopeend- def stage_where_on(start_date, end_date = start_date)- life_cycle_scope(Project::Stage.name)+ def phase_where_on(start_date, end_date = start_date)+ project_phase_scope.where(date_range_clause(Project::Phase.table_name, "start_date", nil, start_date)).where(date_range_clause(Project::Phase.table_name, "end_date", end_date, nil))end- def stage_where_between(start_date, end_date)- life_cycle_scope(Project::Stage.name)+ def phase_where_between(start_date, end_date)+ project_phase_scope.where(date_range_clause(Project::Phase.table_name, "start_date", start_date, nil)).where(date_range_clause(Project::Phase.table_name, "end_date", nil, end_date))end- def stage_overlaps_this_week- life_cycle_scope(Project::Stage.name)+ def phase_overlaps_this_week+ project_phase_scope.where.not(start_date: nil).where.not(end_date: nil).where(@@ -125,24 +125,12 @@ module Queries::Projects::Filters::FilterOnLifeCycle)end- def stage_none- life_cycle_scope(Project::Stage.name)+ def phase_none+ project_phase_scope.where(start_date: nil).where(end_date: nil)end- def gate_none- life_cycle_scope(Project::Gate.name)- .where(start_date: nil)- .where(end_date: nil)- end-- def gate_where(start_date, end_date = start_date)- # On gates, only the start_date is set.- life_cycle_scope(Project::Gate.name)- .where(date_range_clause(Project::Phase.table_name, "start_date", start_date, end_date))- end-def parsed_startvalues.first.present? ? Date.parse(values.first) : nilend@@ -163,14 +151,13 @@ module Queries::Projects::Filters::FilterOnLifeCyclebeginning_of_week + 7.daysend- def life_cycle_scope(type)- life_cycle_scope = Project::Phase+ def project_phase_scope+ project_phase_scope = Project::Phase.where("#{Project::Phase.table_name}.project_id = #{Project.table_name}.id").where(project_id: Project.allowed_to(User.current, :view_project_phases))- .where(type:).active- life_cycle_scope_limit(life_cycle_scope)+ project_phase_scope_limit(project_phase_scope)enddelegate :connection, to: :"ActiveRecord::Base"diff --git a/app/models/queries/projects/filters/life_cycle_gate_filter.rb b/app/models/queries/projects/filters/life_cycle_gate_filter.rbdeleted file mode 100644index 4f925f6cccf..00000000000--- a/app/models/queries/projects/filters/life_cycle_gate_filter.rb+++ /dev/null@@ -1,81 +0,0 @@-# frozen_string_literal: true--# -- copyright-# OpenProject is an open source project management software.-# Copyright (C) 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::Projects::Filters::LifeCycleGateFilter < Queries::Projects::Filters::Base- include Queries::Projects::Filters::DynamicallyFromLifeCycle- include Queries::Projects::Filters::FilterOnLifeCycle-- class << self- def key- /\Alcsd_gate_(\d+)\z/- end-- private-- def name_for_step(gate)- "lcsd_gate_#{gate.id}"- end-- def step_subclass- Project::GateDefinition- end- end-- def human_name- I18n.t("project.filters.life_cycle_gate", gate: life_cycle_step_definition.name)- end-- private-- def on_date- gate_where(parsed_end)- end-- def on_today- gate_where(today, today)- end-- def between_date- gate_where(parsed_start, parsed_end)- end-- def this_week- gate_where(beginning_of_week.to_date, end_of_week.to_date)- end-- def none- gate_none- end-- def life_cycle_scope_limit(scope)- super- .where(definition_id: life_cycle_step_definition.id)- end-enddiff --git a/app/models/queries/projects/filters/life_cycle_any_filter.rb b/app/models/queries/projects/filters/project_phase_any_filter.rbsimilarity index 72%rename from app/models/queries/projects/filters/life_cycle_any_filter.rbrename to app/models/queries/projects/filters/project_phase_any_filter.rbindex 2e60e1619b9..0285d47b268 100644--- a/app/models/queries/projects/filters/life_cycle_any_filter.rb+++ b/app/models/queries/projects/filters/project_phase_any_filter.rb@@ -28,41 +28,36 @@# See COPYRIGHT and LICENSE files for more details.# ++-class Queries::Projects::Filters::LifeCycleAnyFilter < Queries::Projects::Filters::Base- include Queries::Projects::Filters::FilterOnLifeCycle+class Queries::Projects::Filters::ProjectPhaseAnyFilter < Queries::Projects::Filters::Base+ include Queries::Projects::Filters::FilterOnProjectPhaseinclude Queries::Operators::DateRangeClauses# Similar to other lifecycle stepsdef self.key- :lcsd_any+ :project_phase_anyenddef human_name- I18n.t("project.filters.life_cycle_any")+ I18n.t("project.filters.project_phase_any")enddef on_date- stage_where_on(parsed_start)- .or(gate_where(parsed_end))+ phase_where_on(parsed_start)enddef on_today- stage_where_on(today)- .or(gate_where(today, today))+ phase_where_on(today)enddef between_date- stage_where_between(parsed_start, parsed_end)- .or(gate_where(parsed_start, parsed_end))+ phase_where_between(parsed_start, parsed_end)enddef this_week- stage_overlaps_this_week- .or(gate_where(beginning_of_week.to_date, end_of_week.to_date))+ phase_overlaps_this_weekenddef none- stage_none- .or(gate_none)+ phase_noneendenddiff --git a/app/models/queries/projects/filters/life_cycle_stage_filter.rb b/app/models/queries/projects/filters/project_phase_filter.rbsimilarity index 67%rename from app/models/queries/projects/filters/life_cycle_stage_filter.rbrename to app/models/queries/projects/filters/project_phase_filter.rbindex 3b20f9e0cf6..13a5f3a8179 100644--- a/app/models/queries/projects/filters/life_cycle_stage_filter.rb+++ b/app/models/queries/projects/filters/project_phase_filter.rb@@ -28,54 +28,50 @@# See COPYRIGHT and LICENSE files for more details.# ++-class Queries::Projects::Filters::LifeCycleStageFilter < Queries::Projects::Filters::Base- include Queries::Projects::Filters::DynamicallyFromLifeCycle- include Queries::Projects::Filters::FilterOnLifeCycle+class Queries::Projects::Filters::ProjectPhaseFilter < Queries::Projects::Filters::Base+ include Queries::Projects::Filters::DynamicallyFromProjectPhase+ include Queries::Projects::Filters::FilterOnProjectPhaseclass << selfdef key- /\Alcsd_stage_(\d+)\z/+ /\Aproject_phase_(?<id>\d+)\z/endprivate- def name_for_step(stage)- "lcsd_stage_#{stage.id}"- end-- def step_subclass- Project::StageDefinition+ def create_from_phase(phase, context)+ create!(name: "project_phase_#{phase.id}", context:)endenddef human_name- I18n.t("project.filters.life_cycle_stage", stage: life_cycle_step_definition.name)+ I18n.t("project.filters.project_phase", phase: project_phase_definition.name)endprivatedef on_date- stage_where_on(parsed_start)+ phase_where_on(parsed_start)enddef on_today- stage_where_on(today)+ phase_where_on(today)enddef between_date- stage_where_between(parsed_start, parsed_end)+ phase_where_between(parsed_start, parsed_end)enddef this_week- stage_overlaps_this_week+ phase_overlaps_this_weekenddef none- stage_none+ phase_noneend- def life_cycle_scope_limit(scope)+ def project_phase_scope_limit(scope)super- .where(definition_id: life_cycle_step_definition.id)+ .where(definition_id: project_phase_definition.id)endenddiff --git a/app/models/queries/projects/filters/project_phase_gate_filter.rb b/app/models/queries/projects/filters/project_phase_gate_filter.rbnew file mode 100644index 00000000000..38d68d65581--- /dev/null+++ b/app/models/queries/projects/filters/project_phase_gate_filter.rb@@ -0,0 +1,117 @@+# frozen_string_literal: true++# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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::Projects::Filters::ProjectPhaseGateFilter < Queries::Projects::Filters::Base+ include Queries::Projects::Filters::DynamicallyFromProjectPhase+ include Queries::Projects::Filters::FilterOnProjectPhase++ class << self+ def key+ /\Aproject_(?<gate>end|start)_gate_(?<id>\d+)\z/+ end++ private++ def accessor_matches?(definition, match)+ super && match[:gate].in?(%w[start end]) &&+ ((match[:gate] == "start" && definition.start_gate) ||+ (match[:gate] == "end" && definition.end_gate))+ end++ def create_from_phase(phase, context)+ filters = []+ filters << create!(name: "project_start_gate_#{phase.id}", context:) if phase.start_gate+ filters << create!(name: "project_end_gate_#{phase.id}", context:) if phase.end_gate+ filters+ end+ end++ def initialize(name, options = {})+ @project_phase_gate = name.match(self.class.key)[:gate]++ super+ end++ def human_name+ gate_name = if project_phase_gate == "start"+ project_phase_definition.start_gate_name+ else+ project_phase_definition.end_gate_name+ end++ I18n.t("project.filters.project_phase_gate", gate: gate_name)+ end++ private++ attr_accessor :project_phase_gate++ def on_date+ gate_where(parsed_end)+ end++ def on_today+ gate_where(today, today)+ end++ def between_date+ gate_where(parsed_start, parsed_end)+ end++ def this_week+ gate_where(beginning_of_week.to_date, end_of_week.to_date)+ end++ def none+ project_phase_scope+ .where(column_name => nil)+ end++ def gate_where(start_date, end_date = start_date)+ project_phase_scope+ .where(date_range_clause(Project::Phase.table_name,+ column_name,+ start_date,+ end_date))+ end++ def project_phase_scope_limit(scope)+ super+ .joins(:definition)+ .where(project_phase_definitions: {+ id: project_phase_definition.id,+ "#{project_phase_gate}_gate" => true+ })+ end++ def column_name+ "#{project_phase_gate}_date"+ end+enddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 04d87f5bb09..bd75137d905 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -3508,9 +3508,9 @@ en:subprojects_confirmation: "Its subproject(s): %{value} will also be deleted."title: "Delete the project %{name}"filters:- life_cycle_any: "Lifecycle: Any stage or gate"- life_cycle_stage: "Lifecycle stage: %{stage}"- life_cycle_gate: "Lifecycle gate: %{gate}"+ project_phase: "Project phase: %{phase}"+ project_phase_any: "Project phase: Any"+ project_phase_gate: "Project phase gate: %{gate}"identifier:warning_one: Members of the project will have to relocate the project's repositories.warning_two: Existing links to the project will no longer work.diff --git a/spec/models/queries/projects/filters/life_cycle_gate_filter_spec.rb b/spec/models/queries/projects/filters/life_cycle_gate_filter_spec.rbdeleted file mode 100644index ba206ba3b85..00000000000--- a/spec/models/queries/projects/filters/life_cycle_gate_filter_spec.rb+++ /dev/null@@ -1,149 +0,0 @@-# frozen_string_literal: true--# -- copyright-# OpenProject is an open source project management software.-# Copyright (C) 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"--RSpec.describe Queries::Projects::Filters::LifeCycleGateFilter do- let(:gate) { build_stubbed(:project_phase_definition) }- # Defined here and in the .all to check that the filter only works on gates- let(:stage) { build_stubbed(:project_phase_definition) }- let(:query) { build_stubbed(:project_query) }-- let(:instance) do- described_class.create!(name: accessor, operator: "=", context: query)- end-- before do- allow(Project::PhaseDefinition)- .to receive(:all)- .and_return([stage, gate])- end-- describe ".create!" do- context "for an existing gate" do- it "returns a filter based on the gate" do- expect(described_class.create!(name: "lcsd_gate_#{gate.id}", context: query))- .to be_a described_class- end- end-- context "for a non existing gate" do- it "raise an error" do- expect { described_class.create!(name: "lcsd_gate_-1", context: query) }- .to raise_error Queries::Filters::InvalidError- end- end- end-- describe ".all_for" do- it "returns filters for all life cycle steps" do- expect(described_class.all_for)- .to all(be_a(described_class))-- expect(described_class.all_for.map(&:human_name))- .to contain_exactly(I18n.t("project.filters.life_cycle_gate", gate: gate.name))- end- end-- describe ".key" do- it "is a regex for matching lifecycle steps" do- expect(described_class.key)- .to eql(/\Alcsd_gate_(\d+)\z/)- end- end-- describe "human_name" do- let(:accessor) { "lcsd_gate_#{gate.id}" }-- it "is the name of the gate with a prefix" do- expect(instance.human_name)- .to eql I18n.t("project.filters.life_cycle_gate", gate: gate.name)- end- end-- describe "#available?" do- let(:project) { build_stubbed(:project) }- let(:accessor) { "lcsd_gate_#{gate.id}" }- let(:user) { build_stubbed(:user) }-- current_user { user }-- before do- mock_permissions_for(user) do |mock|- mock.allow_in_project(*permissions, project:)- end- end-- context "for a user with the necessary permission and the feature flag on", with_flag: { stages_and_gates: true } do- let(:permissions) { %i[view_project_phases] }-- it "is true" do- expect(instance)- .to be_available- end- end-- context "for a user with the necessary permission and the feature flag off", with_flag: { stages_and_gates: false } do- let(:permissions) { %i[view_project_phases] }-- it "is false" do- expect(instance)- .not_to be_available- end- end-- context "for a user without the necessary permission", with_flag: { stages_and_gates: true } do- let(:permissions) { %i[view_project] }-- it "is false" do- expect(instance)- .not_to be_available- end- end- end-- describe "#type" do- let(:accessor) { "lcsd_gate_#{gate.id}" }-- it "is :date" do- expect(instance.type)- .to be :date- end- end-- describe "#name" do- let(:accessor) { "lcsd_gate_#{gate.id}" }-- it "is the accessor" do- expect(instance.name)- .to eql accessor.to_sym- end- end-enddiff --git a/spec/models/queries/projects/filters/life_cycle_any_filter_spec.rb b/spec/models/queries/projects/filters/project_phase_any_filter_spec.rbsimilarity index 93%rename from spec/models/queries/projects/filters/life_cycle_any_filter_spec.rbrename to spec/models/queries/projects/filters/project_phase_any_filter_spec.rbindex 4df756f3e0c..67ae71503bc 100644--- a/spec/models/queries/projects/filters/life_cycle_any_filter_spec.rb+++ b/spec/models/queries/projects/filters/project_phase_any_filter_spec.rb@@ -30,12 +30,12 @@require "spec_helper"-RSpec.describe Queries::Projects::Filters::LifeCycleAnyFilter do+RSpec.describe Queries::Projects::Filters::ProjectPhaseAnyFilter doit_behaves_like "basic query filter" do- let(:class_key) { :lcsd_any }+ let(:class_key) { :project_phase_any }let(:type) { :date }let(:model) { Project }- let(:human_name) { I18n.t("project.filters.life_cycle_any") }+ let(:human_name) { I18n.t("project.filters.project_phase_any") }describe "default_operator" doit "is 'today'" dodiff --git a/spec/models/queries/projects/filters/life_cycle_stage_filter_spec.rb b/spec/models/queries/projects/filters/project_phase_filter_spec.rbsimilarity index 71%rename from spec/models/queries/projects/filters/life_cycle_stage_filter_spec.rbrename to spec/models/queries/projects/filters/project_phase_filter_spec.rbindex a903b0e1dc4..ac70fa2a378 100644--- a/spec/models/queries/projects/filters/life_cycle_stage_filter_spec.rb+++ b/spec/models/queries/projects/filters/project_phase_filter_spec.rb@@ -30,10 +30,10 @@require "spec_helper"-RSpec.describe Queries::Projects::Filters::LifeCycleStageFilter do- let(:stage) { build_stubbed(:project_phase_definition) }- # Defined here and in the .all to check that the filter only works on gates- let(:gate) { build_stubbed(:project_phase_definition) }+RSpec.describe Queries::Projects::Filters::ProjectPhaseFilter do+ let(:phase) { build_stubbed(:project_phase_definition) }+ let(:phase_with_end_gate) { build_stubbed(:project_phase_definition, end_gate: true) }+ let(:phase_with_start_gate) { build_stubbed(:project_phase_definition, start_gate: true) }let(:query) { build_stubbed(:project_query) }let(:instance) do@@ -43,20 +43,20 @@ RSpec.describe Queries::Projects::Filters::LifeCycleStageFilter dobefore doallow(Project::PhaseDefinition).to receive(:all)- .and_return([stage, gate])+ .and_return([phase, phase_with_end_gate, phase_with_start_gate])enddescribe ".create!" do- context "for an existing stage" do- it "returns a filter based on the stage" do- expect(described_class.create!(name: "lcsd_stage_#{stage.id}", context: query))+ context "for an existing phase" do+ it "returns a filter based on the phase" do+ expect(described_class.create!(name: "project_phase_#{phase.id}", context: query)).to be_a described_classendend- context "for a non existing stage" do+ context "for a non existing phase" doit "raise an error" do- expect { described_class.create!(name: "lcsd_stage_-1", context: query) }+ expect { described_class.create!(name: "project_phase_-1", context: query) }.to raise_error Queries::Filters::InvalidErrorendend@@ -68,29 +68,31 @@ RSpec.describe Queries::Projects::Filters::LifeCycleStageFilter do.to all(be_a(described_class))expect(described_class.all_for.map(&:human_name))- .to contain_exactly(I18n.t("project.filters.life_cycle_stage", stage: stage.name))+ .to contain_exactly(I18n.t("project.filters.project_phase", phase: phase.name),+ I18n.t("project.filters.project_phase", phase: phase_with_end_gate.name),+ I18n.t("project.filters.project_phase", phase: phase_with_start_gate.name))endenddescribe ".key" doit "is a regex for matching lifecycle steps" doexpect(described_class.key)- .to eql(/\Alcsd_stage_(\d+)\z/)+ .to eql(/\Aproject_phase_(?<id>\d+)\z/)endenddescribe "human_name" do- let(:accessor) { "lcsd_stage_#{stage.id}" }+ let(:accessor) { "project_phase_#{phase.id}" }- it "is the name of the stage with a prefix" do+ it "is the name of the phase with a prefix" doexpect(instance.human_name)- .to eql I18n.t("project.filters.life_cycle_stage", stage: stage.name)+ .to eql I18n.t("project.filters.project_phase", phase: phase.name)endenddescribe "#available?" dolet(:project) { build_stubbed(:project) }- let(:accessor) { "lcsd_stage_#{stage.id}" }+ let(:accessor) { "project_phase_#{phase.id}" }let(:user) { build_stubbed(:user) }current_user { user }@@ -130,7 +132,7 @@ RSpec.describe Queries::Projects::Filters::LifeCycleStageFilter doenddescribe "#type" do- let(:accessor) { "lcsd_stage_#{stage.id}" }+ let(:accessor) { "project_phase_#{phase.id}" }it "is :date" doexpect(instance.type)@@ -139,7 +141,7 @@ RSpec.describe Queries::Projects::Filters::LifeCycleStageFilter doenddescribe "#name" do- let(:accessor) { "lcsd_stage_#{stage.id}" }+ let(:accessor) { "project_phase_#{phase.id}" }it "is the accessor" doexpect(instance.name)diff --git a/spec/models/queries/projects/filters/project_phase_gate_filter_spec.rb b/spec/models/queries/projects/filters/project_phase_gate_filter_spec.rbnew file mode 100644index 00000000000..5d6e662bd64--- /dev/null+++ b/spec/models/queries/projects/filters/project_phase_gate_filter_spec.rb@@ -0,0 +1,209 @@+# frozen_string_literal: true++# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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"++RSpec.describe Queries::Projects::Filters::ProjectPhaseGateFilter do+ let(:phase) { build_stubbed(:project_phase_definition) }+ let(:phase_with_end_gate) do+ build_stubbed(:project_phase_definition,+ name: "End gated phase",+ end_gate: true,+ end_gate_name: "End gate")+ end+ let(:phase_with_start_gate) do+ build_stubbed(:project_phase_definition,+ name: "Start gated phase",+ start_gate: true,+ start_gate_name: "Start gate")+ end+ let(:phase_with_both_gates) do+ build_stubbed(:project_phase_definition,+ name: "Double gated phase",+ end_gate: true,+ end_gate_name: "End gate of two",+ start_gate: true,+ start_gate_name: "Start gate of two")+ end+ let(:query) { build_stubbed(:project_query) }++ let(:instance) do+ described_class.create!(name: accessor, operator: "=", context: query)+ end++ before do+ allow(Project::PhaseDefinition)+ .to receive(:all)+ .and_return([phase, phase_with_start_gate, phase_with_end_gate, phase_with_both_gates])+ end++ describe ".create!" do+ context "for an existing start gate" do+ it "returns a filter based on the gate" do+ expect(described_class.create!(name: "project_start_gate_#{phase_with_both_gates.id}", context: query))+ .to be_a described_class+ end+ end++ context "for an existing end gate" do+ it "returns a filter based on the gate" do+ expect(described_class.create!(name: "project_end_gate_#{phase_with_both_gates.id}", context: query))+ .to be_a described_class+ end+ end++ context "for an existing phase but without a start gate" do+ it "returns a filter based on the gate" do+ expect { described_class.create!(name: "project_start_gate_#{phase_with_end_gate.id}", context: query) }+ .to raise_error Queries::Filters::InvalidError+ end+ end++ context "for an existing phase but without an end gate" do+ it "returns a filter based on the gate" do+ expect { described_class.create!(name: "project_end_gate_#{phase_with_start_gate.id}", context: query) }+ .to raise_error Queries::Filters::InvalidError+ end+ end++ context "for a non existing start phase" do+ it "raise an error" do+ expect { described_class.create!(name: "project_start_gate_-1", context: query) }+ .to raise_error Queries::Filters::InvalidError+ end+ end++ context "for a non existing end phase" do+ it "raise an error" do+ expect { described_class.create!(name: "project_end_gate_-1", context: query) }+ .to raise_error Queries::Filters::InvalidError+ end+ end+ end++ describe ".all_for" do+ it "returns filters for all life cycle steps" do+ expect(described_class.all_for)+ .to all(be_a(described_class))++ expect(described_class.all_for.map(&:human_name))+ .to contain_exactly(I18n.t("project.filters.project_phase_gate", gate: phase_with_end_gate.end_gate_name),+ I18n.t("project.filters.project_phase_gate", gate: phase_with_start_gate.start_gate_name),+ I18n.t("project.filters.project_phase_gate", gate: phase_with_both_gates.start_gate_name),+ I18n.t("project.filters.project_phase_gate", gate: phase_with_both_gates.end_gate_name))+ end+ end++ describe ".key" do+ it "is a regex for matching lifecycle steps" do+ expect(described_class.key)+ .to eql(/\Aproject_(?<boundry>end|start)_gate_(?<id>\d+)\z/)+ end+ end++ describe "human_name" do+ context "for a start gate" do+ let(:accessor) { "project_start_gate_#{phase_with_both_gates.id}" }++ it "is the name of the gate with a prefix" do+ expect(instance.human_name)+ .to eql I18n.t("project.filters.project_phase_gate", gate: phase_with_both_gates.start_gate_name)+ end+ end++ context "for an end gate" do+ let(:accessor) { "project_end_gate_#{phase_with_both_gates.id}" }++ it "is the name of the gate with a prefix" do+ expect(instance.human_name)+ .to eql I18n.t("project.filters.project_phase_gate", gate: phase_with_both_gates.end_gate_name)+ end+ end+ end++ describe "#available?" do+ let(:project) { build_stubbed(:project) }+ let(:accessor) { "project_start_gate_#{phase_with_both_gates.id}" }+ let(:user) { build_stubbed(:user) }++ current_user { user }++ before do+ mock_permissions_for(user) do |mock|+ mock.allow_in_project(*permissions, project:)+ end+ end++ context "for a user with the necessary permission and the feature flag on", with_flag: { stages_and_gates: true } do+ let(:permissions) { %i[view_project_phases] }++ it "is true" do+ expect(instance)+ .to be_available+ end+ end++ context "for a user with the necessary permission and the feature flag off", with_flag: { stages_and_gates: false } do+ let(:permissions) { %i[view_project_phases] }++ it "is false" do+ expect(instance)+ .not_to be_available+ end+ end++ context "for a user without the necessary permission", with_flag: { stages_and_gates: true } do+ let(:permissions) { %i[view_project] }++ it "is false" do+ expect(instance)+ .not_to be_available+ end+ end+ end++ describe "#type" do+ let(:accessor) { "project_start_gate_#{phase_with_both_gates.id}" }++ it "is :date" do+ expect(instance.type)+ .to be :date+ end+ end++ describe "#name" do+ let(:accessor) { "project_start_gate_#{phase_with_both_gates.id}" }++ it "is the accessor" do+ expect(instance.name)+ .to eql accessor.to_sym+ end+ end+enddiff --git a/spec/models/queries/projects/project_query_results_life_cycle_any_spec.rb b/spec/models/queries/projects/project_query_results_life_cycle_any_spec.rbdeleted file mode 100644index b98f6d336b8..00000000000--- a/spec/models/queries/projects/project_query_results_life_cycle_any_spec.rb+++ /dev/null@@ -1,871 +0,0 @@-# frozen_string_literal: true--# -- copyright-# OpenProject is an open source project management software.-# Copyright (C) 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"--RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" do- let(:instance) { described_class.new }-- shared_let(:view_role) { create(:project_role, permissions: %i[view_project_phases]) }-- shared_let(:stage_start_date) { Date.parse("2025-02-07") }- shared_let(:stage_end_date) { Date.parse("2025-02-17") }- shared_let(:project_with_stage) { create(:project, name: "Project with stage") }- shared_let(:stage) do- create(:project_phase, project: project_with_stage, start_date: stage_start_date, end_date: stage_end_date)- end-- shared_let(:gate_date) { Date.parse("2025-03-06") }- shared_let(:project_with_gate) { create(:project, name: "Project with gate") }- shared_let(:gate) { create(:project_gate, project: project_with_gate, date: gate_date) }-- shared_let(:project_without_step) { create(:project, name: "Project without step") }-- shared_let(:user) do- create(:user, member_with_permissions: {- project_with_stage => %i[view_project_phases],- project_with_gate => %i[view_project_phases],- project_without_step => %i[view_project_phases]- })- end-- current_user { user }-- # rubocop:disable RSpec/ScatteredSetup- def self.remove_gate- before do- Project::Phase.where(type: Project::Gate.name).destroy_all- end- end-- def self.remove_stage- before do- Project::Phase.where(type: Project::Stage.name).destroy_all- end- end-- def self.disable_stage- before do- Project::Phase.where(type: Project::Stage.name).update_all(active: false)- end- end-- def self.disable_gate- before do- Project::Phase.where(type: Project::Gate.name).update_all(active: false)- end- end-- def self.remove_stage_dates- before do- stage.update_columns(end_date: nil, start_date: nil)- end- end-- def self.remove_gate_dates- before do- gate.update_columns(end_date: nil, start_date: nil)- end- end-- def self.remove_permissions- before do- # We keep the permission within the project without steps so that the filter itself is available- # but we check that the filter does not return values.- RolePermission- .where(role_id: Role.joins(:member_roles)- .where(member_roles: { member_id: Member.where(project: [project_with_stage,- project_with_gate]) }))- .where(permission: :view_project_phases)- .destroy_all- end- end- # rubocop:enable RSpec/ScatteredSetup-- context "with a =d (on) operator" do- before do- instance.where("lcsd_any", "=d", values)- end-- context "when filtering in the middle of the stage" do- let(:values) { [(stage_start_date + ((stage_end_date - stage_start_date) / 2)).to_s] }-- it "returns the project whose stage is covering an interval including the date" do- expect(instance.results).to contain_exactly(project_with_stage)- end- end-- context "when filtering on the first day of the stage" do- let(:values) { [stage_start_date.to_s] }-- it "returns the project whose stage begins on that date" do- expect(instance.results).to contain_exactly(project_with_stage)- end- end-- context "when filtering on the last day of the stage" do- let(:values) { [stage_end_date.to_s] }-- it "returns the project whose stage ends on that date" do- expect(instance.results).to contain_exactly(project_with_stage)- end- end-- context "when filtering before the stage" do- let(:values) { [(stage_start_date - 1.day).to_s] }-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when filtering after the stage" do- let(:values) { [(stage_end_date + 1.day).to_s] }-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when the stage has no dates" do- let(:values) { [stage_end_date.to_s] }-- remove_stage_dates-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when filtering on the day of the gate" do- let(:values) { [gate_date.to_s] }-- it "returns the project whose gate is on the date of the value" do- expect(instance.results).to contain_exactly(project_with_gate)- end- end-- context "when filtering before the gate" do- let(:values) { [(gate_date - 1.day).to_s] }-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when filtering after the gate" do- let(:values) { [(gate_date + 1.day).to_s] }-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when the gate has no dates" do- let(:values) { [gate_date.to_s] }-- remove_gate_dates-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when filtering in the middle of the stage but with the stage being inactive" do- let(:values) { [(stage_start_date + ((stage_end_date - stage_start_date) / 2)).to_s] }-- disable_stage-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when filtering on the day of the gate but with the gate being inactive" do- let(:values) { [gate_date.to_s] }-- disable_gate-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when filtering in the middle of the stage but without permissions" do- let(:values) { [(stage_start_date + ((stage_end_date - stage_start_date) / 2)).to_s] }-- remove_permissions-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when filtering on the day of the gate but without permissions" do- let(:values) { [gate_date.to_s] }-- remove_permissions-- it "returns no project" do- expect(instance.results).to be_empty- end- end- end-- context "with a t (today) operator" do- before do- instance.where("lcsd_any", "t", [])- end-- context "when being in the middle of the stage" do- it "returns the project whose stage is currently running" do- Timecop.travel((stage_start_date + (stage_end_date - stage_start_date)).noon) do- expect(instance.results).to contain_exactly(project_with_stage)- end- end- end-- context "when being on the first day of the stage" do- it "returns the project whose stage begins on that date" do- Timecop.travel(stage_start_date.noon) do- expect(instance.results).to contain_exactly(project_with_stage)- end- end- end-- context "when being on the last day of the stage" do- it "returns the project whose stage begins on that date" do- Timecop.travel(stage_end_date.noon) do- expect(instance.results).to contain_exactly(project_with_stage)- end- end- end-- context "when being before the stage" do- it "returns no project" do- Timecop.travel(stage_start_date.noon - 1.day) do- expect(instance.results).to be_empty- end- end- end-- context "when being after the stage" do- it "returns no project" do- Timecop.travel(stage_end_date.noon + 1.day) do- expect(instance.results).to be_empty- end- end- end-- context "when the stage has no dates" do- remove_stage_dates-- it "returns no project" do- Timecop.travel(stage_end_date.noon) do- expect(instance.results).to be_empty- end- end- end-- context "when being on the day of the gate" do- it "returns the project whose gate is on the date of the value" do- Timecop.travel(gate_date.noon) do- expect(instance.results).to contain_exactly(project_with_gate)- end- end- end-- context "when being before the day of the gate" do- it "returns no project" do- Timecop.travel(gate_date.noon - 1.day) do- expect(instance.results).to be_empty- end- end- end-- context "when being after the day of the gate" do- it "returns no project" do- Timecop.travel(gate_date.noon + 1.day) do- expect(instance.results).to be_empty- end- end- end-- context "when the gate has no dates" do- remove_gate_dates-- it "returns no project" do- Timecop.travel(gate_date.noon) do- expect(instance.results).to be_empty- end- end- end-- context "when being in the middle of the stage but with the stage being disabled" do- disable_stage-- it "returns no project" do- Timecop.travel((stage_start_date + (stage_end_date - stage_start_date)).noon) do- expect(instance.results).to be_empty- end- end- end-- context "when being on the day of the gate but with the gate being disabled" do- disable_gate-- it "returns no project" do- Timecop.travel(gate_date.noon) do- expect(instance.results).to be_empty- end- end- end-- context "when being in the middle of the stage but without permissions" do- remove_permissions-- it "returns no project" do- Timecop.travel((stage_start_date + (stage_end_date - stage_start_date)).noon) do- expect(instance.results).to be_empty- end- end- end-- context "when being on the day of the gate but without permissions" do- remove_permissions-- it "returns no project" do- Timecop.travel(gate_date.noon) do- expect(instance.results).to be_empty- end- end- end- end-- context "with a w (this week) operator" do- before do- instance.where("lcsd_any", "w", [])- end-- context "when being in the middle of the stage" do- it "returns the project whose stage is currently running" do- Timecop.travel((stage_start_date + 3.days).noon) do- expect(instance.results).to contain_exactly(project_with_stage)- end- end- end-- context "when the current week overlaps the beginning of the stage" do- it "returns the project whose stage begins within the week" do- Timecop.travel((stage_start_date - 1.day).noon) do- expect(instance.results).to contain_exactly(project_with_stage)- end- end- end-- context "when the current week overlaps the end of the stage" do- it "returns the project whose stage begins within the week" do- Timecop.travel(stage_end_date.noon) do- expect(instance.results).to contain_exactly(project_with_stage)- end- end- end-- context "when being before the stage" do- it "returns no project" do- Timecop.travel(stage_start_date.noon - 7.days) do- expect(instance.results).to be_empty- end- end- end-- context "when being after the stage" do- it "returns no project" do- Timecop.travel(stage_end_date.noon + 7.days) do- expect(instance.results).to be_empty- end- end- end-- context "when the stage has no dates" do- remove_stage_dates-- it "returns no project" do- Timecop.travel(stage_end_date.noon + 7.days) do- expect(instance.results).to be_empty- end- end- end-- context "when being a day before the gate" do- it "returns the project whose gate is within the current week" do- Timecop.travel(gate_date.noon - 1.day) do- expect(instance.results).to contain_exactly(project_with_gate)- end- end- end-- context "when being a day after the gate" do- it "returns the project whose gate is within the current week" do- Timecop.travel(gate_date.noon + 1.day) do- expect(instance.results).to contain_exactly(project_with_gate)- end- end- end-- context "when being in the week before the day of the gate" do- it "returns no project" do- Timecop.travel(gate_date.noon - 7.days) do- expect(instance.results).to be_empty- end- end- end-- context "when being in the week after the day of the gate" do- it "returns no project" do- Timecop.travel(gate_date.noon + 7.days) do- expect(instance.results).to be_empty- end- end- end-- context "when being in the middle of the stage but with the stage disabled" do- disable_stage-- it "returns no project" do- Timecop.travel((stage_start_date + 3.days).noon) do- expect(instance.results).to be_empty- end- end- end-- context "when being a day before the gate but with the gate disabled" do- disable_gate-- it "returns no project" do- Timecop.travel(gate_date.noon - 1.day) do- expect(instance.results).to be_empty- end- end- end-- context "when being in the middle of the stage but without permissions" do- remove_permissions-- it "returns no project" do- Timecop.travel((stage_start_date + 3.days).noon) do- expect(instance.results).to be_empty- end- end- end-- context "when being a day before the gate but without permissions" do- remove_permissions-- it "returns no project" do- Timecop.travel(gate_date.noon - 1.day) do- expect(instance.results).to be_empty- end- end- end-- context "when the gate has no dates" do- remove_gate_dates-- it "returns no project" do- Timecop.travel(gate_date.noon - 1.day) do- expect(instance.results).to be_empty- end- end- end-- context "when being on Monday, the stage ends on Sunday and the week is configured to start on Sunday",- with_settings: { start_of_week: 7 } do- before do- stage.update_column(:end_date, Date.parse("2025-02-16"))- end-- it "returns the project whose stage has ended within the current week" do- Timecop.travel(Date.parse("2025-02-17").noon) do- expect(instance.results).to contain_exactly(project_with_stage)- end- end- end-- context "when being on Monday, the stage ends on Sunday and the week is configured to start on Monday",- with_settings: { start_of_week: 1 } do- before do- stage.update_column(:end_date, Date.parse("2025-02-16"))- end-- it "returns no project as the stage ended in the week before" do- Timecop.travel(Date.parse("2025-02-17").noon) do- expect(instance.results).to be_empty- end- end- end-- context "when being on Monday, the gate is on Sunday and the week is configured to start on Sunday",- with_settings: { start_of_week: 7 } do- before do- gate.update_column(:start_date, Date.parse("2025-03-02"))- end-- it "returns the project whose gate is in the current week" do- Timecop.travel(Date.parse("2025-03-03").noon) do- expect(instance.results).to contain_exactly(project_with_gate)- end- end- end-- context "when being on Monday, the gate is on Sunday and the week is configured to start on Monday",- with_settings: { start_of_week: 1 } do- before do- gate.update_column(:start_date, Date.parse("2025-03-02"))- end-- it "returns no project as the stage ended in the week before" do- Timecop.travel(Date.parse("2025-03-03").noon) do- expect(instance.results).to be_empty- end- end- end-- context "when being on Sunday, the stage ends on Monday and the week is configured to start on Monday",- with_settings: { start_of_week: 1 } do- before do- stage.update_column(:end_date, Date.parse("2025-02-17"))- end-- it "returns the project whose stage has ended within the current week" do- Timecop.travel(Date.parse("2025-02-23").noon) do- expect(instance.results).to contain_exactly(project_with_stage)- end- end- end-- context "when being on Sunday, the stage ends on Monday and the week is configured to start on Sunday",- with_settings: { start_of_week: 7 } do- before do- stage.update_column(:end_date, Date.parse("2025-02-17"))- end-- it "returns no project as the stage ended in the week before" do- Timecop.travel(Date.parse("2025-02-23").noon) do- expect(instance.results).to be_empty- end- end- end-- context "when being on Sunday, the gate is on Monday and the week is configured to start on Monday",- with_settings: { start_of_week: 1 } do- before do- gate.update_column(:start_date, Date.parse("2025-03-03"))- end-- it "returns the project whose gate is in the current week" do- Timecop.travel(Date.parse("2025-03-09").noon) do- expect(instance.results).to contain_exactly(project_with_gate)- end- end- end-- context "when being on Sunday, the gate is on Monday and the week is configured to start on Sunday",- with_settings: { start_of_week: 7 } do- before do- gate.update_column(:start_date, Date.parse("2025-03-03"))- end-- it "returns no project as the stage ended in the week before" do- Timecop.travel(Date.parse("2025-03-09").noon) do- expect(instance.results).to be_empty- end- end- end- end-- context "with a <>d (between) operator" do- before do- instance.where("lcsd_any", "<>d", values)- end-- context "when encompassing the stage completely" do- let(:values) { [(stage_start_date - 1.day).to_s, (stage_end_date + 1.day).to_s] }-- it "returns the project with the stage" do- expect(instance.results).to contain_exactly(project_with_stage)- end- end-- context "when encompassing the stage precisely" do- let(:values) { [stage_start_date.to_s, stage_end_date.to_s] }-- it "returns the project with the stage" do- expect(instance.results).to contain_exactly(project_with_stage)- end- end-- context "when the values overlap the stage's start date but not the end date" do- let(:values) { [(stage_start_date - 1.day).to_s, (stage_end_date - 1.day).to_s] }-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when the values overlap the stage's end date but not the start date" do- let(:values) { [(stage_start_date + 1.day).to_s, stage_end_date.to_s] }-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when the values are between the start and the end date of the stage" do- let(:values) { [(stage_start_date + 1.day).to_s, (stage_end_date - 1.day).to_s] }-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when only the lower value is provided and that one is before the stage's start date" do- let(:values) { [(stage_start_date - 1.day).to_s, ""] }-- # Interferes at it would otherwise be found as well- remove_gate-- it "returns the project with the stage" do- expect(instance.results).to contain_exactly(project_with_stage)- end- end-- context "when only the lower value is provided and that one is on the stage's start date" do- let(:values) { [stage_start_date.to_s, ""] }-- # Interferes at it would otherwise be found as well- remove_gate-- it "returns the project with the stage" do- expect(instance.results).to contain_exactly(project_with_stage)- end- end-- context "when only the lower value is provided and that one after the stage's start date" do- let(:values) { [(stage_start_date + 1.day).to_s, ""] }-- # Interferes at it would otherwise be found as well- remove_gate-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when only the upper value is provided and that one is after the stage's end date" do- let(:values) { ["", (stage_end_date + 1.day).to_s] }-- it "returns the project with the stage" do- expect(instance.results).to contain_exactly(project_with_stage)- end- end-- context "when the stage has no dates" do- let(:values) { [(stage_start_date - 1.day).to_s, (stage_end_date + 1.day).to_s] }-- remove_stage_dates-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when no value is provided" do- let(:values) { ["", ""] }-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when encompassing the gate completely" do- let(:values) { [(gate_date - 1.day).to_s, (gate_date + 1.day).to_s] }-- it "returns the project with the gate" do- expect(instance.results).to contain_exactly(project_with_gate)- end- end-- context "when encompassing the gate precisely" do- let(:values) { [gate_date.to_s, gate_date.to_s] }-- it "returns the project with the gate" do- expect(instance.results).to contain_exactly(project_with_gate)- end- end-- context "when only the lower value is provided and that one is before the gate's date" do- let(:values) { [(gate_date - 1.day).to_s, ""] }-- it "returns the project with the gate" do- expect(instance.results).to contain_exactly(project_with_gate)- end- end-- context "when only the upper value is provided and that one is after the gate's date" do- let(:values) { ["", (gate_date + 1.day).to_s] }-- # Interferes at it would otherwise be found as well- remove_stage-- it "returns the project with the gate" do- expect(instance.results).to contain_exactly(project_with_gate)- end- end-- context "when only the upper value is provided and that one is on the gate's date" do- let(:values) { ["", gate_date.to_s] }-- # Interferes at it would otherwise be found as well- remove_stage-- it "returns the project with the gate" do- expect(instance.results).to contain_exactly(project_with_gate)- end- end-- context "when only the upper value is provided and that one is before the gate's date" do- let(:values) { ["", (gate_date - 1.day).to_s] }-- # Interferes at it would otherwise be found as well- remove_stage-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when the gate has no dates" do- let(:values) { [(gate_date - 1.day).to_s, (gate_date + 1.day).to_s] }-- remove_gate_dates-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when encompassing the stage completely but with the stage disabled" do- let(:values) { [(stage_start_date - 1.day).to_s, (stage_end_date + 1.day).to_s] }-- disable_stage-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when encompassing the gate precisely but with the gate disabled" do- let(:values) { [gate_date.to_s, gate_date.to_s] }-- disable_gate-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when encompassing the stage completely but without permissions" do- let(:values) { [(stage_start_date - 1.day).to_s, (stage_end_date + 1.day).to_s] }-- remove_permissions-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when encompassing the gate precisely but without permissions" do- let(:values) { [gate_date.to_s, gate_date.to_s] }-- remove_permissions-- it "returns no project" do- expect(instance.results).to be_empty- end- end- end-- context "with a !* (none) operator" do- before do- instance.where("lcsd_any", "!*", [])- end-- context "when the stage is active but has no dates" do- remove_stage_dates-- it "returns the project with the stage" do- expect(instance.results).to contain_exactly(project_with_stage)- end- end-- context "when the stage/gate is active and has dates" do- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when the stage is inactive and has no dates" do- remove_stage_dates- disable_stage-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when the gate is active but has no dates" do- remove_gate_dates-- it "returns the project with the gate" do- expect(instance.results).to contain_exactly(project_with_gate)- end- end-- context "when the gate is inactive and has no dates" do- remove_gate_dates- disable_gate-- it "returns no project" do- expect(instance.results).to be_empty- end- end- end-enddiff --git a/spec/models/queries/projects/project_query_results_life_cycle_gate_spec.rb b/spec/models/queries/projects/project_query_results_life_cycle_gate_spec.rbdeleted file mode 100644index b9e917db627..00000000000--- a/spec/models/queries/projects/project_query_results_life_cycle_gate_spec.rb+++ /dev/null@@ -1,446 +0,0 @@-# frozen_string_literal: true--# -- copyright-# OpenProject is an open source project management software.-# Copyright (C) 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"--RSpec.describe ProjectQuery, "results of a life cycle gate filter" do- let(:instance) { described_class.new }- let(:filter_key) { "lcsd_gate_#{gate.definition_id}" }-- shared_let(:view_role) { create(:project_role, permissions: %i[view_project_phases]) }-- shared_let(:stage_start_date) { Date.parse("2025-02-07") }- shared_let(:stage_end_date) { Date.parse("2025-02-17") }- shared_let(:project_with_stage) { create(:project, name: "Project with stage") }- shared_let(:stage) do- create(:project_phase, project: project_with_stage, start_date: stage_start_date, end_date: stage_end_date)- end-- shared_let(:gate_date) { Date.parse("2025-03-06") }- shared_let(:project_with_gate) { create(:project, name: "Project with gate") }- shared_let(:gate) { create(:project_gate, project: project_with_gate, date: gate_date) }-- # This is added to ensure that the filter only works on the gate provided.- shared_let(:project_with_rival_gate) { create(:project, name: "Project with rival gate") }- shared_let(:rival_gate) { create(:project_gate, project: project_with_rival_gate, date: gate_date) }-- shared_let(:project_without_step) { create(:project, name: "Project without step") }-- shared_let(:user) do- create(:user, member_with_permissions: {- project_with_stage => %i[view_project_phases],- project_with_gate => %i[view_project_phases],- project_with_rival_gate => %i[view_project_phases],- project_without_step => %i[view_project_phases]- })- end-- current_user { user }-- # rubocop:disable RSpec/ScatteredSetup- def self.disable_gate- before do- Project::Phase.where(type: Project::Gate.name).update_all(active: false)- end- end-- def self.remove_gate_dates- before do- gate.update_columns(end_date: nil, start_date: nil)- end- end-- def self.remove_permissions- before do- # We keep the permission within the project without steps so that the filter itself is available- # but we check that the filter does not return values.- RolePermission- .where(role_id: Role.joins(:member_roles)- .where(member_roles: { member_id: Member.where(project: [project_with_stage,- project_with_gate]) }))- .where(permission: :view_project_phases)- .destroy_all- end- end- # rubocop:enable RSpec/ScatteredSetup-- context "with a =d (on) operator" do- before do- instance.where(filter_key, "=d", values)- end-- context "when filtering on the day of the gate" do- let(:values) { [gate_date.to_s] }-- it "returns the project whose gate is on the date of the value" do- expect(instance.results).to contain_exactly(project_with_gate)- end- end-- context "when filtering before the gate" do- let(:values) { [(gate_date - 1.day).to_s] }-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when filtering after the gate" do- let(:values) { [(gate_date + 1.day).to_s] }-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when the gate has no dates" do- let(:values) { [gate_date.to_s] }-- remove_gate_dates-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when filtering on the day of the gate but with the gate being inactive" do- let(:values) { [gate_date.to_s] }-- disable_gate-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when filtering on the day of the gate but without permissions" do- let(:values) { [gate_date.to_s] }-- remove_permissions-- it "returns no project" do- expect(instance.results).to be_empty- end- end- end-- context "with a t (today) operator" do- before do- instance.where(filter_key, "t", [])- end-- context "when being on the day of the gate" do- it "returns the project whose gate is on the date of the value" do- Timecop.travel(gate_date.noon) do- expect(instance.results).to contain_exactly(project_with_gate)- end- end- end-- context "when being before the day of the gate" do- it "returns no project" do- Timecop.travel(gate_date.noon - 1.day) do- expect(instance.results).to be_empty- end- end- end-- context "when being after the day of the gate" do- it "returns no project" do- Timecop.travel(gate_date.noon + 1.day) do- expect(instance.results).to be_empty- end- end- end-- context "when the gate has no dates" do- remove_gate_dates-- it "returns no project" do- Timecop.travel(gate_date.noon) do- expect(instance.results).to be_empty- end- end- end-- context "when being on the day of the gate but with the gate being disabled" do- disable_gate-- it "returns no project" do- Timecop.travel(gate_date.noon) do- expect(instance.results).to be_empty- end- end- end-- context "when being on the day of the gate but without permissions" do- remove_permissions-- it "returns no project" do- Timecop.travel(gate_date.noon) do- expect(instance.results).to be_empty- end- end- end- end-- context "with a w (this week) operator" do- before do- instance.where(filter_key, "w", [])- end-- context "when being a day before the gate" do- it "returns the project whose gate is within the current week" do- Timecop.travel(gate_date.noon - 1.day) do- expect(instance.results).to contain_exactly(project_with_gate)- end- end- end-- context "when being a day after the gate" do- it "returns the project whose gate is within the current week" do- Timecop.travel(gate_date.noon + 1.day) do- expect(instance.results).to contain_exactly(project_with_gate)- end- end- end-- context "when being in the week before the day of the gate" do- it "returns no project" do- Timecop.travel(gate_date.noon - 7.days) do- expect(instance.results).to be_empty- end- end- end-- context "when being in the week after the day of the gate" do- it "returns no project" do- Timecop.travel(gate_date.noon + 7.days) do- expect(instance.results).to be_empty- end- end- end-- context "when being a day before the gate but with the gate disabled" do- disable_gate-- it "returns no project" do- Timecop.travel(gate_date.noon - 1.day) do- expect(instance.results).to be_empty- end- end- end-- context "when being a day before the gate but without permissions" do- remove_permissions-- it "returns no project" do- Timecop.travel(gate_date.noon - 1.day) do- expect(instance.results).to be_empty- end- end- end-- context "when the gate has no dates" do- remove_gate_dates-- it "returns no project" do- Timecop.travel(gate_date.noon - 1.day) do- expect(instance.results).to be_empty- end- end- end-- context "when being on Monday, the gate is on Sunday and the week is configured to start on Sunday",- with_settings: { start_of_week: 7 } do- before do- gate.update_column(:start_date, Date.parse("2025-03-02"))- end-- it "returns the project whose gate is in the current week" do- Timecop.travel(Date.parse("2025-03-03").noon) do- expect(instance.results).to contain_exactly(project_with_gate)- end- end- end-- context "when being on Monday, the gate is on Sunday and the week is configured to start on Monday",- with_settings: { start_of_week: 1 } do- before do- gate.update_column(:start_date, Date.parse("2025-03-02"))- end-- it "returns no project as the stage ended in the week before" do- Timecop.travel(Date.parse("2025-03-03").noon) do- expect(instance.results).to be_empty- end- end- end-- context "when being on Sunday, the gate is on Monday and the week is configured to start on Monday",- with_settings: { start_of_week: 1 } do- before do- gate.update_column(:start_date, Date.parse("2025-03-03"))- end-- it "returns the project whose gate is in the current week" do- Timecop.travel(Date.parse("2025-03-09").noon) do- expect(instance.results).to contain_exactly(project_with_gate)- end- end- end-- context "when being on Sunday, the gate is on Monday and the week is configured to start on Sunday",- with_settings: { start_of_week: 7 } do- before do- gate.update_column(:start_date, Date.parse("2025-03-03"))- end-- it "returns no project as the stage ended in the week before" do- Timecop.travel(Date.parse("2025-03-09").noon) do- expect(instance.results).to be_empty- end- end- end- end-- context "with a <>d (between) operator" do- before do- instance.where(filter_key, "<>d", values)- end-- context "when encompassing the gate completely" do- let(:values) { [(gate_date - 1.day).to_s, (gate_date + 1.day).to_s] }-- it "returns the project with the gate" do- expect(instance.results).to contain_exactly(project_with_gate)- end- end-- context "when encompassing the gate precisely" do- let(:values) { [gate_date.to_s, gate_date.to_s] }-- it "returns the project with the gate" do- expect(instance.results).to contain_exactly(project_with_gate)- end- end-- context "when only the lower value is provided and that one is before the gate's date" do- let(:values) { [(gate_date - 1.day).to_s, ""] }-- it "returns the project with the gate" do- expect(instance.results).to contain_exactly(project_with_gate)- end- end-- context "when only the upper value is provided and that one is after the gate's date" do- let(:values) { ["", (gate_date + 1.day).to_s] }-- it "returns the project with the gate" do- expect(instance.results).to contain_exactly(project_with_gate)- end- end-- context "when only the upper value is provided and that one is on the gate's date" do- let(:values) { ["", gate_date.to_s] }-- it "returns the project with the gate" do- expect(instance.results).to contain_exactly(project_with_gate)- end- end-- context "when only the upper value is provided and that one is before the gate's date" do- let(:values) { ["", (gate_date - 1.day).to_s] }-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when the gate has no dates" do- let(:values) { [(gate_date - 1.day).to_s, (gate_date + 1.day).to_s] }-- remove_gate_dates-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when encompassing the gate precisely but with the gate disabled" do- let(:values) { [gate_date.to_s, gate_date.to_s] }-- disable_gate-- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when encompassing the gate precisely but without permissions" do- let(:values) { [gate_date.to_s, gate_date.to_s] }-- remove_permissions-- it "returns no project" do- expect(instance.results).to be_empty- end- end- end-- context "with a !* (none) operator" do- before do- instance.where(filter_key, "!*", [])- end-- context "when the gate is active but has no dates" do- remove_gate_dates-- it "returns the project with the gate" do- expect(instance.results).to contain_exactly(project_with_gate)- end- end-- context "when the gate is active and has dates" do- it "returns no project" do- expect(instance.results).to be_empty- end- end-- context "when the gate is inactive and has no dates" do- remove_gate_dates- disable_gate-- it "returns no project" do- expect(instance.results).to be_empty- end- end- end-enddiff --git a/spec/models/queries/projects/project_query_results_project_phase_any_spec.rb b/spec/models/queries/projects/project_query_results_project_phase_any_spec.rbnew file mode 100644index 00000000000..bdd8705de12--- /dev/null+++ b/spec/models/queries/projects/project_query_results_project_phase_any_spec.rb@@ -0,0 +1,512 @@+# frozen_string_literal: true++# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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"++RSpec.describe ProjectQuery, "results of 'Project phase: Any' filter" do+ let(:instance) { described_class.new }++ shared_let(:view_role) { create(:project_role, permissions: %i[view_project_phases]) }++ shared_let(:phase_start_date) { Date.parse("2025-02-07") }+ shared_let(:phase_end_date) { Date.parse("2025-02-17") }+ shared_let(:project_with_phase) { create(:project, name: "Project with phase") }+ shared_let(:phase) do+ create(:project_phase, project: project_with_phase, start_date: phase_start_date, end_date: phase_end_date)+ end++ shared_let(:project_without_phase) { create(:project, name: "Project without phase") }++ shared_let(:user) do+ create(:user, member_with_permissions: {+ project_with_phase => %i[view_project_phases],+ project_without_phase => %i[view_project_phases]+ })+ end++ current_user { user }++ # rubocop:disable RSpec/ScatteredSetup+ def self.remove_phase+ before do+ Project::Phase.destroy_all+ end+ end++ def self.disable_phase+ before do+ Project::Phase.update_all(active: false)+ end+ end++ def self.remove_phase_dates+ before do+ phase.update_columns(end_date: nil, start_date: nil)+ end+ end++ def self.remove_permissions+ before do+ # We keep the permission within the Project without phases so that the filter itself is available+ # but we check that the filter does not return values.+ RolePermission+ .where(role_id: Role.joins(:member_roles)+ .where(member_roles: { member_id: Member.where(project: [project_with_phase]) }))+ .where(permission: :view_project_phases)+ .destroy_all+ end+ end+ # rubocop:enable RSpec/ScatteredSetup++ context "with a =d (on) operator" do+ before do+ instance.where("project_phase_any", "=d", values)+ end++ context "when filtering in the middle of the phase" do+ let(:values) { [(phase_start_date + ((phase_end_date - phase_start_date) / 2)).to_s] }++ it "returns the project whose phase is covering an interval including the date" do+ expect(instance.results).to contain_exactly(project_with_phase)+ end+ end++ context "when filtering on the first day of the phase" do+ let(:values) { [phase_start_date.to_s] }++ it "returns the project whose phase begins on that date" do+ expect(instance.results).to contain_exactly(project_with_phase)+ end+ end++ context "when filtering on the last day of the phase" do+ let(:values) { [phase_end_date.to_s] }++ it "returns the project whose phase ends on that date" do+ expect(instance.results).to contain_exactly(project_with_phase)+ end+ end++ context "when filtering before the phase" do+ let(:values) { [(phase_start_date - 1.day).to_s] }++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end++ context "when filtering after the phase" do+ let(:values) { [(phase_end_date + 1.day).to_s] }++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end++ context "when the phase has no dates" do+ let(:values) { [phase_end_date.to_s] }++ remove_phase_dates++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end++ context "when filtering in the middle of the phase but with the phase being inactive" do+ let(:values) { [(phase_start_date + ((phase_end_date - phase_start_date) / 2)).to_s] }++ disable_phase++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end++ context "when filtering in the middle of the phase but without permissions" do+ let(:values) { [(phase_start_date + ((phase_end_date - phase_start_date) / 2)).to_s] }++ remove_permissions++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end+ end++ context "with a t (today) operator" do+ before do+ instance.where("project_phase_any", "t", [])+ end++ context "when being in the middle of the phase" do+ it "returns the project whose phase is currently running" do+ Timecop.travel((phase_start_date + (phase_end_date - phase_start_date)).noon) do+ expect(instance.results).to contain_exactly(project_with_phase)+ end+ end+ end++ context "when being on the first day of the phase" do+ it "returns the project whose phase begins on that date" do+ Timecop.travel(phase_start_date.noon) do+ expect(instance.results).to contain_exactly(project_with_phase)+ end+ end+ end++ context "when being on the last day of the phase" do+ it "returns the project whose phase begins on that date" do+ Timecop.travel(phase_end_date.noon) do+ expect(instance.results).to contain_exactly(project_with_phase)+ end+ end+ end++ context "when being before the phase" do+ it "returns no project" do+ Timecop.travel(phase_start_date.noon - 1.day) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when being after the phase" do+ it "returns no project" do+ Timecop.travel(phase_end_date.noon + 1.day) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when the phase has no dates" do+ remove_phase_dates++ it "returns no project" do+ Timecop.travel(phase_end_date.noon) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when being in the middle of the phase but with the phase being disabled" do+ disable_phase++ it "returns no project" do+ Timecop.travel((phase_start_date + (phase_end_date - phase_start_date)).noon) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when being in the middle of the phase but without permissions" do+ remove_permissions++ it "returns no project" do+ Timecop.travel((phase_start_date + (phase_end_date - phase_start_date)).noon) do+ expect(instance.results).to be_empty+ end+ end+ end+ end++ context "with a w (this week) operator" do+ before do+ instance.where("project_phase_any", "w", [])+ end++ context "when being in the middle of the phase" do+ it "returns the project whose phase is currently running" do+ Timecop.travel((phase_start_date + 3.days).noon) do+ expect(instance.results).to contain_exactly(project_with_phase)+ end+ end+ end++ context "when the current week overlaps the beginning of the phase" do+ it "returns the project whose phase begins within the week" do+ Timecop.travel((phase_start_date - 1.day).noon) do+ expect(instance.results).to contain_exactly(project_with_phase)+ end+ end+ end++ context "when the current week overlaps the end of the phase" do+ it "returns the project whose phase begins within the week" do+ Timecop.travel(phase_end_date.noon) do+ expect(instance.results).to contain_exactly(project_with_phase)+ end+ end+ end++ context "when being before the phase" do+ it "returns no project" do+ Timecop.travel(phase_start_date.noon - 7.days) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when being after the phase" do+ it "returns no project" do+ Timecop.travel(phase_end_date.noon + 7.days) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when the phase has no dates" do+ remove_phase_dates++ it "returns no project" do+ Timecop.travel(phase_end_date.noon + 7.days) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when being in the middle of the phase but with the phase disabled" do+ disable_phase++ it "returns no project" do+ Timecop.travel((phase_start_date + 3.days).noon) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when being in the middle of the phase but without permissions" do+ remove_permissions++ it "returns no project" do+ Timecop.travel((phase_start_date + 3.days).noon) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when being on Monday, the phase ends on Sunday and the week is configured to start on Sunday",+ with_settings: { start_of_week: 7 } do+ before do+ phase.update_column(:end_date, Date.parse("2025-02-16"))+ end++ it "returns the project whose phase has ended within the current week" do+ Timecop.travel(Date.parse("2025-02-17").noon) do+ expect(instance.results).to contain_exactly(project_with_phase)+ end+ end+ end++ context "when being on Monday, the phase ends on Sunday and the week is configured to start on Monday",+ with_settings: { start_of_week: 1 } do+ before do+ phase.update_column(:end_date, Date.parse("2025-02-16"))+ end++ it "returns no project as the phase ended in the week before" do+ Timecop.travel(Date.parse("2025-02-17").noon) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when being on Sunday, the phase ends on Monday and the week is configured to start on Monday",+ with_settings: { start_of_week: 1 } do+ before do+ phase.update_column(:end_date, Date.parse("2025-02-17"))+ end++ it "returns the project whose phase has ended within the current week" do+ Timecop.travel(Date.parse("2025-02-23").noon) do+ expect(instance.results).to contain_exactly(project_with_phase)+ end+ end+ end++ context "when being on Sunday, the phase ends on Monday and the week is configured to start on Sunday",+ with_settings: { start_of_week: 7 } do+ before do+ phase.update_column(:end_date, Date.parse("2025-02-17"))+ end++ it "returns no project as the phase ended in the week before" do+ Timecop.travel(Date.parse("2025-02-23").noon) do+ expect(instance.results).to be_empty+ end+ end+ end+ end++ context "with a <>d (between) operator" do+ before do+ instance.where("project_phase_any", "<>d", values)+ end++ context "when encompassing the phase completely" do+ let(:values) { [(phase_start_date - 1.day).to_s, (phase_end_date + 1.day).to_s] }++ it "returns the project with the phase" do+ expect(instance.results).to contain_exactly(project_with_phase)+ end+ end++ context "when encompassing the phase precisely" do+ let(:values) { [phase_start_date.to_s, phase_end_date.to_s] }++ it "returns the project with the phase" do+ expect(instance.results).to contain_exactly(project_with_phase)+ end+ end++ context "when the values overlap the phase's start date but not the end date" do+ let(:values) { [(phase_start_date - 1.day).to_s, (phase_end_date - 1.day).to_s] }++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end++ context "when the values overlap the phase's end date but not the start date" do+ let(:values) { [(phase_start_date + 1.day).to_s, phase_end_date.to_s] }++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end++ context "when the values are between the start and the end date of the phase" do+ let(:values) { [(phase_start_date + 1.day).to_s, (phase_end_date - 1.day).to_s] }++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end++ context "when only the lower value is provided and that one is before the phase's start date" do+ let(:values) { [(phase_start_date - 1.day).to_s, ""] }++ it "returns the project with the phase" do+ expect(instance.results).to contain_exactly(project_with_phase)+ end+ end++ context "when only the lower value is provided and that one is on the phase's start date" do+ let(:values) { [phase_start_date.to_s, ""] }++ it "returns the project with the phase" do+ expect(instance.results).to contain_exactly(project_with_phase)+ end+ end++ context "when only the lower value is provided and that one after the phase's start date" do+ let(:values) { [(phase_start_date + 1.day).to_s, ""] }++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end++ context "when only the upper value is provided and that one is after the phase's end date" do+ let(:values) { ["", (phase_end_date + 1.day).to_s] }++ it "returns the project with the phase" do+ expect(instance.results).to contain_exactly(project_with_phase)+ end+ end++ context "when the phase has no dates" do+ let(:values) { [(phase_start_date - 1.day).to_s, (phase_end_date + 1.day).to_s] }++ remove_phase_dates++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end++ context "when no value is provided" do+ let(:values) { ["", ""] }++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end++ context "when encompassing the phase completely but with the phase disabled" do+ let(:values) { [(phase_start_date - 1.day).to_s, (phase_end_date + 1.day).to_s] }++ disable_phase++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end++ context "when encompassing the phase completely but without permissions" do+ let(:values) { [(phase_start_date - 1.day).to_s, (phase_end_date + 1.day).to_s] }++ remove_permissions++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end+ end++ context "with a !* (none) operator" do+ before do+ instance.where("project_phase_any", "!*", [])+ end++ context "when the phase is active but has no dates" do+ remove_phase_dates++ it "returns the project with the phase" do+ expect(instance.results).to contain_exactly(project_with_phase)+ end+ end++ context "when the phase is active and has dates" do+ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end++ context "when the phase is inactive and has no dates" do+ remove_phase_dates+ disable_phase++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end+ end+enddiff --git a/spec/models/queries/projects/project_query_results_project_phase_gate_spec.rb b/spec/models/queries/projects/project_query_results_project_phase_gate_spec.rbnew file mode 100644index 00000000000..b5d7e39a230--- /dev/null+++ b/spec/models/queries/projects/project_query_results_project_phase_gate_spec.rb@@ -0,0 +1,477 @@+# frozen_string_literal: true++# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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"++RSpec.describe ProjectQuery, "results of a project phase gate filter" do+ let(:instance) { described_class.new }++ shared_let(:view_role) { create(:project_role, permissions: %i[view_project_phases]) }++ shared_let(:gate_definition) { create(:project_phase_definition, start_gate: true, end_gate: true) }+ shared_let(:start_gate_date) { Date.parse("2025-03-04") }+ shared_let(:end_gate_date) { Date.parse("2025-03-07") }+ shared_let(:project_with_gate) { create(:project, name: "Project with gate") }+ shared_let(:gate) do+ create(:project_phase,+ project: project_with_gate,+ start_date: start_gate_date,+ end_date: end_gate_date,+ definition: gate_definition)+ end++ # This is added to ensure that the filter only works on the gate provided.+ shared_let(:rival_gate_definition) { create(:project_phase_definition, start_gate: true) }+ shared_let(:project_with_rival_gate) { create(:project, name: "Project with rival gate") }+ shared_let(:rival_gate) do+ create(:project_phase,+ project: project_with_rival_gate,+ start_date: start_gate_date,+ end_date: end_gate_date,+ definition: rival_gate_definition)+ end++ shared_let(:project_without_phase) { create(:project, name: "Project without phase") }++ shared_let(:user) do+ create(:user, member_with_permissions: {+ project_with_gate => %i[view_project_phases],+ project_with_rival_gate => %i[view_project_phases],+ project_without_phase => %i[view_project_phases]+ })+ end++ current_user { user }++ # rubocop:disable RSpec/ScatteredSetup+ def self.disable_gate+ before do+ Project::Phase.update_all(active: false)+ end+ end++ def self.remove_gate_date+ before do+ gate.update_columns("#{boundary}_date": nil)+ end+ end++ def self.remove_permissions+ before do+ # We keep the permission within the Project without phases so that the filter itself is available,+ # but we check that the filter does not return values.+ RolePermission+ .where(role_id: Role.joins(:member_roles)+ .where(member_roles: { member_id: Member.where(project: [project_with_gate]) }))+ .where(permission: :view_project_phases)+ .destroy_all+ end+ end+ # rubocop:enable RSpec/ScatteredSetup++ shared_examples_for "a project phase gate filter" do+ let(:filter_key) { "project_#{boundary}_gate_#{gate.definition_id}" }++ context "with a =d (on) operator" do+ before do+ instance.where(filter_key, "=d", values)+ end++ context "when filtering on the day of the gate" do+ let(:values) { [filter_reference_date.to_s] }++ it "returns the project whose gate is on the date of the value" do+ expect(instance.results).to contain_exactly(project_with_gate)+ end+ end++ context "when filtering before the gate" do+ let(:values) { [(filter_reference_date - 1.day).to_s] }++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end++ context "when filtering after the gate" do+ let(:values) { [(filter_reference_date + 1.day).to_s] }++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end++ context "when the gate has no dates" do+ let(:values) { [filter_reference_date.to_s] }++ remove_gate_date++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end++ context "when filtering on the day of the gate but with the gate being inactive" do+ let(:values) { [filter_reference_date.to_s] }++ disable_gate++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end++ context "when filtering on the day of the gate but without permissions" do+ let(:values) { [filter_reference_date.to_s] }++ remove_permissions++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end+ end++ context "with a t (today) operator" do+ before do+ instance.where(filter_key, "t", [])+ end++ context "when being on the day of the gate" do+ it "returns the project whose gate is on the date of the value" do+ Timecop.travel(filter_reference_date.noon) do+ expect(instance.results).to contain_exactly(project_with_gate)+ end+ end+ end++ context "when being before the day of the gate" do+ it "returns no project" do+ Timecop.travel(filter_reference_date.noon - 1.day) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when being after the day of the gate" do+ it "returns no project" do+ Timecop.travel(filter_reference_date.noon + 1.day) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when the gate has no dates" do+ remove_gate_date++ it "returns no project" do+ Timecop.travel(filter_reference_date.noon) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when being on the day of the gate but with the gate being disabled" do+ disable_gate++ it "returns no project" do+ Timecop.travel(filter_reference_date.noon) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when being on the day of the gate but without permissions" do+ remove_permissions++ it "returns no project" do+ Timecop.travel(filter_reference_date.noon) do+ expect(instance.results).to be_empty+ end+ end+ end+ end++ context "with a w (this week) operator" do+ before do+ instance.where(filter_key, "w", [])+ end++ context "when being a day before the gate" do+ it "returns the project whose gate is within the current week" do+ Timecop.travel(filter_reference_date.noon - 1.day) do+ expect(instance.results).to contain_exactly(project_with_gate)+ end+ end+ end++ context "when being a day after the gate" do+ it "returns the project whose gate is within the current week" do+ Timecop.travel(filter_reference_date.noon + 1.day) do+ expect(instance.results).to contain_exactly(project_with_gate)+ end+ end+ end++ context "when being in the week before the day of the gate" do+ it "returns no project" do+ Timecop.travel(filter_reference_date.noon - 7.days) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when being in the week after the day of the gate" do+ it "returns no project" do+ Timecop.travel(filter_reference_date.noon + 7.days) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when being a day before the gate but with the gate disabled" do+ disable_gate++ it "returns no project" do+ Timecop.travel(filter_reference_date.noon - 1.day) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when being a day before the gate but without permissions" do+ remove_permissions++ it "returns no project" do+ Timecop.travel(filter_reference_date.noon - 1.day) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when being a day before the gate but without the gate having dates" do+ remove_gate_date++ it "returns no project" do+ Timecop.travel(filter_reference_date.noon - 1.day) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when being on Monday, the gate is on Sunday and the week is configured to start on Sunday",+ with_settings: { start_of_week: 7 } do+ before do+ # This might produce invalid phases where the start date is after the end date.+ # For the sake of the test, this is irrelevant.+ gate.update_column(:"#{boundary}_date", Date.parse("2025-03-02"))+ end++ it "returns the project whose gate is in the current week" do+ Timecop.travel(Date.parse("2025-03-03").noon) do+ expect(instance.results).to contain_exactly(project_with_gate)+ end+ end+ end++ context "when being on Monday, the gate is on Sunday and the week is configured to start on Monday",+ with_settings: { start_of_week: 1 } do+ before do+ # This might produce invalid phases where the start date is after the end date.+ # For the sake of the test, this is irrelevant.+ gate.update_column(:"#{boundary}_date", Date.parse("2025-03-02"))+ end++ it "returns no project as the stage ended in the week before" do+ Timecop.travel(Date.parse("2025-03-03").noon) do+ expect(instance.results).to be_empty+ end+ end+ end++ context "when being on Sunday, the gate is on Monday and the week is configured to start on Monday",+ with_settings: { start_of_week: 1 } do+ before do+ # This might produce invalid phases where the start date is after the end date.+ # For the sake of the test, this is irrelevant.+ gate.update_column(:"#{boundary}_date", Date.parse("2025-03-03"))+ end++ it "returns the project whose gate is in the current week" do+ Timecop.travel(Date.parse("2025-03-09").noon) do+ expect(instance.results).to contain_exactly(project_with_gate)+ end+ end+ end++ context "when being on Sunday, the gate is on Monday and the week is configured to start on Sunday",+ with_settings: { start_of_week: 7 } do+ before do+ # This might produce invalid phases where the start date is after the end date.+ # For the sake of the test, this is irrelevant.+ gate.update_column(:"#{boundary}_date", Date.parse("2025-03-03"))+ end++ it "returns no project as the stage ended in the week before" do+ Timecop.travel(Date.parse("2025-03-09").noon) do+ expect(instance.results).to be_empty+ end+ end+ end+ end++ context "with a <>d (between) operator" do+ before do+ instance.where(filter_key, "<>d", values)+ end++ context "when encompassing the gate completely" do+ let(:values) { [(filter_reference_date - 1.day).to_s, (filter_reference_date + 1.day).to_s] }++ it "returns the project with the gate" do+ expect(instance.results).to contain_exactly(project_with_gate)+ end+ end++ context "when encompassing the gate precisely" do+ let(:values) { [filter_reference_date.to_s, filter_reference_date.to_s] }++ it "returns the project with the gate" do+ expect(instance.results).to contain_exactly(project_with_gate)+ end+ end++ context "when only the lower value is provided and that one is before the gate's date" do+ let(:values) { [(filter_reference_date - 1.day).to_s, ""] }++ it "returns the project with the gate" do+ expect(instance.results).to contain_exactly(project_with_gate)+ end+ end++ context "when only the upper value is provided and that one is after the gate's date" do+ let(:values) { ["", (filter_reference_date + 1.day).to_s] }++ it "returns the project with the gate" do+ expect(instance.results).to contain_exactly(project_with_gate)+ end+ end++ context "when only the upper value is provided and that one is on the gate's date" do+ let(:values) { ["", filter_reference_date.to_s] }++ it "returns the project with the gate" do+ expect(instance.results).to contain_exactly(project_with_gate)+ end+ end++ context "when only the upper value is provided and that one is before the gate's date" do+ let(:values) { ["", (filter_reference_date - 1.day).to_s] }++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end++ context "when the gate has no dates" do+ let(:values) { [(filter_reference_date - 1.day).to_s, (filter_reference_date + 1.day).to_s] }++ remove_gate_date++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end++ context "when encompassing the gate precisely but with the gate disabled" do+ let(:values) { [filter_reference_date.to_s, filter_reference_date.to_s] }++ disable_gate++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end++ context "when encompassing the gate precisely but without permissions" do+ let(:values) { [filter_reference_date.to_s, filter_reference_date.to_s] }++ remove_permissions++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end+ end++ context "with a !* (none) operator" do+ before do+ instance.where(filter_key, "!*", [])+ end++ context "when the gate is active but has no dates" do+ remove_gate_date++ it "returns the project with the gate" do+ expect(instance.results).to contain_exactly(project_with_gate)+ end+ end++ context "when the gate is active and has dates" do+ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end++ context "when the gate is inactive and has no dates" do+ remove_gate_date+ disable_gate++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end+ end+ end++ context "for a gate on the start date" do+ let(:boundary) { "start" }+ let(:filter_reference_date) { start_gate_date }++ it_behaves_like "a project phase gate filter"+ end++ context "for a gate on the end date" do+ let(:boundary) { "end" }+ let(:filter_reference_date) { end_gate_date }++ it_behaves_like "a project phase gate filter"+ end+enddiff --git a/spec/models/queries/projects/project_query_results_life_cycle_stage_spec.rb b/spec/models/queries/projects/project_query_results_project_phase_spec.rbsimilarity index 74%rename from spec/models/queries/projects/project_query_results_life_cycle_stage_spec.rbrename to spec/models/queries/projects/project_query_results_project_phase_spec.rbindex db2056d94bd..64c32feaf3f 100644--- a/spec/models/queries/projects/project_query_results_life_cycle_stage_spec.rb+++ b/spec/models/queries/projects/project_query_results_project_phase_spec.rb@@ -30,50 +30,45 @@require "spec_helper"-RSpec.describe ProjectQuery, "results of a life cycle stage filter" do+RSpec.describe ProjectQuery, "results of a project phase filter" dolet(:instance) { described_class.new }- let(:filter_key) { "lcsd_stage_#{stage.definition_id}" }+ let(:filter_key) { "project_phase_#{stage.definition_id}" }shared_let(:view_role) { create(:project_role, permissions: %i[view_project_phases]) }- shared_let(:stage_start_date) { Date.parse("2025-02-07") }- shared_let(:stage_end_date) { Date.parse("2025-02-17") }- shared_let(:project_with_stage) { create(:project, name: "Project with stage") }+ shared_let(:phase_start_date) { Date.parse("2025-02-07") }+ shared_let(:phase_end_date) { Date.parse("2025-02-17") }+ shared_let(:project_with_phase) { create(:project, name: "Project with stage") }shared_let(:stage) do- create(:project_phase, project: project_with_stage, start_date: stage_start_date, end_date: stage_end_date)+ create(:project_phase, project: project_with_phase, start_date: phase_start_date, end_date: phase_end_date)end# This is added to ensure that the filter only works on the stage provided.- shared_let(:project_with_rival_stage) { create(:project, name: "Project with rival stage") }+ shared_let(:project_with_rival_phase) { create(:project, name: "Project with rival stage") }shared_let(:rival_stage) do- create(:project_phase, project: project_with_rival_stage, start_date: stage_start_date, end_date: stage_end_date)+ create(:project_phase, project: project_with_rival_phase, start_date: phase_start_date, end_date: phase_end_date)end- shared_let(:gate_date) { Date.parse("2025-03-06") }- shared_let(:project_with_gate) { create(:project, name: "Project with gate") }- shared_let(:gate) { create(:project_gate, project: project_with_gate, date: gate_date) }-- shared_let(:project_without_step) { create(:project, name: "Project without step") }+ shared_let(:project_without_phase) { create(:project, name: "Project without phase") }shared_let(:user) docreate(:user, member_with_permissions: {- project_with_stage => %i[view_project_phases],- project_with_rival_stage => %i[view_project_phases],- project_with_gate => %i[view_project_phases],- project_without_step => %i[view_project_phases]+ project_with_phase => %i[view_project_phases],+ project_with_rival_phase => %i[view_project_phases],+ project_without_phase => %i[view_project_phases]})endcurrent_user { user }# rubocop:disable RSpec/ScatteredSetup- def self.disable_stage+ def self.disable_phasebefore do- Project::Phase.where(type: Project::Stage.name).update_all(active: false)+ Project::Phase.update_all(active: false)endend- def self.remove_stage_dates+ def self.remove_phase_datesbefore dostage.update_columns(end_date: nil, start_date: nil)end@@ -81,12 +76,11 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" dodef self.remove_permissionsbefore do- # We keep the permission within the project without steps so that the filter itself is available+ # We keep the permission within the Project without phases so that the filter itself is available# but we check that the filter does not return values.RolePermission.where(role_id: Role.joins(:member_roles)- .where(member_roles: { member_id: Member.where(project: [project_with_stage,- project_with_gate]) }))+ .where(member_roles: { member_id: Member.where(project: [project_with_phase]) })).where(permission: :view_project_phases).destroy_allend@@ -99,31 +93,31 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" doendcontext "when filtering in the middle of the stage" do- let(:values) { [(stage_start_date + ((stage_end_date - stage_start_date) / 2)).to_s] }+ let(:values) { [(phase_start_date + ((phase_end_date - phase_start_date) / 2)).to_s] }it "returns the project whose stage is covering an interval including the date" do- expect(instance.results).to contain_exactly(project_with_stage)+ expect(instance.results).to contain_exactly(project_with_phase)endendcontext "when filtering on the first day of the stage" do- let(:values) { [stage_start_date.to_s] }+ let(:values) { [phase_start_date.to_s] }it "returns the project whose stage begins on that date" do- expect(instance.results).to contain_exactly(project_with_stage)+ expect(instance.results).to contain_exactly(project_with_phase)endendcontext "when filtering on the last day of the stage" do- let(:values) { [stage_end_date.to_s] }+ let(:values) { [phase_end_date.to_s] }it "returns the project whose stage ends on that date" do- expect(instance.results).to contain_exactly(project_with_stage)+ expect(instance.results).to contain_exactly(project_with_phase)endendcontext "when filtering before the stage" do- let(:values) { [(stage_start_date - 1.day).to_s] }+ let(:values) { [(phase_start_date - 1.day).to_s] }it "returns no project" doexpect(instance.results).to be_empty@@ -131,7 +125,7 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" doendcontext "when filtering after the stage" do- let(:values) { [(stage_end_date + 1.day).to_s] }+ let(:values) { [(phase_end_date + 1.day).to_s] }it "returns no project" doexpect(instance.results).to be_empty@@ -139,9 +133,9 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" doendcontext "when the stage has no dates" do- let(:values) { [stage_end_date.to_s] }+ let(:values) { [phase_end_date.to_s] }- remove_stage_dates+ remove_phase_datesit "returns no project" doexpect(instance.results).to be_empty@@ -149,9 +143,9 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" doendcontext "when filtering in the middle of the stage but with the stage being inactive" do- let(:values) { [(stage_start_date + ((stage_end_date - stage_start_date) / 2)).to_s] }+ let(:values) { [(phase_start_date + ((phase_end_date - phase_start_date) / 2)).to_s] }- disable_stage+ disable_phaseit "returns no project" doexpect(instance.results).to be_empty@@ -159,7 +153,7 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" doendcontext "when filtering in the middle of the stage but without permissions" do- let(:values) { [(stage_start_date + ((stage_end_date - stage_start_date) / 2)).to_s] }+ let(:values) { [(phase_start_date + ((phase_end_date - phase_start_date) / 2)).to_s] }remove_permissions@@ -176,31 +170,31 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" docontext "when being in the middle of the stage" doit "returns the project whose stage is currently running" do- Timecop.travel((stage_start_date + (stage_end_date - stage_start_date)).noon) do- expect(instance.results).to contain_exactly(project_with_stage)+ Timecop.travel((phase_start_date + (phase_end_date - phase_start_date)).noon) do+ expect(instance.results).to contain_exactly(project_with_phase)endendendcontext "when being on the first day of the stage" doit "returns the project whose stage begins on that date" do- Timecop.travel(stage_start_date.noon) do- expect(instance.results).to contain_exactly(project_with_stage)+ Timecop.travel(phase_start_date.noon) do+ expect(instance.results).to contain_exactly(project_with_phase)endendendcontext "when being on the last day of the stage" doit "returns the project whose stage begins on that date" do- Timecop.travel(stage_end_date.noon) do- expect(instance.results).to contain_exactly(project_with_stage)+ Timecop.travel(phase_end_date.noon) do+ expect(instance.results).to contain_exactly(project_with_phase)endendendcontext "when being before the stage" doit "returns no project" do- Timecop.travel(stage_start_date.noon - 1.day) do+ Timecop.travel(phase_start_date.noon - 1.day) doexpect(instance.results).to be_emptyendend@@ -208,14 +202,14 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" docontext "when being after the stage" doit "returns no project" do- Timecop.travel(stage_end_date.noon + 1.day) do+ Timecop.travel(phase_end_date.noon + 1.day) doexpect(instance.results).to be_emptyendendendcontext "when the stage has no dates" do- remove_stage_dates+ remove_phase_datesit "returns no project" doexpect(instance.results).to be_empty@@ -223,10 +217,10 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" doendcontext "when being in the middle of the stage but with the stage being disabled" do- disable_stage+ disable_phaseit "returns no project" do- Timecop.travel((stage_start_date + (stage_end_date - stage_start_date)).noon) do+ Timecop.travel((phase_start_date + (phase_end_date - phase_start_date)).noon) doexpect(instance.results).to be_emptyendend@@ -236,7 +230,7 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" doremove_permissionsit "returns no project" do- Timecop.travel((stage_start_date + (stage_end_date - stage_start_date)).noon) do+ Timecop.travel((phase_start_date + (phase_end_date - phase_start_date)).noon) doexpect(instance.results).to be_emptyendend@@ -250,31 +244,31 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" docontext "when being in the middle of the stage" doit "returns the project whose stage is currently running" do- Timecop.travel((stage_start_date + 3.days).noon) do- expect(instance.results).to contain_exactly(project_with_stage)+ Timecop.travel((phase_start_date + 3.days).noon) do+ expect(instance.results).to contain_exactly(project_with_phase)endendendcontext "when the current week overlaps the beginning of the stage" doit "returns the project whose stage begins within the week" do- Timecop.travel((stage_start_date - 1.day).noon) do- expect(instance.results).to contain_exactly(project_with_stage)+ Timecop.travel((phase_start_date - 1.day).noon) do+ expect(instance.results).to contain_exactly(project_with_phase)endendendcontext "when the current week overlaps the end of the stage" doit "returns the project whose stage begins within the week" do- Timecop.travel(stage_end_date.noon) do- expect(instance.results).to contain_exactly(project_with_stage)+ Timecop.travel(phase_end_date.noon) do+ expect(instance.results).to contain_exactly(project_with_phase)endendendcontext "when being before the stage" doit "returns no project" do- Timecop.travel(stage_start_date.noon - 7.days) do+ Timecop.travel(phase_start_date.noon - 7.days) doexpect(instance.results).to be_emptyendend@@ -282,27 +276,27 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" docontext "when being after the stage" doit "returns no project" do- Timecop.travel(stage_end_date.noon + 7.days) do+ Timecop.travel(phase_end_date.noon + 7.days) doexpect(instance.results).to be_emptyendendendcontext "when the stage has no dates" do- remove_stage_dates+ remove_phase_datesit "returns no project" do- Timecop.travel(stage_end_date.noon + 7.days) do+ Timecop.travel(phase_end_date.noon + 7.days) doexpect(instance.results).to be_emptyendendendcontext "when being in the middle of the stage but with the stage disabled" do- disable_stage+ disable_phaseit "returns no project" do- Timecop.travel((stage_start_date + 3.days).noon) do+ Timecop.travel((phase_start_date + 3.days).noon) doexpect(instance.results).to be_emptyendend@@ -312,7 +306,7 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" doremove_permissionsit "returns no project" do- Timecop.travel((stage_start_date + 3.days).noon) do+ Timecop.travel((phase_start_date + 3.days).noon) doexpect(instance.results).to be_emptyendend@@ -326,7 +320,7 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" doit "returns the project whose stage has ended within the current week" doTimecop.travel(Date.parse("2025-02-17").noon) do- expect(instance.results).to contain_exactly(project_with_stage)+ expect(instance.results).to contain_exactly(project_with_phase)endendend@@ -352,7 +346,7 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" doit "returns the project whose stage has ended within the current week" doTimecop.travel(Date.parse("2025-02-23").noon) do- expect(instance.results).to contain_exactly(project_with_stage)+ expect(instance.results).to contain_exactly(project_with_phase)endendend@@ -377,23 +371,23 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" doendcontext "when encompassing the stage completely" do- let(:values) { [(stage_start_date - 1.day).to_s, (stage_end_date + 1.day).to_s] }+ let(:values) { [(phase_start_date - 1.day).to_s, (phase_end_date + 1.day).to_s] }it "returns the project with the stage" do- expect(instance.results).to contain_exactly(project_with_stage)+ expect(instance.results).to contain_exactly(project_with_phase)endendcontext "when encompassing the stage precisely" do- let(:values) { [stage_start_date.to_s, stage_end_date.to_s] }+ let(:values) { [phase_start_date.to_s, phase_end_date.to_s] }it "returns the project with the stage" do- expect(instance.results).to contain_exactly(project_with_stage)+ expect(instance.results).to contain_exactly(project_with_phase)endendcontext "when the values overlap the stage's start date but not the end date" do- let(:values) { [(stage_start_date - 1.day).to_s, (stage_end_date - 1.day).to_s] }+ let(:values) { [(phase_start_date - 1.day).to_s, (phase_end_date - 1.day).to_s] }it "returns no project" doexpect(instance.results).to be_empty@@ -401,7 +395,7 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" doendcontext "when the values overlap the stage's end date but not the start date" do- let(:values) { [(stage_start_date + 1.day).to_s, stage_end_date.to_s] }+ let(:values) { [(phase_start_date + 1.day).to_s, phase_end_date.to_s] }it "returns no project" doexpect(instance.results).to be_empty@@ -409,7 +403,7 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" doendcontext "when the values are between the start and the end date of the stage" do- let(:values) { [(stage_start_date + 1.day).to_s, (stage_end_date - 1.day).to_s] }+ let(:values) { [(phase_start_date + 1.day).to_s, (phase_end_date - 1.day).to_s] }it "returns no project" doexpect(instance.results).to be_empty@@ -417,23 +411,23 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" doendcontext "when only the lower value is provided and that one is before the stage's start date" do- let(:values) { [(stage_start_date - 1.day).to_s, ""] }+ let(:values) { [(phase_start_date - 1.day).to_s, ""] }it "returns the project with the stage" do- expect(instance.results).to contain_exactly(project_with_stage)+ expect(instance.results).to contain_exactly(project_with_phase)endendcontext "when only the lower value is provided and that one is on the stage's start date" do- let(:values) { [stage_start_date.to_s, ""] }+ let(:values) { [phase_start_date.to_s, ""] }it "returns the project with the stage" do- expect(instance.results).to contain_exactly(project_with_stage)+ expect(instance.results).to contain_exactly(project_with_phase)endendcontext "when only the lower value is provided and that one after the stage's start date" do- let(:values) { [(stage_start_date + 1.day).to_s, ""] }+ let(:values) { [(phase_start_date + 1.day).to_s, ""] }it "returns no project" doexpect(instance.results).to be_empty@@ -441,17 +435,17 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" doendcontext "when only the upper value is provided and that one is after the stage's end date" do- let(:values) { ["", (stage_end_date + 1.day).to_s] }+ let(:values) { ["", (phase_end_date + 1.day).to_s] }it "returns the project with the stage" do- expect(instance.results).to contain_exactly(project_with_stage)+ expect(instance.results).to contain_exactly(project_with_phase)endendcontext "when the stage has no dates" do- let(:values) { [(stage_start_date - 1.day).to_s, (stage_end_date + 1.day).to_s] }+ let(:values) { [(phase_start_date - 1.day).to_s, (phase_end_date + 1.day).to_s] }- remove_stage_dates+ remove_phase_datesit "returns no project" doexpect(instance.results).to be_empty@@ -467,9 +461,9 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" doendcontext "when encompassing the stage completely but with the stage disabled" do- let(:values) { [(stage_start_date - 1.day).to_s, (stage_end_date + 1.day).to_s] }+ let(:values) { [(phase_start_date - 1.day).to_s, (phase_end_date + 1.day).to_s] }- disable_stage+ disable_phaseit "returns no project" doexpect(instance.results).to be_empty@@ -477,7 +471,7 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" doendcontext "when encompassing the stage completely but without permissions" do- let(:values) { [(stage_start_date - 1.day).to_s, (stage_end_date + 1.day).to_s] }+ let(:values) { [(phase_start_date - 1.day).to_s, (phase_end_date + 1.day).to_s] }remove_permissions@@ -492,11 +486,11 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" doinstance.where(filter_key, "!*", [])end- context "when the gate is active but has no dates" do- remove_stage_dates+ context "when the phase is active but has no dates" do+ remove_phase_datesit "returns the project with the stage" do- expect(instance.results).to contain_exactly(project_with_stage)+ expect(instance.results).to contain_exactly(project_with_phase)endend@@ -507,8 +501,8 @@ RSpec.describe ProjectQuery, "results of a life cycle stage filter" doendcontext "when the stage is inactive and has no dates" do- remove_stage_dates- disable_stage+ remove_phase_dates+ disable_phaseit "returns no project" doexpect(instance.results).to be_empty