47 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
		
		
			
		
	
	
			47 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			Ruby
		
	
	
	
	
	
|   | 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 | ||
|  |     include_examples 'field type validation', :remote_user, :not_nil, :non_empty_string, :only_word_symbols, :field_validator | ||
|  |     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 | ||
|  |   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 |