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 time entry query

Klaus Zanders8c413577ddc7
diff --git a/modules/costs/spec/models/queries/time_entries/time_entry_query_spec.rb b/modules/costs/spec/models/queries/time_entries/time_entry_query_spec.rb
index 3d7c08090ea..459cfa6b29b 100644
--- a/modules/costs/spec/models/queries/time_entries/time_entry_query_spec.rb
+++ b/modules/costs/spec/models/queries/time_entries/time_entry_query_spec.rb
@@ -133,19 +133,22 @@ RSpec.describe Queries::TimeEntries::TimeEntryQuery do
end
end
- context "with a work_package filter" do
+ context "with an entity filter" do
before do
allow(WorkPackage)
.to receive_message_chain(:visible, :pluck)
.with(:id)
.and_return([1])
- instance.where("work_package_id", "=", ["1"])
+ instance.where("entity_type", "=", "WorkPackage")
+ instance.where("entity_id", "=", ["1"])
end
describe "#results" do
it "is the same as handwriting the query" do
+ # we need to build the exact same query as the filter, so we cannot optimize for the cop
expected = base_scope
- .where(["time_entries.work_package_id IN (?)", ["1"]])
+ .where("time_entries.entity_type IN (?)", "WorkPackage") # rubocop:disable Rails/WhereEquals
+ .where("time_entries.entity_id IN (?)", ["1"]) # rubocop:disable Rails/WhereEquals
expect(instance.results.to_sql).to eql expected.to_sql
end
@@ -157,8 +160,8 @@ RSpec.describe Queries::TimeEntries::TimeEntryQuery do
end
it "is invalid if the filter is invalid" do
- instance.where("work_package_id", "=", [""])
- expect(instance).to be_invalid
+ instance.where("entity_id", "=", [""])
+ expect(instance).not_to be_valid
end
end
end