Commit b497b0ce authored by Z.J. van de Weg's avatar Z.J. van de Weg

Incorporate feedback

parent 826862d4
...@@ -37,7 +37,7 @@ v 8.11.0 (unreleased) ...@@ -37,7 +37,7 @@ v 8.11.0 (unreleased)
- Update `timeago` plugin to use multiple string/locale settings - Update `timeago` plugin to use multiple string/locale settings
- Remove unused images (ClemMakesApps) - Remove unused images (ClemMakesApps)
- Limit git rev-list output count to one in forced push check - Limit git rev-list output count to one in forced push check
- Show deployment status on merge requests - Show deployment status on merge requests with external URLs
- Clean up unused routes (Josef Strzibny) - Clean up unused routes (Josef Strzibny)
- Fix issue on empty project to allow developers to only push to protected branches if given permission - Fix issue on empty project to allow developers to only push to protected branches if given permission
- Add green outline to New Branch button. !5447 (winniehell) - Add green outline to New Branch button. !5447 (winniehell)
......
...@@ -37,10 +37,10 @@ class Deployment < ActiveRecord::Base ...@@ -37,10 +37,10 @@ class Deployment < ActiveRecord::Base
deployable.try(:other_actions) deployable.try(:other_actions)
end end
def deployed_to(ref) def deployed_to?(ref)
commit = project.commit(ref) commit = project.commit(ref)
return false unless commit return false unless commit
project.repository.merge_base(commit.id, sha) == commit.id project.repository.is_ancestor?(commit.id, sha)
end end
end end
...@@ -26,9 +26,9 @@ class Environment < ActiveRecord::Base ...@@ -26,9 +26,9 @@ class Environment < ActiveRecord::Base
self.external_url = nil if self.external_url.blank? self.external_url = nil if self.external_url.blank?
end end
def deployed_to?(ref) def deployed_from?(ref)
return unless last_deployment return false unless last_deployment
last_deployment.deployed_to(ref) last_deployment.deployed_to?(ref)
end end
end end
...@@ -592,7 +592,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -592,7 +592,7 @@ class MergeRequest < ActiveRecord::Base
def environments def environments
target_project.environments.select do |environment| target_project.environments.select do |environment|
environment.deployed_to?(ref_path) environment.deployed_from?(ref_path)
end end
end end
......
...@@ -15,4 +15,24 @@ describe Deployment, models: true do ...@@ -15,4 +15,24 @@ describe Deployment, models: true do
it { is_expected.to validate_presence_of(:ref) } it { is_expected.to validate_presence_of(:ref) }
it { is_expected.to validate_presence_of(:sha) } it { is_expected.to validate_presence_of(:sha) }
describe '#deployed_to?' do
let(:project) { create(:project) }
let(:environment) { create(:environment, project: project) }
let(:deployment) do
create(:deployment, environment: environment, sha: '5f923865dde3436854e9ceb9cdb7815618d4e849')
end
context 'when there is no project commit' do
it 'returns false' do
expect(deployment.deployed_to?('random-branch')).to be false
end
end
context 'when they share the same tree branch' do
it 'returns true' do
expect(deployment.deployed_to?('HEAD')).to be true
end
end
end
end end
...@@ -30,4 +30,14 @@ describe Environment, models: true do ...@@ -30,4 +30,14 @@ describe Environment, models: true do
expect(env.external_url).to be_nil expect(env.external_url).to be_nil
end end
end end
describe '#deployed_from?' do
let(:environment) { create(:environment) }
context 'without a last deployment' do
it "returns false" do
expect(environment.deployed_from?('HEAD')).to be false
end
end
end
end end
...@@ -674,6 +674,21 @@ describe MergeRequest, models: true do ...@@ -674,6 +674,21 @@ describe MergeRequest, models: true do
end end
end end
describe "#environments" do
let(:project) { create(:project) }
let!(:deployment) { create(:deployment, environment: environment, sha: '5f923865dde3436854e9ceb9cdb7815618d4e849') }
let!(:environment) { create(:environment, project: project) }
let!(:environment1) { create(:environment, project: project) }
let(:merge_request) { create(:merge_request, source_project: project) }
it 'selects deployed environments' do
expect(merge_request.environments).to eq [environment]
end
end
describe "#reload_diff" do describe "#reload_diff" do
let(:note) { create(:diff_note_on_merge_request, project: subject.project, noteable: subject) } let(:note) { create(:diff_note_on_merge_request, project: subject.project, noteable: subject) }
......
...@@ -7,8 +7,10 @@ describe 'projects/merge_requests/widget/_heading' do ...@@ -7,8 +7,10 @@ describe 'projects/merge_requests/widget/_heading' do
let(:project) { merge_request.target_project } let(:project) { merge_request.target_project }
let(:merge_request) { create(:merge_request, :merged) } let(:merge_request) { create(:merge_request, :merged) }
let(:environment) { create(:environment, project: project) } let(:environment) { create(:environment, project: project) }
let!(:deployment) { create(:deployment, environment: environment, let!(:deployment) do
sha: 'a5391128b0ef5d21df5dd23d98557f4ef12fae20') } create(:deployment, environment: environment,
sha: 'a5391128b0ef5d21df5dd23d98557f4ef12fae20')
end
before do before do
assign(:merge_request, merge_request) assign(:merge_request, merge_request)
......
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