2016-06-14 07:51:12 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Environment, models: true do
|
|
|
|
let(:environment) { create(:environment) }
|
|
|
|
|
|
|
|
it { is_expected.to belong_to(:project) }
|
|
|
|
it { is_expected.to have_many(:deployments) }
|
|
|
|
|
|
|
|
it { is_expected.to delegate_method(:last_deployment).to(:deployments).as(:last) }
|
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of(:name) }
|
|
|
|
it { is_expected.to validate_uniqueness_of(:name).scoped_to(:project_id) }
|
|
|
|
it { is_expected.to validate_length_of(:name).is_within(0..255) }
|
2016-07-26 03:35:47 -04:00
|
|
|
|
|
|
|
it { is_expected.to validate_length_of(:external_url).is_within(0..255) }
|
|
|
|
|
|
|
|
# To circumvent a not null violation of the name column:
|
|
|
|
# https://github.com/thoughtbot/shoulda-matchers/issues/336
|
|
|
|
it 'validates uniqueness of :external_url' do
|
|
|
|
create(:environment)
|
|
|
|
|
|
|
|
is_expected.to validate_uniqueness_of(:external_url).scoped_to(:project_id)
|
|
|
|
end
|
2016-07-26 08:19:37 -04:00
|
|
|
|
|
|
|
describe '#nullify_external_url' do
|
|
|
|
it 'replaces a blank url with nil' do
|
|
|
|
env = build(:environment, external_url: "")
|
|
|
|
|
|
|
|
expect(env.save).to be true
|
2016-07-29 06:14:36 -04:00
|
|
|
expect(env.external_url).to be_nil
|
2016-07-26 08:19:37 -04:00
|
|
|
end
|
|
|
|
end
|
2016-06-14 07:51:12 -04:00
|
|
|
end
|