Move pro concern logic into framework

MS-1361
This commit is contained in:
Fernando Arias 2016-04-07 10:59:40 -05:00
parent 8de58e4b80
commit f5415c8058
No known key found for this signature in database
GPG Key ID: 89EC07CE01DF79A1
2 changed files with 17 additions and 5 deletions

View File

@ -38,12 +38,24 @@ module Mdm::Workspace::BoundaryRange
# Validates that {#boundary} is {#valid_ip_or_range? a valid IP address or
# IP address range}. Due to this not being tested before it was moved here
# from Mdm, the default workspace does not validate. We therefore don't
# validate boundaries of workspaces that don't use them.
# from Mdm, the default workspace does not validate. We always validate boundaries
# and a workspace may have a blank default boundary.
#
# @return [void]
def boundary_must_be_ip_range
errors.add(:boundary, "must be a valid IP range") unless !limit_to_network || valid_ip_or_range?(boundary)
unless boundary.blank?
begin
boundaries = Shellwords.split(boundary)
rescue ArgumentError
boundaries = []
end
boundaries.each do |range|
unless valid_ip_or_range?(range)
errors.add(:boundary, "must be a valid IP range")
end
end
end
end
private

View File

@ -20,8 +20,8 @@ RSpec.describe Mdm::Workspace, type: :model do
workspace.valid?
end
it 'should validate using #valid_ip_or_range?' do
expect(workspace).to receive(:valid_ip_or_range?).with(boundary).and_return(false)
it 'should validate using #boundary_must_be_ip_range' do
expect(workspace).to receive(:boundary_must_be_ip_range).and_return(false)
workspace.valid?
end