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

convert tag.category to a regular association #17418

Merged
merged 1 commit into from
Jun 19, 2018
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
6 changes: 1 addition & 5 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Tag < ApplicationRecord
has_many :taggings, :dependent => :destroy
has_one :classification
virtual_has_one :category, :class_name => "Classification"
has_one :category, :through => :classification, :source => :parent
virtual_has_one :categorization, :class_name => "Hash"

has_many :container_label_tag_mappings
Expand Down Expand Up @@ -137,10 +137,6 @@ def ==(comparison_object)
super || name.downcase == comparison_object.to_s.downcase
end

def category
@category ||= Classification.find_by_name(name_path.split('/').first, nil)
end

def show
category.try(:show)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def mapped_tag(category_name, tag_name)
mapping = FactoryGirl.create(:tag_mapping_with_category,
:category_name => category_name,
:category_description => category_name)
category = mapping.tag.category
category = mapping.tag.classification
Copy link
Member

Choose a reason for hiding this comment

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

Why does this have to change? The code is looking for the category, so it's surprising to ask for the classification

Copy link
Member Author

@kbrock kbrock May 21, 2018

Choose a reason for hiding this comment

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

Spoke with @cben about this (author of the test)

There is currently a bug in #category
name_path.split('/').first means it will return a category or classification.

This test was relying upon a bug in #category. Changing this line s/category/classification still passes the tests.

In this test, there is category/tag (which really translates to classification/category)

entry = category.add_entry(:name => tag_name, :description => tag_name)
entry.tag
end
Expand Down
5 changes: 5 additions & 0 deletions spec/models/tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@

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
end
end

describe ".find_by_classification_name" do
Expand Down