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

Validate towhat policy field #18032

Merged
merged 3 commits into from
Sep 28, 2018
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
11 changes: 11 additions & 0 deletions app/models/miq_policy.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# TODO: Import/Export support

class MiqPolicy < ApplicationRecord
TOWHAT_APPLIES_TO_CLASSES = %w(ContainerGroup
ContainerImage
ContainerNode
ContainerProject
ContainerReplicator
ExtManagementSystem
Host
PhysicalServer
Vm).freeze

acts_as_miq_taggable
acts_as_miq_set_member
include_concern 'ImportExport'
Expand Down Expand Up @@ -29,6 +39,7 @@ class MiqPolicy < ApplicationRecord
validates_presence_of :name, :description, :guid
validates_uniqueness_of :name, :description, :guid
validates :mode, :inclusion => { :in => %w(compliance control) }
validates :towhat, :inclusion => { :in => TOWHAT_APPLIES_TO_CLASSES }

scope :with_mode, ->(mode) { where(:mode => mode) }
scope :with_towhat, ->(towhat) { where(:towhat => towhat) }
Expand Down
10 changes: 10 additions & 0 deletions spec/models/miq_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,14 @@
)
end
end

context '.validates' do
it 'validates towhat' do
expect(FactoryGirl.build(:miq_policy, :towhat => "Host")).to be_valid
end

it 'reports invalid towhat' do
expect(FactoryGirl.build(:miq_policy, :towhat => "BobsYourUncle")).not_to be_valid
end
end
end