Skip to content

Commit

Permalink
Merge pull request ManageIQ#20430 from d-m-u/fix_get_policies
Browse files Browse the repository at this point in the history
get_policies should maybe return policies in the set as well as the set itself
  • Loading branch information
kbrock authored Aug 12, 2020
2 parents aa26b90 + 5a41715 commit 5f2a3a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/mixins/miq_policy_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_policies
.map { |t| t.split("/").first(2) }
.group_by(&:first)
.select { |klass, _ids| ["miq_policy", "miq_policy_set"].include?(klass) }
.flat_map { |klass, ids| klass.camelize.constantize.where(:id => ids).to_a }
.flat_map { |klass, ids| klass.camelize.constantize.where(:id => ids.map(&:last)).to_a }
end

def resolve_policies(list, event = nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
shared_examples_for "MiqPolicyMixin" do
context "MiqPolicyMixin methods" do
let(:policy) { FactoryBot.create(:miq_policy) }
let(:policy2) { FactoryBot.create(:miq_policy) }
let(:policy_set) { FactoryBot.create(:miq_policy_set).tap { |ps| ps.add_member(policy) } }
let(:policy_set) { FactoryBot.create(:miq_policy_set).tap { |ps| ps.add_member(policy2) } }

describe "#get_policies" do
it "supports no policies" do
Expand All @@ -15,8 +17,10 @@
end

it "supports policy sets" do
subject.add_policy(policy)
subject.add_policy(policy2)
subject.add_policy(policy_set)
expect(subject.get_policies).to eq([policy_set])
expect(subject.get_policies).to contain_exactly(policy_set, policy, policy2)
end
end

Expand Down

0 comments on commit 5f2a3a7

Please sign in to comment.