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

Skip tags without classification in assigments #17883

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
3 changes: 2 additions & 1 deletion app/models/mixins/assignment_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def get_assigned_tos
result[:objects] << object unless object.nil?
when :tag
tag = Tag.find_by(:name => "/" + parts.join("/"))
result[:tags] << [Classification.find_by(:tag_id => tag.id), klass] unless tag.nil?
classification = Classification.find_by(:tag_id => tag.id) if tag
result[:tags] << [classification, klass] if classification
when :label
label = if AssignmentMixin.escaped?(parts[1])
name = AssignmentMixin.unescape(parts[1])
Expand Down
20 changes: 15 additions & 5 deletions spec/models/mixins/assignment_mixin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,29 @@
end

describe "#get_assigned_tos" do
it "returns objects and tags" do
cc_classification = FactoryGirl.create(:classification_cost_center)
classification_tag = FactoryGirl.create(:classification_tag, :parent => cc_classification)
vm = FactoryGirl.create(:vm)
alert_set = FactoryGirl.create(:miq_alert_set)
let(:cc_classification) { FactoryGirl.create(:classification_cost_center) }
let(:classification_tag) { FactoryGirl.create(:classification_tag, :parent => cc_classification) }
let(:vm) { FactoryGirl.create(:vm) }
let(:alert_set) { FactoryGirl.create(:miq_alert_set) }

before do
alert_set.assign_to_objects([vm])
alert_set.assign_to_tags([classification_tag], "vms")
end

it "returns objects and tags" do
assigned_tos = alert_set.get_assigned_tos
expect(assigned_tos[:objects]).to include(vm)
expect(assigned_tos[:tags]).to include([classification_tag, "vms"])
end

it "doesn't return tags when classification is missing" do
classification_tag.destroy

assigned_tos = alert_set.get_assigned_tos
expect(assigned_tos[:objects]).to include(vm)
expect(alert_set.get_assigned_tos[:tags]).to be_empty
end
end

describe ".all_assignments" do
Expand Down