From c992d6c04d5bc278e79199a067f8d41d62928ff2 Mon Sep 17 00:00:00 2001 From: Dombi Attila <83396+dombesz@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:24:30 +0200 Subject: [PATCH] Fix query mocks --- spec/models/queries/factory_project_query_spec.rb | 12 +++++++----- .../queries/projects/selects/custom_field_spec.rb | 9 +++++---- .../project_queries/set_attributes_service_spec.rb | 10 +++++++--- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/spec/models/queries/factory_project_query_spec.rb b/spec/models/queries/factory_project_query_spec.rb index f4335a76c49..3ba22ef23e3 100644 --- a/spec/models/queries/factory_project_query_spec.rb +++ b/spec/models/queries/factory_project_query_spec.rb @@ -64,13 +64,15 @@ RSpec.describe Queries::Factory, .and_return(scope) allow(scope) - .to receive(:find_by) - .and_return nil + .to receive(:includes) + .with(:calculated_value_errors) + .and_return(scope) allow(scope) - .to receive(:find_by) - .with(id: cf.id.to_s) - .and_return(cf) + .to receive(:where) do |conditions| + cf_id = conditions[:id]&.first + cf_id == cf.id ? [cf] : [] + end end end diff --git a/spec/models/queries/projects/selects/custom_field_spec.rb b/spec/models/queries/projects/selects/custom_field_spec.rb index 068b4bf3233..d85ce6c287f 100644 --- a/spec/models/queries/projects/selects/custom_field_spec.rb +++ b/spec/models/queries/projects/selects/custom_field_spec.rb @@ -55,14 +55,15 @@ RSpec.describe Queries::Projects::Selects::CustomField do let(:id) { 42 } before do - visible = double + scope = double - allow(ProjectCustomField).to receive(:visible).and_return(visible) - allow(visible).to receive(:find_by).with(id: id.to_s).and_return(custom_field) + allow(ProjectCustomField).to receive(:visible).and_return(scope) + allow(scope).to receive(:includes).with(:calculated_value_errors).and_return(scope) + allow(scope).to receive(:where).with(id: [id]).and_return([custom_field].compact) end context "when custom field exists" do - let(:custom_field) { instance_double(ProjectCustomField) } + let(:custom_field) { instance_double(ProjectCustomField, id:) } it "returns the custom field" do expect(instance.custom_field).to eq(custom_field) diff --git a/spec/services/project_queries/set_attributes_service_spec.rb b/spec/services/project_queries/set_attributes_service_spec.rb index 090329064d2..a3c9ebf4aa2 100644 --- a/spec/services/project_queries/set_attributes_service_spec.rb +++ b/spec/services/project_queries/set_attributes_service_spec.rb @@ -65,9 +65,13 @@ RSpec.describe ProjectQueries::SetAttributesService, type: :model do .and_return(scope) allow(scope) - .to receive(:find_by) - .with(id: cf.id.to_s) - .and_return(cf) + .to receive(:includes) + .with(:calculated_value_errors) + .and_return(scope) + + allow(scope) + .to receive(:where) + .and_return([cf]) allow(scope) .to receive(:pluck)