require 'db/mongo/models/stack_template/stack_template_ec2' require_relative 'shared_stack_template_specs' RSpec.describe Devops::Model::StackTemplateEc2, type: :model do let(:stack_template) { build(:stack_template_ec2) } before do allow(Provider::ProviderFactory).to receive(:providers).and_return(%w(ec2)) allow_any_instance_of(Devops::Model::StackTemplateEc2).to receive_message_chain('provider_instance.validate_stack_template') { true } allow_any_instance_of(Devops::Model::StackTemplateEc2).to receive_message_chain('provider_instance.store_stack_template') { {'url' => nil} } end it_behaves_like 'stack template' it 'uploads file to S3' do expect_any_instance_of(Devops::Model::StackTemplateEc2).to receive_message_chain('provider_instance.store_stack_template') params = { 'id' => 'foo', 'template_body' => '{}', 'owner' => 'root', 'provider' => 'ec2' } expect(described_class.create(params)).to be_an_instance_of(described_class) end describe 'available parameters fetching' do let(:template_body) { %q( { "Description" : "Example", "Parameters" : { "KeyName": { "Description" : "Name of KeyPair", "Type": "AWS::EC2::KeyPair::KeyName" }, "SSHLocation" : { "Type": "String", "MinLength": "9" } } } ) } let(:template_attributes) { FactoryGirl.attributes_for(:stack_template_ec2, template_body: template_body) } let(:template) { described_class.create(template_attributes.stringify_keys) } it 'fetches parameters from template body' do expect(template.available_parameters).to be_a(Hash) expect(template.available_parameters).to include('KeyName', 'SSHLocation') end it 'parses description' do expect(template.available_parameters['KeyName']['description']).to eq 'Name of KeyPair' expect(template.available_parameters['SSHLocation']['description']).to be nil end end end