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
at_timestamp: handle where clauses with sql strings where the `work_packages.id` is referenced
Sebastian Fiedlschuster3fde1fe4eb96
diff --git a/app/models/journable/historic_active_record_relation.rb b/app/models/journable/historic_active_record_relation.rbindex f269c198ab9..8419bf12ccf 100644--- a/app/models/journable/historic_active_record_relation.rb+++ b/app/models/journable/historic_active_record_relation.rb@@ -124,6 +124,7 @@ class Journable::HistoricActiveRecordRelation < ActiveRecord::Relationrelation.where_clause.instance_variable_get(:@predicates).each do |predicate|if predicate.kind_of? Stringpredicate.gsub! "#{model.table_name}.", "#{model.journal_class.table_name}."+ predicate.gsub! "#{model.journal_class.table_name}.id", "journals.journable_id"elsif predicate.left.relation == arel_tableif predicate.right.respond_to? :name and predicate.right.name == "id"predicate.right.instance_variable_set(:@name, "journable_id")diff --git a/spec/models/journable/timestamps_spec.rb b/spec/models/journable/timestamps_spec.rbindex ab578be9d0e..68a4babf612 100644--- a/spec/models/journable/timestamps_spec.rb+++ b/spec/models/journable/timestamps_spec.rb@@ -522,6 +522,19 @@ describe Journable::Timestamps doit "returns the requested work package" doexpect(subject).to include work_packageend++ describe "when the sql where statement includes work_package.id" do+ # This is used, for example, in 'follows' relations.+ subject { WorkPackage.where("(work_packages.id IN (#{work_package.id}))").at_timestamp(wednesday) }++ it "transforms the expression to query the correct table" do+ expect(subject.to_sql).to include "journals.journable_id IN (#{work_package.id})"+ end++ it "returns the requested work package" do+ expect(subject).to include work_package+ end+ endenddescribe "when chaining an order clause" do