Skip to content

Commit

Permalink
Merge pull request ManageIQ#18177 from juliancheal/fix_tags_without_c…
Browse files Browse the repository at this point in the history
…lassifications_errors

Tags without a classification cause errors
  • Loading branch information
gtanzillo authored Nov 9, 2018
2 parents a865a8d + 8bb45d6 commit 3217a89
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ def categorization
{}
else
{
"name" => classification.name,
"description" => classification.description,
"category" => {"name" => category.name, "description" => category.description},
"display_name" => "#{category.description}: #{classification.description}"
"name" => classification.try(:name),
"description" => classification.try(:description),
"category" => {"name" => category.try(:name), "description" => category.try(:description)},
"display_name" => "#{category.try(:description)}: #{classification.try(:description)}"
}
end
end
Expand Down
12 changes: 12 additions & 0 deletions spec/models/tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@
expect(categorization).to eq(expected_categorization)
end

it "tag with nil classification" do
@tag.classification = nil
categorization = @tag.categorization

expected_categorization = {"name" => nil,
"description" => nil,
"category" => {"name" => @category.name, "description" => @category.description},
"display_name" => "#{@category.description}: "}
expect(@tag.show).to eq(true)
expect(categorization).to eq(expected_categorization)
end

it "category tags have no category" do
category_tag = @tag.category.tag
expect(category_tag.category).to be_nil
Expand Down

0 comments on commit 3217a89

Please sign in to comment.