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
Fix multiple day filter bug, by explicitly applying the from clause when it's present
Dombi Attila64b2af75ea42
diff --git a/app/models/queries/days/day_query.rb b/app/models/queries/days/day_query.rbindex f026b7ca8ba..3f53c9b4752 100644--- a/app/models/queries/days/day_query.rb+++ b/app/models/queries/days/day_query.rb@@ -36,14 +36,13 @@ class Queries::Days::DayQuery < Queries::BaseQueryend##- # This override is necessary, the dates interval filter needs to adjust the- # `from` clause of the query. To update the `from` clause, we reverse merge the filters,- # otherwise the `from` clause of the filter is ignored.+ # The dates interval filter needs to adjust the `from` clause of the query.+ # If there are multiple filters with custom from clause (currently not possible),+ # the first one is applied and the rest is ignored.def apply_filters(scope)- filters.each do |filter|- scope = filter.scope.merge(scope)- end-+ scope = super(scope)+ from_clause_filter = filters.find(&:from)+ scope = scope.from(from_clause_filter.from) if from_clause_filterscopeenddiff --git a/spec/models/queries/days/day_query_spec.rb b/spec/models/queries/days/day_query_spec.rbindex 0c5131f7519..fbf35764114 100644--- a/spec/models/queries/days/day_query_spec.rb+++ b/spec/models/queries/days/day_query_spec.rb@@ -60,22 +60,25 @@ describe Queries::Days::DayQuery, type: :model doinstance.where('date', '<>d', date_range)end- context 'with dates within the default range' do+ shared_examples_for 'dates within the default range' do |working: nil|let(:from) { Time.zone.today }let(:to) { 5.days.from_now.to_date }let(:base_scope) { Day.from_range(from:, to:).reorder(date: :asc) }-it 'is the same as handwriting the query' do# Expectation has to be weirdly specific to the logic of Queries::Operators::DateRangeClauses- expected = base_scope.where("days.date > ? AND days.date <= ?",+ expected_scope = base_scope.where("days.date > ? AND days.date <= ?",(from - 1.day).end_of_day,to.end_of_day)- expect(instance.results.to_sql).to eql expected.to_sql+ unless working.nil?+ expected_scope = expected_scope.where("days.working IN ('#{working}')")+ end++ expect(instance.results.to_sql).to eql expected_scope.to_sqlendend- context 'with dates out of the default range' do+ shared_examples_for 'dates out of the default range' dolet(:from) { 5.days.from_now.to_date }let(:to) { 153.days.from_now.to_date }@@ -101,5 +104,17 @@ describe Queries::Days::DayQuery, type: :model doendendend++ include_examples 'dates within the default range'+ include_examples 'dates out of the default range'++ context 'when having a working filter too' do+ before do+ instance.where('working', '=', 't')+ end++ include_examples 'dates within the default range', working: 't'+ include_examples 'dates out of the default range'+ endendend