53 lines
1.7 KiB
Ruby
53 lines
1.7 KiB
Ruby
|
|
RSpec.shared_examples 'stack template' do
|
||
|
|
validated_model_name = described_class.name.demodulize.underscore
|
||
|
|
|
||
|
|
it 'is valid with factory attrs' do
|
||
|
|
expect(build(validated_model_name)).to be_valid
|
||
|
|
end
|
||
|
|
|
||
|
|
describe 'validation rules' do
|
||
|
|
include_examples 'field type validation', :id, :not_nil, :non_empty_string, :only_word_symbols, :field_validator
|
||
|
|
include_examples 'field type validation', :provider, :not_nil, :non_empty_string, :field_validator
|
||
|
|
include_examples 'field type validation', :template_body, :not_nil, :non_empty_string, :field_validator
|
||
|
|
include_examples 'field type validation', :owner, :not_nil, :non_empty_string, :field_validator
|
||
|
|
end
|
||
|
|
|
||
|
|
describe '#to_hash_without_id' do
|
||
|
|
it 'returns hash with provider, template_body and owner' do
|
||
|
|
expect(stack_template.to_hash_without_id).to include(:provider, :template_body, :owner)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
describe '.create' do
|
||
|
|
it "returns instance of #{described_class.name}" do
|
||
|
|
params = {
|
||
|
|
'id' => 'foo',
|
||
|
|
'template_body' => '{}',
|
||
|
|
'owner' => 'root',
|
||
|
|
'provider' => 'ec2'
|
||
|
|
}
|
||
|
|
expect(described_class.create(params)).to be_an_instance_of(described_class)
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
describe '#build_from_bson' do
|
||
|
|
let(:params) { {
|
||
|
|
'_id' => 'foo',
|
||
|
|
'template_body' => '{}',
|
||
|
|
'owner' => 'root',
|
||
|
|
'provider' => 'ec2'
|
||
|
|
}}
|
||
|
|
|
||
|
|
subject { described_class.build_from_bson(params) }
|
||
|
|
|
||
|
|
it 'sets id from _id' do
|
||
|
|
expect(subject.id).to eq 'foo'
|
||
|
|
end
|
||
|
|
|
||
|
|
it 'sets other params from given hash' do
|
||
|
|
expect(subject.template_body).to eq '{}'
|
||
|
|
expect(subject.owner).to eq 'root'
|
||
|
|
expect(subject.provider).to eq 'ec2'
|
||
|
|
end
|
||
|
|
end
|
||
|
|
end
|