Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for a Dialog with Tag Control Failure #11773

Merged
merged 1 commit into from
Oct 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/dialog_field_sorted_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eclarizio It looks like @raw_values is an empty array here for the tag control. I would expect other field to return a multi-dimensional array (like [[1, "One"], [2, "Two"]]) if they had values, otherwise they could have empty arrays as well. Does that sound correct to you?

This change will now set default_value to nil when we get an empty @raw_values array.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmcculloug Yes, that is correct.

Maybe this has to do with timing, but the other alternative would be to check for an empty array and in that case not set the default_value. On line 98, though, we're using default_value, and it's already been established by line 95 that the default_value is non-existent within the @raw_values array, so setting it to nil is probably the better option since you shouldn't be able to select a value that isn't there as opposed to just not selecting a value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I like that we are setting default_value to nil in this case. 👍

end
self.value ||= default_value

Expand Down
20 changes: 18 additions & 2 deletions spec/models/dialog_field_drop_down_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down