diff --git a/app/models/dialog_field_sorted_item.rb b/app/models/dialog_field_sorted_item.rb index 80e8672db5b..dec19be284e 100644 --- a/app/models/dialog_field_sorted_item.rb +++ b/app/models/dialog_field_sorted_item.rb @@ -93,7 +93,7 @@ def sort_data(data_to_sort) def raw_values @raw_values ||= dynamic ? values_from_automate : self[:values].to_miq_a unless @raw_values.collect { |value_pair| value_pair[0] }.include?(default_value) - self.default_value = sort_data(@raw_values).first.first + self.default_value = sort_data(@raw_values).first.try(:first) end self.value ||= default_value diff --git a/spec/models/dialog_field_drop_down_list_spec.rb b/spec/models/dialog_field_drop_down_list_spec.rb index 613076df272..d0a6815aa37 100644 --- a/spec/models/dialog_field_drop_down_list_spec.rb +++ b/spec/models/dialog_field_drop_down_list_spec.rb @@ -238,11 +238,27 @@ context "when the raw values are not already set" do before do - dialog_field.values = %w(original values) + dialog_field.values = [%w(original values)] end it "returns the values" do - expect(dialog_field.trigger_automate_value_updates).to eq(%w(original values)) + expect(dialog_field.trigger_automate_value_updates).to eq([%w(original values)]) + end + + it "sets up the default value" do + dialog_field.trigger_automate_value_updates + expect(dialog_field.default_value).to eq("original") + end + end + + context "when the raw values are nil" do + before do + dialog_field.values = nil + end + + it "sets the default value to nil without blowing up" do + dialog_field.trigger_automate_value_updates + expect(dialog_field.default_value).to eq(nil) end end end