Commit 2e7cb7f8 authored by Doug Stull's avatar Doug Stull

Prevent suggest pipeline showing on invalid states

- should not show when in non open state or when
  source branch does not exist, since the next step
  is to go to web ide on the source branch and
  create a file.
parent 31c13529
......@@ -95,7 +95,9 @@ class MergeRequestWidgetEntity < Grape::Entity
end
def can_add_ci_config_path?(merge_request)
merge_request.source_project&.uses_default_ci_config? &&
merge_request.open? &&
merge_request.source_branch_exists? &&
merge_request.source_project&.uses_default_ci_config? &&
!merge_request.source_project.has_ci? &&
merge_request.commits_count.positive? &&
can?(current_user, :read_build, merge_request.source_project) &&
......
......@@ -155,6 +155,36 @@ describe MergeRequestWidgetEntity do
expect(subject[:merge_request_add_ci_config_path]).to be_nil
end
end
context 'when merge request is merged' do
before do
resource.mark_as_merged!
end
it 'returns a blank ci config path' do
expect(subject[:merge_request_add_ci_config_path]).to be_nil
end
end
context 'when merge request is closed' do
before do
resource.close!
end
it 'returns a blank ci config path' do
expect(subject[:merge_request_add_ci_config_path]).to be_nil
end
end
context 'when source branch does not exist' do
before do
resource.source_project.repository.rm_branch(user, resource.source_branch)
end
it 'returns a blank ci config path' do
expect(subject[:merge_request_add_ci_config_path]).to be_nil
end
end
end
context 'when user does not have permissions' do
......
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