Skip to content

Commit

Permalink
Merge pull request #17418 from kbrock/tag_category
Browse files Browse the repository at this point in the history
convert tag.category to a regular association
  • Loading branch information
Fryguy authored Jun 19, 2018
2 parents 900fdc4 + fe708cd commit f1ef359
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
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
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

0 comments on commit f1ef359

Please sign in to comment.