diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-11-03 23:39:37 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-11-03 23:39:37 +0800 |
commit | 1ae557c106e94c20742d0788dc7eb604603faa08 (patch) | |
tree | 5a3fb7c52bf5d733fd3e69765098a040884a48cc | |
parent | ee4c8b75de6b04a8c2ed755b1b409dab9f0536c5 (diff) | |
download | gitlab-ce-1ae557c106e94c20742d0788dc7eb604603faa08.tar.gz |
Merge status_for and status, feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7034#note_17742297
-rw-r--r-- | app/helpers/ci_status_helper.rb | 2 | ||||
-rw-r--r-- | app/models/commit.rb | 6 | ||||
-rw-r--r-- | app/views/projects/_last_commit.html.haml | 2 | ||||
-rw-r--r-- | app/views/projects/commits/_commit.html.haml | 4 | ||||
-rw-r--r-- | spec/models/commit_spec.rb | 70 |
5 files changed, 41 insertions, 43 deletions
diff --git a/app/helpers/ci_status_helper.rb b/app/helpers/ci_status_helper.rb index 7851949ccf0..3decedace4f 100644 --- a/app/helpers/ci_status_helper.rb +++ b/app/helpers/ci_status_helper.rb @@ -63,7 +63,7 @@ module CiStatusHelper render_status_with_link( 'commit', - commit.status_for(ref), + commit.status(ref), path, tooltip_placement: tooltip_placement) end diff --git a/app/models/commit.rb b/app/models/commit.rb index 20bb93f4663..1fbda6f6acc 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -230,11 +230,7 @@ class Commit project.pipelines.where(sha: sha) end - def status - status_for(nil) - end - - def status_for(ref) + def status(ref = nil) if @statuses.key?(ref) @statuses[ref] elsif ref diff --git a/app/views/projects/_last_commit.html.haml b/app/views/projects/_last_commit.html.haml index 593967d9310..8aa503159f9 100644 --- a/app/views/projects/_last_commit.html.haml +++ b/app/views/projects/_last_commit.html.haml @@ -1,4 +1,4 @@ -- status = commit.status_for(ref) +- status = commit.status(ref) - if status = link_to builds_namespace_project_commit_path(commit.project.namespace, commit.project, commit), class: "ci-status ci-#{status}" do = ci_icon_for_status(status) diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml index c5830b5b7f7..fd70de9c13d 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -18,14 +18,14 @@ %span.commit-row-message.visible-xs-inline · = commit.short_id - - if commit.status_for(ref) + - if commit.status(ref) .visible-xs-inline = render_commit_status(commit, ref: ref) - if commit.description? %a.text-expander.hidden-xs.js-toggle-button ... .commit-actions.hidden-xs - - if commit.status_for(ref) + - if commit.status(ref) = render_commit_status(commit, ref: ref) = clipboard_button(clipboard_text: commit.id) = link_to commit.short_id, namespace_project_commit_path(project.namespace, project, commit), class: "commit-short-id btn btn-transparent" diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb index 468e198e9ea..203fb6596a6 100644 --- a/spec/models/commit_spec.rb +++ b/spec/models/commit_spec.rb @@ -210,49 +210,51 @@ eos end describe '#status' do - shared_examples 'giving the status from pipeline' do - it do - expect(commit.status).to eq(Ci::Pipeline.status) + context 'without arguments for compound status' do + shared_examples 'giving the status from pipeline' do + it do + expect(commit.status).to eq(Ci::Pipeline.status) + end end - end - context 'with pipelines' do - let!(:pipeline) do - create(:ci_empty_pipeline, project: project, sha: commit.sha) - end + context 'with pipelines' do + let!(:pipeline) do + create(:ci_empty_pipeline, project: project, sha: commit.sha) + end - it_behaves_like 'giving the status from pipeline' - end + it_behaves_like 'giving the status from pipeline' + end - context 'without pipelines' do - it_behaves_like 'giving the status from pipeline' + context 'without pipelines' do + it_behaves_like 'giving the status from pipeline' + end end - end - describe '#status_for' do - let!(:pipeline_from_master) do - create(:ci_empty_pipeline, - project: project, - sha: commit.sha, - ref: 'master', - status: 'failed') - end + context 'when a particular ref is specified' do + let!(:pipeline_from_master) do + create(:ci_empty_pipeline, + project: project, + sha: commit.sha, + ref: 'master', + status: 'failed') + end - let!(:pipeline_from_fix) do - create(:ci_empty_pipeline, - project: project, - sha: commit.sha, - ref: 'fix', - status: 'success') - end + let!(:pipeline_from_fix) do + create(:ci_empty_pipeline, + project: project, + sha: commit.sha, + ref: 'fix', + status: 'success') + end - it 'gives pipelines from a particular branch' do - expect(commit.status_for('master')).to eq(pipeline_from_master.status) - expect(commit.status_for('fix')).to eq(pipeline_from_fix.status) - end + it 'gives pipelines from a particular branch' do + expect(commit.status('master')).to eq(pipeline_from_master.status) + expect(commit.status('fix')).to eq(pipeline_from_fix.status) + end - it 'gives compound status if ref is nil' do - expect(commit.status_for(nil)).to eq(commit.status) + it 'gives compound status if ref is nil' do + expect(commit.status(nil)).to eq(commit.status) + end end end |