Skip to content

Commit

Permalink
Merge pull request #15513 from djberg96/validate_blacklist
Browse files Browse the repository at this point in the history
Add validate_blacklist method for VM pre-provisioning
(cherry picked from commit 34cab60)

https://bugzilla.redhat.com/show_bug.cgi?id=1478563
  • Loading branch information
gmcculloug authored and simaishi committed Aug 4, 2017
1 parent bb075a7 commit 0c39c46
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/models/miq_request_workflow/dialog_field_validation.rb
Expand Up @@ -37,4 +37,12 @@ def validate_regex(_field, _values, dlg, fld, value)
error
end
end

def validate_blacklist(_field, _values, dlg, fld, value)
blacklist = fld[:blacklist]
return _("%{name} is required") % {:name => required_description(dlg, fld)} if value.blank?
if blacklist && blacklist.include?(value)
_("%{name} may not contain blacklisted value") % {:name => required_description(dlg, fld)}
end
end
end
16 changes: 16 additions & 0 deletions spec/models/miq_request_workflow_spec.rb
Expand Up @@ -358,6 +358,22 @@
end
end

context "#validate_blacklist" do
let(:blacklist) { {:blacklist => ['foo', 'bar']} }

it "returns nil if the value is not blacklisted" do
expect(workflow.validate_blacklist(nil, {}, {}, blacklist, 'test')).to be_nil
end

it "returns a formatted message when the value is blacklisted" do
expect(workflow.validate_blacklist(nil, {}, {}, blacklist, 'foo')).to eq("'/' may not contain blacklisted value")
end

it "returns an error when no value exists" do
expect(workflow.validate_blacklist(nil, {}, {}, blacklist, '')).to eq "'/' is required"
end
end

context "#validate regex" do
let(:regex) { {:required_regex => "^n@test.com$"} }
let(:regex_two) { {:required_regex => "^n$"} }
Expand Down

0 comments on commit 0c39c46

Please sign in to comment.