Skip to content

Commit

Permalink
remove category (reference classification instead)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrock committed Feb 26, 2019
1 parent cb18388 commit 4d4b680
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 45 deletions.
7 changes: 0 additions & 7 deletions app/models/category.rb

This file was deleted.

5 changes: 5 additions & 0 deletions app/models/classification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ def name
@name ||= tag2name(tag_name || tag.name)
end

# useful for categories
def tags
Tag.joins(:classification).where(:classifications => {:parent_id => id})
end

attr_writer :name

def find_entry_by_name(name, region_id = my_region_number)
Expand Down
4 changes: 2 additions & 2 deletions app/models/dialog_field_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def adjust_category(opts)

def find_category(opts)
if opts[:category_id]
cat = Category.find_by(:id => opts[:category_id])
cat = Classification.is_category.find_by(:id => opts[:category_id])
return cat if cat.try(:name) == opts[:category_name]
end
Category.find_by_name(opts[:category_name])
Classification.is_category.find_by_name(opts[:category_name])
end
end
2 changes: 1 addition & 1 deletion app/models/dialog_field_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def serialize(dialog_field, all_attributes = false)
end

if dialog_field.type == "DialogFieldTagControl"
category = Category.find_by(:id => dialog_field.category)
category = Classification.is_category.find_by(:id => dialog_field.category)
if category
dialog_field.options.merge!(:category_name => category.name, :category_description => category.description)
dialog_field.options[:force_single_value] = dialog_field.options[:force_single_value] || category.single_value
Expand Down
7 changes: 0 additions & 7 deletions spec/factories/categories.rb

This file was deleted.

18 changes: 0 additions & 18 deletions spec/models/category_spec.rb

This file was deleted.

10 changes: 5 additions & 5 deletions spec/models/dialog_field_importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
let(:category_description) { "best_category" }

context "when the category exists by name and description" do
before do
@existing_category = Category.create!(:name => "best_category", :description => "best_category")
let!(:category) do
Classification.is_category.create!(:name => "best_category", :description => "best_category")
end

context "when the category description does not match" do
Expand All @@ -104,7 +104,7 @@
context "when the category description matches" do
it "uses the correct category, ignoring id" do
dialog_field_importer.import_field(dialog_field)
expect(DialogFieldTagControl.first.category).to eq(@existing_category.id.to_s)
expect(DialogFieldTagControl.first.category).to eq(category.id.to_s)
end
end
end
Expand All @@ -124,8 +124,8 @@

context "when the import file contains a category_id" do
before do
@first_category = Category.create!(:name => "first_category", :description => "first_category")
@existing_category = Category.create!(:name => "best_category", :description => "best_category")
@first_category = Classification.is_category.create!(:name => "first_category", :description => "first_category")
@existing_category = Classification.is_category.create!(:name => "best_category", :description => "best_category")
end

let(:options) do
Expand Down
9 changes: 4 additions & 5 deletions spec/models/dialog_field_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,13 @@
end

let(:type) { "DialogFieldTagControl" }
let(:options) { {:category_id => "123", :force_single_value => false} }
let(:options) { {:category_id => category.id.to_s, :force_single_value => false} }
let(:dynamic) { false }
let(:category) do
double("Category", :name => "best category ever", :description => "best category ever", :single_value => true)
Classification.is_category.create!(:name => "best_category_ever", :description => "best category ever", :single_value => true)
end

before do
allow(Category).to receive(:find_by).with(:id => "123").and_return(category)
allow(dialog_field).to receive(:values).and_return("values")
end

Expand All @@ -165,8 +164,8 @@
"resource_action" => "serialized resource action",
"dialog_field_responders" => dialog_field_responders,
"options" => {
:category_id => "123",
:category_name => "best category ever",
:category_id => category.id.to_s,
:category_name => "best_category_ever",
:category_description => "best category ever",
:force_single_value => true
},
Expand Down

0 comments on commit 4d4b680

Please sign in to comment.