A platform for community discussion. Free, open, simple.
DEV: Don’t check model validity when no changes have been made
Loïc Guitaut1a9f5770442e
diff --git a/lib/service/base.rb b/lib/service/base.rbindex 3bece326a95..8a065da4c3d 100644--- a/lib/service/base.rb+++ b/lib/service/base.rb@@ -196,7 +196,7 @@ module Servicedef run_stepcontext[name] = superraise NotFound if !optional && (!context[name] || context[name].try(:empty?))- if context[name].try(:invalid?)+ if context[name].try(:has_changes_to_save?) && context[name].try(:invalid?)context[result_key].fail(invalid: true)context.fail!enddiff --git a/spec/lib/service/runner_spec.rb b/spec/lib/service/runner_spec.rbindex ca76f3225ad..bf1a54b654d 100644--- a/spec/lib/service/runner_spec.rb+++ b/spec/lib/service/runner_spec.rb@@ -83,7 +83,7 @@ RSpec.describe Service::Runner doprivatedef fetch_fake_model- OpenStruct.new(invalid?: true)+ OpenStruct.new(has_changes_to_save?: true, invalid?: true)endend@@ -444,7 +444,7 @@ RSpec.describe Service::Runner docontext "when using the block argument" dolet(:actions) { <<-BLOCK }proc do- on_model_errors(:fake_model) { |model| model == OpenStruct.new(invalid?: true) }+ on_model_errors(:fake_model) { |model| model.invalid? }endBLOCKdiff --git a/spec/lib/service/steps_inspector_spec.rb b/spec/lib/service/steps_inspector_spec.rbindex 3f1e6f2452e..67f33b6478f 100644--- a/spec/lib/service/steps_inspector_spec.rb+++ b/spec/lib/service/steps_inspector_spec.rb@@ -281,7 +281,11 @@ RSpec.describe Service::StepsInspector dobefore doclass DummyServicedef fetch_model- OpenStruct.new(invalid?: true, errors: ActiveModel::Errors.new(nil))+ OpenStruct.new(+ has_changes_to_save?: true,+ invalid?: true,+ errors: ActiveModel::Errors.new(nil),+ )endendend