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

Tags without a classification cause errors #18177

Merged
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
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
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this have been @tag.classification.delete?

If I do this and issue @tag.reload, I get:

  1) Tag categorization tag with nil classification
     Failure/Error: expect(@tag.show).to eq(true)

       expected: true
            got: nil

       (compared using ==)
     # ./spec/models/tag_spec.rb:117:in `block (3 levels) in <top (required)>'

Note, I'm here because rails 5.0 looks to have been returning a cached classification when @tag.categorization calls @tag.category in show. Because this was failing, I changed my tests locally to do @tag.classification.delete and it fails as shown above in both rails 5.0 and 5.1.

I'm not sure how any of the @category expectations are set, such as @category.name below:
To get to the category, you need to navigate through using @tag.classification.parent (what category does I think). If the classification is nil or deleted, category should also be nil, which would cause show to be nil.

😕

Copy link
Member

@jrafanie jrafanie Nov 16, 2018

Choose a reason for hiding this comment

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

In other words, I believe we're relying on @tag.category to return the cached parent of the classification's parent. If you delete the classification, it fails. If you upgrade to rails 5.1, the classification is nil so the category (classification parent) is also nil.

I believe this test is wrong. I think.

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