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
introduce between operator on `AnyStageOrGateFilter`
ulferts57cbb7722867
diff --git a/app/models/queries/projects/filters/any_stage_or_gate_filter.rb b/app/models/queries/projects/filters/any_stage_or_gate_filter.rbindex 7a357d0c860..d8ec1aebd22 100644--- a/app/models/queries/projects/filters/any_stage_or_gate_filter.rb+++ b/app/models/queries/projects/filters/any_stage_or_gate_filter.rb@@ -36,7 +36,8 @@ class Queries::Projects::Filters::AnyStageOrGateFilter < Queries::Projects::Filtdef available_operators[::Queries::Operators::Today,- ::Queries::Operators::OnDate+ ::Queries::Operators::OnDate,+ ::Queries::Operators::BetweenDate]end@@ -52,13 +53,18 @@ class Queries::Projects::Filters::AnyStageOrGateFilter < Queries::Projects::Filtdef wherecase operatorwhen "=d"- stage_where(parsed_start)+ stage_where_on(parsed_start).or(gate_where(parsed_end)).arel.existswhen "t"- stage_where(today)- .or(gate_where(today))+ stage_where_on(today)+ .or(gate_where(today, today))+ .arel+ .exists+ when "<>d"+ stage_where_between(parsed_start, parsed_end)+ .or(gate_where(parsed_start, parsed_end)).arel.existselse@@ -66,7 +72,7 @@ class Queries::Projects::Filters::AnyStageOrGateFilter < Queries::Projects::Filtendend- def stage_where(start_date, end_date = start_date)+ def stage_where_on(start_date, end_date = start_date)Project::LifeCycleStep.where("project_id = #{Project.table_name}.id").where(type: Project::Stage.name)@@ -74,20 +80,28 @@ class Queries::Projects::Filters::AnyStageOrGateFilter < Queries::Projects::Filt.where(date_range_clause(Project::LifeCycleStep.table_name, "end_date", end_date, nil))end- def gate_where(date)+ def stage_where_between(start_date, end_date)+ Project::LifeCycleStep+ .where("project_id = #{Project.table_name}.id")+ .where(type: Project::Stage.name)+ .where(date_range_clause(Project::LifeCycleStep.table_name, "start_date", start_date, nil))+ .where(date_range_clause(Project::LifeCycleStep.table_name, "end_date", nil, end_date))+ end++ def gate_where(start_date, end_date = start_date)# On gates, only the start_date is set.Project::LifeCycleStep.where("project_id = #{Project.table_name}.id").where(type: Project::Gate.name)- .where(date_range_clause(Project::LifeCycleStep.table_name, "start_date", date, date))+ .where(date_range_clause(Project::LifeCycleStep.table_name, "start_date", start_date, end_date))enddef parsed_start- Date.parse(values.first)+ values.first.present? ? Date.parse(values.first) : nilenddef parsed_end- Date.parse(values.last)+ values.last.present? ? Date.parse(values.last) : nilenddef todaydiff --git a/spec/features/projects/lists/filters_spec.rb b/spec/features/projects/lists/filters_spec.rbindex ca5b539890b..65dccb4e8ae 100644--- a/spec/features/projects/lists/filters_spec.rb+++ b/spec/features/projects/lists/filters_spec.rb@@ -642,13 +642,25 @@ RSpec.describe "Projects list filters", :js, with_settings: { login_required?: fprojects_page.expect_filter_available("Any stage or gate")- projects_page.set_filter("any_stage_or_gate", "Any stage or gate", "on", [Time.zone.today + 8.days])+ projects_page.set_filter("any_stage_or_gate",+ "Any stage or gate",+ "on",+ [Time.zone.today + 8.days])projects_page.expect_projects_in_order(project, public_project)- projects_page.set_filter("any_stage_or_gate", "Any stage or gate", "today")+ projects_page.set_filter("any_stage_or_gate",+ "Any stage or gate",+ "today")projects_page.expect_projects_in_order(project)++ projects_page.set_filter("any_stage_or_gate",+ "Any stage or gate",+ "between",+ [Time.zone.today, Time.zone.today + 9.days])++ projects_page.expect_projects_in_order(project, public_project)endenddiff --git a/spec/models/queries/projects/project_query_results_any_stage_or_gate_spec.rb b/spec/models/queries/projects/project_query_results_any_stage_or_gate_spec.rbindex 05c6f8d66c9..99e1cbd76fb 100644--- a/spec/models/queries/projects/project_query_results_any_stage_or_gate_spec.rb+++ b/spec/models/queries/projects/project_query_results_any_stage_or_gate_spec.rb@@ -130,7 +130,6 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" doend# TODO: check active state- # TODO: work with time zones?context "with a t (today) operator" dobefore do@@ -199,4 +198,160 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" doendendend++ context "with a <>d (between) operator" do+ before do+ instance.where("any_stage_or_gate", "<>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+ before do+ Project::LifeCycleStep.where(type: Project::Gate.name).destroy_all+ end++ 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+ before do+ Project::LifeCycleStep.where(type: Project::Gate.name).destroy_all+ end++ 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+ before do+ Project::LifeCycleStep.where(type: Project::Gate.name).destroy_all+ end++ 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 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+ before do+ Project::LifeCycleStep.where(type: Project::Stage.name).destroy_all+ end++ 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+ before do+ Project::LifeCycleStep.where(type: Project::Stage.name).destroy_all+ end++ 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+ before do+ Project::LifeCycleStep.where(type: Project::Stage.name).destroy_all+ end++ it "returns no project" do+ expect(instance.results).to be_empty+ end+ end+ endend