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
check active state in the filter
ulferts8e5f0199e2c8
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 5db1121b470..6737ee50aea 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@@ -82,6 +82,7 @@ class Queries::Projects::Filters::AnyStageOrGateFilter < Queries::Projects::FiltProject::LifeCycleStep.where("#{Project::LifeCycleStep.table_name}.project_id = #{Project.table_name}.id").where(type: Project::Stage.name)+ .active.where(date_range_clause(Project::LifeCycleStep.table_name, "start_date", nil, start_date)).where(date_range_clause(Project::LifeCycleStep.table_name, "end_date", end_date, nil))end@@ -90,6 +91,7 @@ class Queries::Projects::Filters::AnyStageOrGateFilter < Queries::Projects::FiltProject::LifeCycleStep.where("#{Project::LifeCycleStep.table_name}.project_id = #{Project.table_name}.id").where(type: Project::Stage.name)+ .active.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@@ -99,6 +101,7 @@ class Queries::Projects::Filters::AnyStageOrGateFilter < Queries::Projects::FiltProject::LifeCycleStep.where("#{Project::LifeCycleStep.table_name}.project_id = #{Project.table_name}.id").where(type: Project::Gate.name)+ .active.where(date_range_clause(Project::LifeCycleStep.table_name, "start_date", start_date, end_date))end@@ -106,6 +109,7 @@ class Queries::Projects::Filters::AnyStageOrGateFilter < Queries::Projects::FiltProject::LifeCycleStep.where("#{Project::LifeCycleStep.table_name}.project_id = #{Project.table_name}.id").where(type: Project::Stage.name)+ .active.where(<<~SQL.squish, today.beginning_of_week, today.end_of_weekdaterange(#{Project::LifeCycleStep.table_name}.start_date,diff --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 f9e4813ff37..e93f0b12298 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@@ -59,13 +59,31 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" docurrent_user { user }- def remove_gate- Project::LifeCycleStep.where(type: Project::Gate.name).destroy_all+ # rubocop:disable RSpec/ScatteredSetup+ def self.remove_gate+ before do+ Project::LifeCycleStep.where(type: Project::Gate.name).destroy_all+ end+ end++ def self.remove_stage+ before do+ Project::LifeCycleStep.where(type: Project::Stage.name).destroy_all+ endend- def remove_stage- Project::LifeCycleStep.where(type: Project::Stage.name).destroy_all+ def self.disable_stage+ before do+ Project::LifeCycleStep.where(type: Project::Stage.name).update_all(active: false)+ end+ end++ def self.disable_gate+ before do+ Project::LifeCycleStep.where(type: Project::Gate.name).update_all(active: false)+ endend+ # rubocop:enable RSpec/ScatteredSetupcontext "with a =d (on) operator" dobefore do@@ -135,9 +153,28 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" doexpect(instance.results).to be_emptyendend++ 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+ endend- # TODO: check active state# TODO: check permissionscontext "with a t (today) operator" do@@ -147,7 +184,9 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" docontext "when being in the middle of the stage" doit "returns the project whose stage is currently running" do- expect(instance.results).to contain_exactly(project_with_stage)+ Timecop.travel((stage_start_date + (stage_end_date - stage_start_date)).noon) do+ expect(instance.results).to contain_exactly(project_with_stage)+ endendend@@ -206,6 +245,26 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" doendendend++ 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 stage being disabled" do+ disable_gate++ it "returns no project" do+ Timecop.travel(gate_date.noon) do+ expect(instance.results).to be_empty+ end+ end+ endendcontext "with a w (this week) operator" do@@ -231,9 +290,7 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" docontext "when the current week overlaps the end of the stage" do# Would otherwise interfere with the spec- before do- remove_gate- end+ remove_gateit "returns the project whose stage begins within the week" doTimecop.travel(stage_end_date.noon) do@@ -260,9 +317,7 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" docontext "when being a day before the gate" do# Would otherwise interfere with the spec- before do- remove_stage- end+ remove_stageit "returns the project whose gate is within the current week" doTimecop.travel(gate_date.noon - 1.day) do@@ -273,9 +328,7 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" docontext "when being a day after the gate" do# Would otherwise interfere with the spec- before do- remove_stage- end+ remove_stageit "returns the project whose gate is within the current week" doTimecop.travel(gate_date.noon + 1.day) do@@ -286,9 +339,7 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" docontext "when being in the week before the day of the gate" do# Would otherwise interfere with the spec- before do- remove_stage- end+ remove_stageit "returns no project" doTimecop.travel(gate_date.noon - 7.days) do@@ -304,6 +355,28 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" doendendend++ 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+ # Would otherwise interfere with the spec+ remove_stage+ disable_gate++ it "returns no project" do+ Timecop.travel(gate_date.noon - 1.day) do+ expect(instance.results).to be_empty+ end+ end+ endendcontext "with a <>d (between) operator" do@@ -355,9 +428,7 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" dolet(:values) { [(stage_start_date - 1.day).to_s, ""] }# Interferes at it would otherwise be found as well- before do- remove_gate- end+ remove_gateit "returns the project with the stage" doexpect(instance.results).to contain_exactly(project_with_stage)@@ -368,9 +439,7 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" dolet(:values) { [stage_start_date.to_s, ""] }# Interferes at it would otherwise be found as well- before do- remove_gate- end+ remove_gateit "returns the project with the stage" doexpect(instance.results).to contain_exactly(project_with_stage)@@ -381,9 +450,7 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" dolet(:values) { [(stage_start_date + 1.day).to_s, ""] }# Interferes at it would otherwise be found as well- before do- remove_gate- end+ remove_gateit "returns no project" doexpect(instance.results).to be_empty@@ -426,9 +493,7 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" dolet(:values) { ["", (gate_date + 1.day).to_s] }# Interferes at it would otherwise be found as well- before do- remove_stage- end+ remove_stageit "returns the project with the gate" doexpect(instance.results).to contain_exactly(project_with_gate)@@ -439,9 +504,7 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" dolet(:values) { ["", gate_date.to_s] }# Interferes at it would otherwise be found as well- before do- remove_stage- end+ remove_stageit "returns the project with the gate" doexpect(instance.results).to contain_exactly(project_with_gate)@@ -452,9 +515,27 @@ RSpec.describe ProjectQuery, "results of 'Any stage or gate' filter" dolet(:values) { ["", (gate_date - 1.day).to_s] }# Interferes at it would otherwise be found as well- before do- remove_stage+ remove_stage++ it "returns no project" do+ expect(instance.results).to be_emptyend+ 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_gateit "returns no project" doexpect(instance.results).to be_empty