fluke/devops-service/spec/models/project_spec.rb
2015-12-05 12:34:12 +03:00

49 lines
1.6 KiB
Ruby

require 'db/mongo/models/project'
require_relative 'shared_models_context'
RSpec.describe Devops::Model::Project, type: :model do
let(:project) { build(:project) }
include_context 'stubbed calls to connector in env validators'
describe 'validation rules:' do
include_examples 'field type validation', :id, :not_nil, :non_empty_string
include_examples 'field type validation', :deploy_envs, :not_nil, :non_empty_array
include_examples 'field type validation', :description, :maybe_nil, :maybe_empty_string
include_examples 'field type validation', :run_list, :not_nil, :maybe_empty_array, :run_list
it "isn't valid when has envs with same identifier" do
project.deploy_envs << build(:deploy_env_ec2)
expect(project).not_to be_valid
end
it "is valid when all envs have uniq identifiers" do
project.deploy_envs << build(:deploy_env_ec2, identifier: 'new')
expect(project).to be_valid
end
it "isn't valid when at least one of envs isn't valid" do
project.deploy_envs << build(:deploy_env_ec2, identifier: nil)
expect(project).not_to be_valid
end
end
describe '.fields' do
subject { described_class.fields }
it { should eq %w(deploy_envs type description) }
end
describe '#initialize' do
it 'sets @type to generic by default' do
expect(described_class.new.type).to eq 'generic'
end
it 'sets @archived to false by default' do
expect(described_class.new.archived).to eq false
end
it 'sets run_list to empty_array by default' do
expect(described_class.new.run_list).to eq []
end
end
end