Skip to content

Commit

Permalink
Parse default value in Service Dialog
Browse files Browse the repository at this point in the history
When serializing the dialog, it should return an array of values rather than a string if force_multi_value is true
  • Loading branch information
Jillian Tullo committed Nov 29, 2017
1 parent 026070f commit a613395
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/models/dialog_field_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def serialize(dialog_field, all_attributes = false)
"dialog_field_responders" => dialog_field.dialog_field_responders.map(&:name)
}

if dialog_field.try(:force_multi_value) && dialog_field.default_value.present?
extra_attributes["default_value"] = dialog_field.default_value.split(",")
end

if dialog_field.dynamic?
dynamic_values = dialog_field.trigger_automate_value_updates
extra_attributes["values"] = dynamic_values
Expand Down
8 changes: 6 additions & 2 deletions spec/models/dialog_field_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@
allow(dialog_field).to receive(:values).and_return("values")
end

it "serializes the category name and description" do
it "serializes the category name, description and default value" do
default_values = "one,two"
dialog_field.update_attributes(:default_value => default_values)

expect(dialog_field_serializer.serialize(dialog_field))
.to eq(expected_serialized_values.merge(
"resource_action" => "serialized resource action",
Expand All @@ -147,7 +150,8 @@
:category_id => "123",
:category_name => "best category ever",
:category_description => "best category ever"
}
},
"default_value" => %w(one two)
))
end
end
Expand Down

0 comments on commit a613395

Please sign in to comment.