Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/spec/models/mdm/workspace_spec.rb
Views: 11779
RSpec.describe Mdm::Workspace, type: :model do1subject(:workspace) do2Mdm::Workspace.new3end45context 'validations' do6context 'boundary' do7let(:boundary) do8nil9end1011let(:error) do12'must be a valid IP range'13end1415context 'when the workspace is limited to a network' do16before(:example) do17workspace.boundary = boundary18workspace.limit_to_network = true19workspace.valid?20end2122it 'should validate using #boundary_must_be_ip_range' do23expect(workspace).to receive(:boundary_must_be_ip_range).and_return(false)2425workspace.valid?26end2728context 'with valid IP' do29let(:boundary) do30'192.168.0.1'31end3233it 'should not record an error' do34expect(workspace.errors[:boundary]).not_to include(error)35end36end3738context 'with valid range' do39let(:boundary) do40'192.168.0.1/24'41end4243it 'should not record an error' do44expect(workspace.errors[:boundary]).not_to include(error)45end46end4748context 'with invalid IP or range' do49let(:boundary) do50'192.168'51end5253it 'should record error that boundary must be a valid IP range' do54expect(workspace).not_to be_valid55expect(workspace.errors[:boundary]).to include(error)56end57end58end5960context 'when the workspace is not network limited' do61before(:example) do62workspace.boundary = boundary63workspace.valid?64end6566it 'should not care about the value of the boundary' do67expect(workspace.errors[:boundary]).not_to include(error)68end69end70end71end7273context 'methods' do74context '#valid_ip_or_range?' do75let(:ip_or_range) do76nil77end7879subject(:valid_ip_or_range?) { workspace.send(:valid_ip_or_range?, ip_or_range) }8081context 'with exception from Rex::Socket::RangeWalker' do82before(:example) do83allow(Rex::Socket::RangeWalker).to receive(:new).with(ip_or_range).and_raise(StandardError)84end8586it { expect { valid_ip_or_range? }.to raise_error(StandardError) }87end8889context 'without exception from Rex::Socket::RangeWalker' do90context 'with valid IP' do91let(:ip_or_range) do92'192.168.0.1'93end9495it { expect(valid_ip_or_range?).to be_truthy }96end97end98end99end100101102it_should_behave_like 'Mdm::Workspace::Boundary'103end104105106