Skip to content

Commit

Permalink
Merge pull request #20214 from kbrock/undo_tag_missing_exception
Browse files Browse the repository at this point in the history
Revert "Merge pull request #20197 from yrudman/provide-descriptive-me…
  • Loading branch information
Fryguy committed May 27, 2020
2 parents 598eede + a3156fd commit abc255d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 41 deletions.
12 changes: 4 additions & 8 deletions app/models/classification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,10 @@ def ns

def self.classify(obj, category_name, entry_name, is_request = true)
cat = Classification.lookup_by_name(category_name, obj.region_id)
raise "Tag category '#{category_name}' not found in region #{obj.region_id}" if cat.nil?

ent = cat.find_entry_by_name(entry_name, obj.region_id)
raise "Tag name '#{entry_name}' not found in region #{obj.region_id}" if ent.nil?

raise "Object already tagged with ':ns' set to 'none'" if obj.is_tagged_with?(ent.to_tag, :ns => "none")

ent.assign_entry_to(obj, is_request)
unless cat.nil?
ent = cat.find_entry_by_name(entry_name, obj.region_id)
ent.assign_entry_to(obj, is_request) unless ent.nil? || obj.is_tagged_with?(ent.to_tag, :ns => "none")
end
end

def self.unclassify(obj, category_name, entry_name, is_request = true)
Expand Down
33 changes: 0 additions & 33 deletions spec/models/classification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,39 +61,6 @@
FactoryBot.create(:classification_tag, :name => "multi_entry_2", :parent => parent)
end

describe ".classify" do
let(:entry) { "test_entry" }
let(:category) { "test_category" }
before { @vm = FactoryBot.create(:vm) }

it "raise error if tag category not found" do
category = "Hello, World"
expect { Classification.classify(@vm, category, entry) }.to raise_error(
RuntimeError, "Tag category '#{category}' not found in region #{@vm.region_id}"
)
end

it "raise error if tag entry not found" do
entry = "Hello, World"
expect { Classification.classify(@vm, category, entry) }.to raise_error(
RuntimeError, "Tag name '#{entry}' not found in region #{@vm.region_id}"
)
end

it "raise error if object already tagged with tag namespace set to 'none'" do
allow(@vm).to receive(:is_tagged_with?)
allow(@vm).to receive(:is_tagged_with?).with("/managed/test_category/test_entry", :ns => "none").and_return(true)
expect { Classification.classify(@vm, category, entry) }.to raise_error(
RuntimeError, "Object already tagged with ':ns' set to 'none'"
)
end

it "assign tag entry to object if tag category and tag name exist" do
Classification.classify(@vm, category, entry)
expect(@vm.tags.first.name).to eq("/managed/test_category/test_entry")
end
end

context "#destroy" do
it "a category deletes all entries" do
cat = Classification.lookup_by_name("test_category")
Expand Down

0 comments on commit abc255d

Please sign in to comment.