mirror of
https://github.com/opf/openproject.git
synced 2026-06-13 19:20:00 +00:00
Fix query mocks
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user