diff --git a/app/models/dialog.rb b/app/models/dialog.rb index dae0a64336d..821c1ab9bf9 100644 --- a/app/models/dialog.rb +++ b/app/models/dialog.rb @@ -119,6 +119,8 @@ def initialize_value_context(_values) end def init_fields_with_values_for_request(values) + values = values.with_indifferent_access + dialog_field_hash.each do |_key, field| field.value = values[field.automate_key_name] || values[field.name] end diff --git a/spec/models/dialog_spec.rb b/spec/models/dialog_spec.rb index e2dda2c98a4..27d1b8457d3 100644 --- a/spec/models/dialog_spec.rb +++ b/spec/models/dialog_spec.rb @@ -520,19 +520,39 @@ let(:dialog_group) { DialogGroup.new(:dialog_fields => [dialog_field1]) } let(:dialog_field1) { DialogField.new(:value => "123", :name => "field1") } - context "when the values use the automate key name" do - it "initializes the fields with the given values" do - values = {"dialog_field1" => "field 1 new value"} - dialog.init_fields_with_values_for_request(values) - expect(dialog_field1.value).to eq("field 1 new value") + context "when the keys are strings" do + context "when the values use the automate key name" do + it "initializes the fields with the given values" do + values = {"dialog_field1" => "field 1 new value"} + dialog.init_fields_with_values_for_request(values) + expect(dialog_field1.value).to eq("field 1 new value") + end + end + + context "when the values use the regular name" do + it "initializes the fields with the given values" do + values = {"field1" => "field 1 new value"} + dialog.init_fields_with_values_for_request(values) + expect(dialog_field1.value).to eq("field 1 new value") + end end end - context "when the values use the regular name" do - it "initializes the fields with the given values" do - values = {"field1" => "field 1 new value"} - dialog.init_fields_with_values_for_request(values) - expect(dialog_field1.value).to eq("field 1 new value") + context "when the keys are symbols" do + context "when the values use the automate key name" do + it "initializes the fields with the given values" do + values = {:dialog_field1 => "field 1 new value"} + dialog.init_fields_with_values_for_request(values) + expect(dialog_field1.value).to eq("field 1 new value") + end + end + + context "when the values use the regular name" do + it "initializes the fields with the given values" do + values = {:field1 => "field 1 new value"} + dialog.init_fields_with_values_for_request(values) + expect(dialog_field1.value).to eq("field 1 new value") + end end end end