Skip to content
Snippets Groups Projects
Commit 303faf35 authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg
Browse files

Reintroduce tests after removing them

In previous commits on this branch I've removed methods and their tests.
Now these methods where used by another branch so I needed to
reintroduce them.
parent 0b1eadc5
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -378,10 +378,12 @@ class Projects::MergeRequestsController < Projects::ApplicationController
 
if deployments
deployments = deployments.map do |deployment|
project = deployment.project
deployment = {
environment_name: deployment.environment.name,
environment_id: deployment.environment.id,
environment_url: namespace_project_environment_path(@project.namespace, @project, deployment.environment),
environment_url: namespace_project_environment_path(project.namespace, project, deployment.environment),
external_url: deployment.environment.external_url,
created_at: deployment.created_at,
created_at_formatted: deployment.created_at.to_time.in_time_zone.to_s(:medium)
Loading
Loading
Loading
Loading
@@ -33,6 +33,12 @@ class Deployment < ActiveRecord::Base
project.repository.fetch_ref(project.repository.path_to_repo, ref, ref_path)
end
 
def includes_commit?(commit)
return false unless commit
project.repository.is_ancestor?(commit.id, sha)
end
def manual_actions
deployable.try(:other_actions)
end
Loading
Loading
Loading
Loading
@@ -38,6 +38,12 @@ class Environment < ActiveRecord::Base
end
end
 
def includes_commit?(commit)
return false unless last_deployment
last_deployment.includes_commit?(commit)
end
def deployment_id_for(commit)
ref = project.repository.ref_name_for_sha(ref_path, commit.sha)
 
Loading
Loading
Loading
Loading
@@ -15,4 +15,28 @@ describe Deployment, models: true do
 
it { is_expected.to validate_presence_of(:ref) }
it { is_expected.to validate_presence_of(:sha) }
describe '#includes_commit?' do
let(:project) { create(:project) }
let(:environment) { create(:environment, project: project) }
let(:deployment) do
create(:deployment, environment: environment, sha: project.commit.id)
end
context 'when there is no project commit' do
it 'returns false' do
commit = project.commit('feature')
expect(deployment.includes_commit?(commit)).to be false
end
end
context 'when they share the same tree branch' do
it 'returns true' do
commit = project.commit
expect(deployment.includes_commit?(commit)).to be true
end
end
end
end
Loading
Loading
@@ -31,6 +31,39 @@ describe Environment, models: true do
end
end
 
describe '#includes_commit?' do
context 'without a last deployment' do
it "returns false" do
expect(environment.includes_commit?('HEAD')).to be false
end
end
context 'with a last deployment' do
let(:project) { create(:project) }
let(:environment) { create(:environment, project: project) }
let!(:deployment) do
create(:deployment, environment: environment, sha: project.commit('master').id)
end
context 'in the same branch' do
it 'returns true' do
expect(environment.includes_commit?(RepoHelpers.sample_commit)).to be true
end
end
context 'not in the same branch' do
before do
deployment.update(sha: project.commit('feature').id)
end
it 'returns false' do
expect(environment.includes_commit?(RepoHelpers.sample_commit)).to be false
end
end
end
end
describe '#deployment_id_for' do
let(:project) { create(:project) }
let!(:environment) { create(:environment, project: project) }
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment