Commit d9d69d7b authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add specs for environments recently updated on branch

parent e49229aa
......@@ -38,7 +38,7 @@ class Environment < ActiveRecord::Base
end
def recently_updated_on_branch?(ref)
ref.to_s == last_deployment.ref
ref.to_s == last_deployment.try(:ref)
end
def last_deployment
......
......@@ -166,4 +166,25 @@ describe Environment, models: true do
end
end
end
describe 'recently_updated_on_branch?' do
subject { environment.recently_updated_on_branch?('feature') }
context 'when last deployment to environment is the most recent one' do
before do
create(:deployment, environment: environment, ref: 'feature')
end
it { is_expected.to be true }
end
context 'when last deployment to environment is not the most recent' do
before do
create(:deployment, environment: environment, ref: 'feature')
create(:deployment, environment: environment, ref: 'master')
end
it { is_expected.to be false }
end
end
end
......@@ -1688,6 +1688,48 @@ describe Project, models: true do
end
end
describe '#environments_recently_updated_on_branch' do
let(:project) { create(:project) }
let(:environment) { create(:environment, project: project) }
context 'when last deployment to environment is the most recent one' do
before do
create(:deployment, environment: environment, ref: 'feature')
end
it 'finds recently updated environment' do
expect(project.environments_recently_updated_on_branch('feature'))
.to contain_exactly(environment)
end
end
context 'when last deployment to environment is not the most recent' do
before do
create(:deployment, environment: environment, ref: 'feature')
create(:deployment, environment: environment, ref: 'master')
end
it 'does not find environment' do
expect(project.environments_recently_updated_on_branch('feature'))
.to be_empty
end
end
context 'when there are two environments that deploy to the same branch' do
let(:second_environment) { create(:environment, project: project) }
before do
create(:deployment, environment: environment, ref: 'feature')
create(:deployment, environment: second_environment, ref: 'feature')
end
it 'finds both environments' do
expect(project.environments_recently_updated_on_branch('feature'))
.to contain_exactly(environment, second_environment)
end
end
end
def enable_lfs
allow(Gitlab.config.lfs).to receive(:enabled).and_return(true)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment