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

Clarify the 'towhat' inclusion validation message on policy creation. #18338

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/miq_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ 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 }
validates :towhat, :inclusion => { :in => TOWHAT_APPLIES_TO_CLASSES,
:message => "should be one of #{TOWHAT_APPLIES_TO_CLASSES.join(", ")}" }

scope :with_mode, ->(mode) { where(:mode => mode) }
scope :with_towhat, ->(towhat) { where(:towhat => towhat) }
Expand Down
8 changes: 7 additions & 1 deletion spec/models/miq_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,13 @@
end

it 'reports invalid towhat' do
expect(FactoryBot.build(:miq_policy, :towhat => "BobsYourUncle")).not_to be_valid
policy = FactoryBot.build(:miq_policy, :towhat => "BobsYourUncle")
towhat_error = "should be one of ContainerGroup, ContainerImage, "\
"ContainerNode, ContainerProject, ContainerReplicator, "\
"ExtManagementSystem, Host, PhysicalServer, Vm"

expect(policy).not_to be_valid
expect(policy.errors.messages).to include(:towhat => [towhat_error])
end
end
end