Skip to content

Commit

Permalink
Don't JSON.parse(nil)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Nov 12, 2018
1 parent 3d2a9b6 commit d588654
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/models/dialog_field_drop_down_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def default_value_included?(values_list)
end

def coerce_default_value_into_proper_format
return unless default_value
unless JSON.parse(default_value).kind_of?(Array)
self.default_value = Array.wrap(default_value).to_json
end
Expand Down
22 changes: 19 additions & 3 deletions spec/models/dialog_field_drop_down_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,25 @@
allow(DynamicDialogFieldValueProcessor).to receive(:values_from_automate).with(dialog_field).and_return(values)
end

it "uses the given value as the default" do
dialog_field.initialize_with_given_value("test")
expect(dialog_field.default_value).to eq(["test"].to_json)
context "given value is a string" do
it "uses the given value as the default" do
dialog_field.initialize_with_given_value("test")
expect(dialog_field.default_value).to eq(["test"].to_json)
end
end

context "given value is an array" do
it "uses the given value as the default" do
dialog_field.initialize_with_given_value(["test"])
expect(dialog_field.default_value).to eq(["test"].to_json)
end
end

context "given value is nil" do
it "uses the given value as the default" do
dialog_field.initialize_with_given_value(nil)
expect(dialog_field.default_value).to eq(nil)
end
end
end
end
Expand Down

0 comments on commit d588654

Please sign in to comment.