Skip to content

Commit

Permalink
Load not just the values into update the fields
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Sep 12, 2018
1 parent 047586e commit 966dc9d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def load_values_into_fields(values, overwrite = true)

dialog_field_hash.each_value do |field|
field.dialog = self
new_value = values[field.automate_key_name] || values[field.name]
new_value = values[field.automate_key_name] || values[field.name] || values.dig("parameters", field.name)
new_value ||= field.value unless overwrite

field.value = new_value
Expand Down
2 changes: 1 addition & 1 deletion app/models/resource_action_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def add_request_to_cart
end

def update_dialog_field_values(data)
@dialog.load_values_into_fields(data.values.first)
@dialog.load_values_into_fields(data)
end

def process_request(state)
Expand Down
19 changes: 19 additions & 0 deletions spec/models/dialog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,25 @@
dialog.load_values_into_fields(vars)
expect(dialog_field1.value).to eq("10.8.99.248")
end

it "sets field value when in a hash with a key of 'parameters'" do
vars = {"parameters" => {"field1" => "10.8.99.248"}}
dialog.load_values_into_fields(vars)
expect(dialog_field1.value).to eq("10.8.99.248")
end

context "with multiple fields" do
let(:dialog_group) { DialogGroup.new(:dialog_fields => [dialog_field1, dialog_field2]) }
let(:dialog_field1) { DialogField.new(:value => "123", :name => "field1") }
let(:dialog_field2) { DialogField.new(:value => "12", :name => "field2") }

it "sets multiple field values" do
vars = {"field1" => "10.8.99.248", "field2" => "new_value"}
dialog.load_values_into_fields(vars)
expect(dialog_field1.value).to eq("10.8.99.248")
expect(dialog_field2.value).to eq("new_value")
end
end
end

context "symbol values" do
Expand Down

0 comments on commit 966dc9d

Please sign in to comment.