From d7b6cafa85362ccb8a610e9a2db0a1f62f0d1373 Mon Sep 17 00:00:00 2001 From: Jillian Tullo Date: Wed, 21 Mar 2018 08:22:52 -0400 Subject: [PATCH] Expose get_assigned_tos as virtual attribute to allow access via the API --- app/models/miq_alert_set.rb | 2 ++ spec/models/mixins/assignment_mixin_spec.rb | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/app/models/miq_alert_set.rb b/app/models/miq_alert_set.rb index 753a43a93c0..cb50ac8a6f1 100644 --- a/app/models/miq_alert_set.rb +++ b/app/models/miq_alert_set.rb @@ -5,6 +5,8 @@ class MiqAlertSet < ApplicationRecord include AssignmentMixin + virtual_has_one :get_assigned_tos + def self.assigned_to_target(target, options = {}) get_assigned_for_target(target, options) end diff --git a/spec/models/mixins/assignment_mixin_spec.rb b/spec/models/mixins/assignment_mixin_spec.rb index 43edaf85a08..80ffbe2d08a 100644 --- a/spec/models/mixins/assignment_mixin_spec.rb +++ b/spec/models/mixins/assignment_mixin_spec.rb @@ -78,6 +78,22 @@ end 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) + + alert_set.assign_to_objects([vm]) + alert_set.assign_to_tags([classification_tag], "vms") + + assigned_tos = alert_set.get_assigned_tos + expect(assigned_tos[:objects]).to include(vm) + expect(assigned_tos[:tags]).to include([classification_tag, "vms"]) + end + end + describe ".all_assignments" do it "returns only tags representing assignments" do t1 = Tag.create(:name => "/chargeback_rate/assigned_to/vm/tag/managed/environment/any1")