Commit 2fb35639 authored by Igor Drozdov's avatar Igor Drozdov

Move MR view methods from model to helper

Methods which decide which title to display
depending on the state better fit in helper
rather that in model
parent f7f91373
......@@ -27,6 +27,16 @@ module MergeRequestsHelper
classes.join(' ')
end
def state_name_with_icon(merge_request)
if merge_request.merged?
[_("Merged"), "git-merge"]
elsif merge_request.closed?
[_("Closed"), "close"]
else
[_("Open"), "issue-open-m"]
end
end
def ci_build_details_path(merge_request)
build_url = merge_request.source_project.ci_service.build_page(merge_request.diff_head_sha, merge_request.source_branch)
return unless build_url
......
......@@ -1149,26 +1149,6 @@ class MergeRequest < ApplicationRecord
actual_head_pipeline.environments
end
def state_human_name
if merged?
"Merged"
elsif closed?
"Closed"
else
"Open"
end
end
def state_icon_name
if merged?
"git-merge"
elsif closed?
"close"
else
"issue-open-m"
end
end
def fetch_ref!
target_project.repository.fetch_source_branch!(source_project.repository, source_branch, ref_path)
end
......
- can_update_merge_request = can?(current_user, :update_merge_request, @merge_request)
- can_reopen_merge_request = can?(current_user, :reopen_merge_request, @merge_request)
- state_human_name, state_icon_name = state_name_with_icon(@merge_request)
- if @merge_request.closed_without_fork?
.alert.alert-danger
......@@ -8,9 +9,9 @@
.detail-page-header
.detail-page-header-body
.issuable-status-box.status-box{ class: status_box_class(@merge_request) }
= sprite_icon(@merge_request.state_icon_name, size: 16, css_class: 'd-block d-sm-none')
= sprite_icon(state_icon_name, size: 16, css_class: 'd-block d-sm-none')
%span.d-none.d-sm-block
= @merge_request.state_human_name
= state_human_name
.issuable-meta
- if @merge_request.discussion_locked?
......
......@@ -26,6 +26,31 @@ describe MergeRequestsHelper do
end
end
describe '#state_name_with_icon' do
using RSpec::Parameterized::TableSyntax
let(:merge_request) { MergeRequest.new }
where(:state, :expected_name, :expected_icon) do
:merged? | 'Merged' | 'git-merge'
:closed? | 'Closed' | 'close'
:opened? | 'Open' | 'issue-open-m'
end
with_them do
before do
allow(merge_request).to receive(state).and_return(true)
end
it 'returns name and icon' do
name, icon = helper.state_name_with_icon(merge_request)
expect(name).to eq(expected_name)
expect(icon).to eq(expected_icon)
end
end
end
describe '#format_mr_branch_names' do
describe 'within the same project' do
let(:merge_request) { create(: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