Skip to content

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

fix removing consecutive custom field filters in baseline

ulfertsdf25bcff99f1
diff --git a/app/models/journable/historic_active_record_relation.rb b/app/models/journable/historic_active_record_relation.rb
index 1a1a3d986ca..65943964f08 100644
--- a/app/models/journable/historic_active_record_relation.rb
+++ b/app/models/journable/historic_active_record_relation.rb
@@ -232,7 +232,7 @@ class Journable::HistoricActiveRecordRelation < ActiveRecord::Relation
# but it has to the journals table. We join it to the journals table instead.
journal_id = "customizable_journals.journal_id = journals.id"
- predicate.gsub! /#{customized_type}.*AND #{customized_id}/m, journal_id
+ predicate.gsub! /#{customized_type}\s*AND #{customized_id}/m, journal_id
end
end
diff --git a/spec/models/journable/historic_active_record_relation_spec.rb b/spec/models/journable/historic_active_record_relation_spec.rb
index 1bd66072f11..f0f97e53e1e 100644
--- a/spec/models/journable/historic_active_record_relation_spec.rb
+++ b/spec/models/journable/historic_active_record_relation_spec.rb
@@ -220,7 +220,7 @@ RSpec.describe Journable::HistoricActiveRecordRelation do
end
end
- describe "when searching for custom fields" do
+ describe "when searching for a single custom field" do
let(:custom_field) do
create(:text_wp_custom_field,
name: "Text CF",
@@ -284,6 +284,109 @@ RSpec.describe Journable::HistoricActiveRecordRelation do
end
end
end
+
+ describe "when searching for two custom fields (concatenated into string as Query#results does)" do
+ let(:text_custom_field) do
+ create(:text_wp_custom_field,
+ name: "Text CF",
+ types: project.types,
+ projects: [project])
+ end
+ let!(:monday_text_cf_journal) do
+ create(:journal_customizable_journal,
+ journal: monday_journal,
+ custom_field: text_custom_field,
+ value: "Monday_CV")
+ end
+ let!(:wednesday_text_cf_journal) do
+ create(:journal_customizable_journal,
+ journal: wednesday_journal,
+ custom_field: text_custom_field,
+ value: "Wednesday_CV")
+ end
+ let!(:friday_text_cf_journal) do
+ create(:journal_customizable_journal,
+ journal: friday_journal,
+ custom_field: text_custom_field,
+ value: "Friday_CV")
+ end
+ let(:int_custom_field) do
+ create(:integer_wp_custom_field,
+ name: "Int CF",
+ types: project.types,
+ projects: [project])
+ end
+ let!(:monday_int_cf_journal) do
+ create(:journal_customizable_journal,
+ journal: monday_journal,
+ custom_field: int_custom_field,
+ value: "1")
+ end
+ let!(:wednesday_int_cf_journal) do
+ create(:journal_customizable_journal,
+ journal: wednesday_journal,
+ custom_field: int_custom_field,
+ value: "2")
+ end
+ let!(:friday_int_cf_journal) do
+ create(:journal_customizable_journal,
+ journal: friday_journal,
+ custom_field: int_custom_field,
+ value: "3")
+ end
+ let(:work_package_attributes) do
+ { custom_values: { text_custom_field.id => "Friday_CV", int_custom_field.id => "3" } }
+ end
+ let(:text_filter) do
+ Queries::WorkPackages::Filter::CustomFieldFilter.create!(
+ name: text_custom_field.column_name,
+ context: build_stubbed(:query, project:),
+ operator: "~",
+ values: text_values
+ )
+ end
+ let(:int_filter) do
+ Queries::WorkPackages::Filter::CustomFieldFilter.create!(
+ name: int_custom_field.column_name,
+ context: build_stubbed(:query, project:),
+ operator: "=",
+ values: int_values
+ )
+ end
+ # Done just like Query#results does it by fetching Query#statement
+ let(:relation) { WorkPackage.where("(#{text_filter.where}) AND (#{int_filter.where})") }
+
+ context "with the current value at the current time" do
+ let(:text_values) { %w(Friday_CV) }
+ let(:int_values) { "3" }
+ let(:historic_relation) { relation.at_timestamp(Timestamp.new("PT0S")) }
+
+ it "returns the requested work package" do
+ expect(subject).to include work_package
+ end
+ end
+
+ context "with matching historic values" do
+ let(:text_values) { %w(Wednesday) }
+ let(:int_values) { "2" }
+ let(:historic_relation) { relation.at_timestamp(wednesday) }
+
+ it "returns the requested work package" do
+ expect(subject).to include work_package
+ end
+ end
+
+ # Guards against regression #58600
+ context "with only one filter matching historic values" do
+ let(:text_values) { %w(Friday) }
+ let(:int_values) { "2" }
+ let(:historic_relation) { relation.at_timestamp(wednesday) }
+
+ it "returns no work package" do
+ expect(subject).to be_empty
+ end
+ end
+ end
end
describe "foo OR bar (Arel::Nodes::Grouping)" do