Commit fcf2ef6f authored by Doug Stull's avatar Doug Stull

Updates view specs for merge request show

- for prep in extending them in subsequent MR
- gain performance by using let_it_be
parent f4ef8ca3
...@@ -3,19 +3,10 @@ ...@@ -3,19 +3,10 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'projects/merge_requests/show.html.haml' do RSpec.describe 'projects/merge_requests/show.html.haml' do
before do include_context 'merge request show action'
allow(view).to receive(:experiment_enabled?).and_return(false)
end
include_context 'closed merge request show action'
context 'when merge request is created by a GitLab team member' do context 'when merge request is created by a GitLab team member' do
let(:user) { create(:user) }
include_context 'gitlab team member'
before do before do
allow(Gitlab).to receive(:com?).and_return(true)
allow(user).to receive(:gitlab_employee?).and_return(true) allow(user).to receive(:gitlab_employee?).and_return(true)
end end
......
# frozen_string_literal: true # frozen_string_literal: true
RSpec.shared_context 'open merge request show action' do RSpec.shared_context 'merge request show action' do
include Spec::Support::Helpers::Features::MergeRequestHelpers include Spec::Support::Helpers::Features::MergeRequestHelpers
let(:user) { create(:user) } let_it_be(:user) { create(:user) }
let(:project) { create(:project, :public, :repository) } let_it_be(:project) { create(:project, :public, :repository) }
let(:note) { create(:note_on_merge_request, project: project, noteable: open_merge_request) } let_it_be(:merge_request) { create(:merge_request, :opened, source_project: project, author: user) }
let_it_be(:note) { create(:note_on_merge_request, project: project, noteable: merge_request) }
let(:open_merge_request) do
create(:merge_request, :opened, source_project: project, author: user)
end
before do
assign(:project, project)
assign(:merge_request, open_merge_request)
assign(:note, note)
assign(:noteable, open_merge_request)
assign(:notes, [])
assign(:pipelines, Ci::Pipeline.none)
assign(:issuable_sidebar, serialize_issuable_sidebar(user, project, open_merge_request))
preload_view_requirements(open_merge_request, note)
sign_in(user)
end
end
RSpec.shared_context 'closed merge request show action' do
include Devise::Test::ControllerHelpers
include ProjectForksHelper
include Spec::Support::Helpers::Features::MergeRequestHelpers
let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository) }
let(:forked_project) { fork_project(project, user, repository: true) }
let(:unlink_project) { Projects::UnlinkForkService.new(forked_project, user) }
let(:note) { create(:note_on_merge_request, project: project, noteable: closed_merge_request) }
let(:closed_merge_request) do
create(:closed_merge_request,
source_project: forked_project,
target_project: project,
author: user)
end
before do before do
allow(view).to receive(:experiment_enabled?).and_return(false)
allow(view).to receive(:current_user).and_return(user)
assign(:project, project) assign(:project, project)
assign(:merge_request, closed_merge_request) assign(:merge_request, merge_request)
assign(:commits_count, 0)
assign(:note, note) assign(:note, note)
assign(:noteable, closed_merge_request) assign(:noteable, merge_request)
assign(:notes, []) assign(:pipelines, [])
assign(:pipelines, Ci::Pipeline.none) assign(:issuable_sidebar, serialize_issuable_sidebar(user, project, merge_request))
assign(:issuable_sidebar, serialize_issuable_sidebar(user, project, closed_merge_request))
preload_view_requirements(closed_merge_request, note)
allow(view).to receive_messages(current_user: user, preload_view_requirements(merge_request, note)
can?: true,
current_application_settings: Gitlab::CurrentSettings.current_application_settings)
end end
end end
...@@ -2,16 +2,14 @@ ...@@ -2,16 +2,14 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'projects/merge_requests/show.html.haml' do RSpec.describe 'projects/merge_requests/show.html.haml', :aggregate_failures do
include Spec::Support::Helpers::Features::MergeRequestHelpers include_context 'merge request show action'
before do before do
allow(view).to receive(:experiment_enabled?).and_return(false) merge_request.reload
end end
context 'when the merge request is open' do context 'when the merge request is open' do
include_context 'open merge request show action'
it 'shows the "Mark as draft" button' do it 'shows the "Mark as draft" button' do
render render
...@@ -22,20 +20,8 @@ RSpec.describe 'projects/merge_requests/show.html.haml' do ...@@ -22,20 +20,8 @@ RSpec.describe 'projects/merge_requests/show.html.haml' do
end end
context 'when the merge request is closed' do context 'when the merge request is closed' do
include_context 'closed merge request show action' before do
merge_request.close!
describe 'merge request assignee sidebar' do
context 'when assignee is allowed to merge' do
it 'does not show a warning icon' do
closed_merge_request.update!(assignee_id: user.id)
project.add_maintainer(user)
assign(:issuable_sidebar, serialize_issuable_sidebar(user, project, closed_merge_request))
render
expect(rendered).not_to have_css('.merge-icon')
end
end
end end
it 'shows the "Reopen" button' do it 'shows the "Reopen" button' do
...@@ -46,15 +32,15 @@ RSpec.describe 'projects/merge_requests/show.html.haml' do ...@@ -46,15 +32,15 @@ RSpec.describe 'projects/merge_requests/show.html.haml' do
expect(rendered).to have_css('a', visible: false, text: 'Close') expect(rendered).to have_css('a', visible: false, text: 'Close')
end end
it 'does not show the "Reopen" button when the source project does not exist' do context 'when source project does not exist' do
unlink_project.execute it 'does not show the "Reopen" button' do
closed_merge_request.reload allow(merge_request).to receive(:source_project).and_return(nil)
preload_view_requirements(closed_merge_request, note)
render render
expect(rendered).to have_css('a', visible: false, text: 'Reopen') expect(rendered).to have_css('a', visible: false, text: 'Reopen')
expect(rendered).to have_css('a', visible: false, text: 'Close') expect(rendered).to have_css('a', visible: false, text: 'Close')
end
end end
end end
end end
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