Extend specs to cover the expected custom_values_to_validate values.

This commit is contained in:
Dombi Attila
2025-11-19 17:10:33 +02:00
parent 53b0c14191
commit 2e29ca3e51
@@ -314,27 +314,44 @@ RSpec.describe Projects::SetAttributesService, type: :model do
end
end
context "when skip_custom_field_validation is true" do
let(:contract_options) { { skip_custom_field_validation: true } }
let(:project) { create(:project) }
context "with a required custom field" do
shared_let(:required_custom_field) { create(:text_project_custom_field, is_required: true) }
shared_let(:call_attributes) { { custom_field_values: { required_custom_field.id => "Provided value" } } }
it "deactivates custom field validations" do
allow(project).to receive(:deactivate_custom_field_validations!)
subject
context "when skip_custom_field_validation is true" do
let(:contract_options) { { skip_custom_field_validation: true } }
let(:project) { create(:project) }
expect(project).to have_received(:deactivate_custom_field_validations!)
it "deactivates custom field validations" do
allow(project).to receive(:deactivate_custom_field_validations!).and_call_original
subject
expect(project).to have_received(:deactivate_custom_field_validations!)
end
it "clears the custom values to validate" do
subject
expect(subject.result.custom_values_to_validate).to be_empty
end
end
end
context "when skip_custom_field_validation is false" do
let(:contract_options) { { skip_custom_field_validation: false } }
let(:project) { create(:project) }
context "when skip_custom_field_validation is false" do
let(:contract_options) { { skip_custom_field_validation: false } }
let(:project) { create(:project) }
it "does not deactivate custom field validations" do
allow(project).to receive(:deactivate_custom_field_validations!)
subject
it "does not deactivate custom field validations" do
allow(project).to receive(:deactivate_custom_field_validations!).and_call_original
subject
expect(project).not_to have_received(:deactivate_custom_field_validations!)
expect(project).not_to have_received(:deactivate_custom_field_validations!)
end
it "keeps the custom values to validate" do
custom_field_ids = subject.result.custom_values_to_validate.map(&:custom_field_id).uniq
expect(custom_field_ids).to contain_exactly(required_custom_field.id)
end
end
end
end