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

46 lines
1.8 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) }
2016-01-12 12:01:07 +03:00
let(:string_with_dash) { 'asd-asd' }
let(:string_with_slash) { 'asd/asd' }
let(:string_with_parenthesis) { 'centos 6.5 x86_64 (development instance)' }
2018-04-04 22:44:39 +03:00
let(:provider_instance) { double('provider instance', images: ['image']) }
let(:available_images) { ['test_image', string_with_dash, string_with_slash, string_with_parenthesis] }
2015-11-03 11:46:54 +03:00
before do
2018-04-04 22:44:39 +03:00
allow(Devops::Model::Filter).to receive(:available_images) { available_images }
allow(Provider).to receive(:get_connector) { provider_instance }
2015-11-03 11:46:54 +03:00
end
describe 'validation', stubbed_logger: true do
2018-04-04 22:44:39 +03:00
it 'is valid with correct attrs' do
expect(image).to be_valid
end
include_examples 'field type validation', :remote_user, :not_nil, :non_empty_string
include_examples 'field type validation', :name, :not_nil, :non_empty_string
2015-11-03 11:46:54 +03:00
it 'id should contain only letters, digits and dashes' do
2018-04-04 22:44:39 +03:00
expect(build(:image, image_id: string_with_dash)).to be_valid
expect(build(:image, image_id: string_with_slash)).not_to be_valid
expect(build(:image, image_id: string_with_parenthesis)).not_to be_valid
2015-11-03 11:46:54 +03:00
end
it "id should be included in image filters" do
2018-04-04 22:44:39 +03:00
expect(build(:image, image_id: 'wrong')).not_to be_valid
2015-11-03 11:46:54 +03:00
end
2016-01-12 12:01:07 +03:00
it 'name may contain everything' do
expect(build(:image, name: string_with_dash)).to be_valid
expect(build(:image, name: string_with_slash)).to be_valid
expect(build(:image, name: string_with_parenthesis)).to be_valid
end
2018-04-04 22:44:39 +03:00
it 'remote_user should contain only a-zA-Z0-9_-' do
expect(build(:image, remote_user: 'aA0-')).to be_valid
2015-11-30 16:56:54 +03:00
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
end