diff --git a/app/models/tag.rb b/app/models/tag.rb index 9dff4733d60..68595258207 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -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 diff --git a/spec/models/tag_spec.rb b/spec/models/tag_spec.rb index 6b6e3da4054..fd241302dde 100644 --- a/spec/models/tag_spec.rb +++ b/spec/models/tag_spec.rb @@ -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