diff --git a/app/models/dialog_field.rb b/app/models/dialog_field.rb index 5e08b1d9ede..b69c20030b8 100644 --- a/app/models/dialog_field.rb +++ b/app/models/dialog_field.rb @@ -96,7 +96,9 @@ def extract_dynamic_values end def initialize_value_context - @value = values_from_automate if dynamic && @value.blank? + if @value.blank? + @value = dynamic ? values_from_automate : default_value + end end def initialize_with_values(dialog_values) diff --git a/spec/models/dialog_field_spec.rb b/spec/models/dialog_field_spec.rb index 98f99f1421b..d228c256c97 100644 --- a/spec/models/dialog_field_spec.rb +++ b/spec/models/dialog_field_spec.rb @@ -108,6 +108,7 @@ describe "#initialize_value_context" do let(:field) { described_class.new(:dynamic => dynamic, :value => value) } + let(:field_with_default) { described_class.new(:dynamic => dynamic, :value => value, :default_value => "drew_was_here") } context "when the field is dynamic" do let(:dynamic) { true } @@ -138,11 +139,25 @@ context "when the field is not dynamic" do let(:dynamic) { false } - let(:value) { "not dynamic" } - it "does not adjust the value" do - field.initialize_value_context - expect(field.instance_variable_get(:@value)).to eq("not dynamic") + context "with a user-adjusted value" do + let(:value) { "not dynamic" } + + it "does not adjust the value" do + field.initialize_value_context + expect(field.instance_variable_get(:@value)).to eq("not dynamic") + end + end + + context "without a user-adjusted value" do + context "with a default value" do + let(:value) { nil } + + it "does adjust the value" do + field_with_default.initialize_value_context + expect(field_with_default.instance_variable_get(:@value)).to eq("drew_was_here") + end + end end end end