fluke/devops-service/spec/models/image_spec.rb

53 lines
2.1 KiB
Ruby
Raw Normal View History

2015-11-03 11:46:54 +03:00
require 'db/mongo/models/image'
RSpec.describe Devops::Model::Image, type: :model do
let(:image) { build(:image) }
let(:name_with_dash) { 'asd-asd' }
let(:name_with_slash) { 'asd/asd' }
before do
allow(Provider::ProviderFactory).to receive(:providers).and_return(%w(openstack ec2 static'))
allow_any_instance_of(Validators::Image::ImageInFilter).to receive(:available_images).and_return([{'id' => 'test_image'}, {'id' => name_with_dash}, {'id' => name_with_slash}])
end
it 'is valid with correct attrs' do
expect(image).to be_valid
end
describe 'validation' do
include_examples 'field type validation', :id, :not_nil, :non_empty_string, :field_validator
2015-11-30 16:56:54 +03:00
include_examples 'field type validation', :remote_user, :not_nil, :non_empty_string, :field_validator
2015-11-03 11:46:54 +03:00
include_examples 'field type validation', :name, :not_nil, :non_empty_string, :field_validator
include_examples 'field type validation', :bootstrap_template, :maybe_nil, :non_empty_string, :only_word_symbols, :field_validator
it 'id should contain only letters, digits and dashes' do
expect(build(:image, id: name_with_dash)).to be_valid
expect(build(:image, id: name_with_slash)).not_to be_valid
end
it "id should be included in image filters" do
expect(build(:image, id: 'wrong')).not_to be_valid
end
it 'name should contain only letters, digits and dashes' do
expect(build(:image, name: name_with_slash)).not_to be_valid
end
it 'bootstrap_template should be included in available bootstrap templates' do
expect(build(:image, bootstrap_template: 'wrong')).not_to be_valid
end
2015-11-30 16:56:54 +03:00
it 'remote_user should contain only a-zA-Z0-9_-.' do
expect(build(:image, remote_user: 'aA0-.')).to be_valid
expect(build(:image, remote_user: 'name/')).not_to be_valid
expect(build(:image, remote_user: 'name!')).not_to be_valid
end
2015-11-03 11:46:54 +03:00
end
it '#to_hash_without_id returns provider, name, remote_user and bootstrap_template' do
expect(image.to_hash_without_id.keys).to match_array(%w(provider name remote_user bootstrap_template))
end
end