Fix query mocks

This commit is contained in:
Dombi Attila
2025-12-12 17:24:30 +02:00
parent 6053cd2e7c
commit c992d6c04d
3 changed files with 19 additions and 12 deletions
@@ -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
@@ -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)
@@ -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)