Skip to content

Commit

Permalink
Add check for tag control category fix (ManageIQ#16955)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Jun 6, 2018
1 parent 27322e0 commit 0e006d1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/models/dialog_field_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def serialize(dialog_field, all_attributes = false)

if dialog_field.type == "DialogFieldTagControl"
category = Category.find_by(:id => dialog_field.category)
dialog_field.options.merge!(:category_name => category.name, :category_description => category.description)
dialog_field.options.merge!(:category_name => category.name, :category_description => category.description) if category
end

included_attributes(dialog_field.as_json(:methods => [:type, :values]), all_attributes).merge(extra_attributes)
Expand Down
45 changes: 32 additions & 13 deletions spec/models/dialog_field_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,40 @@
let(:dynamic) { false }
let(:category) { double("Category", :name => "best category ever", :description => "best category ever") }

before do
allow(Category).to receive(:find_by).with(:id => "123").and_return(category)
allow(dialog_field).to receive(:values).and_return("values")
context "with category" do
before do
allow(Category).to receive(:find_by).with(:id => "123").and_return(category)
allow(dialog_field).to receive(:values).and_return("values")
end

it "serializes the category name and description" do
expect(dialog_field_serializer.serialize(dialog_field))
.to eq(expected_serialized_values.merge(
"resource_action" => "serialized resource action",
"options" => {
:category_id => "123",
:category_name => "best category ever",
:category_description => "best category ever"
}
))
end
end

it "serializes the category name and description" do
expect(dialog_field_serializer.serialize(dialog_field))
.to eq(expected_serialized_values.merge(
"resource_action" => "serialized resource action",
"options" => {
:category_id => "123",
:category_name => "best category ever",
:category_description => "best category ever"
}
))
context "without category" do
before do
allow(Category).to receive(:find_by).with(:id => "123").and_return(nil)
allow(dialog_field).to receive(:values).and_return("values")
end

it "serializes the category name" do
expect(dialog_field_serializer.serialize(dialog_field))
.to eq(expected_serialized_values.merge(
"resource_action" => "serialized resource action",
"options" => {
:category_id => "123",
}
))
end
end
end
end
Expand Down

0 comments on commit 0e006d1

Please sign in to comment.