Commit febef4e8 authored by Igor Drozdov's avatar Igor Drozdov

Speed up push_options_handler_service_spec

Use let_it_be to create a project once
parent 2f94aec4
...@@ -5,9 +5,10 @@ require 'spec_helper' ...@@ -5,9 +5,10 @@ require 'spec_helper'
RSpec.describe MergeRequests::PushOptionsHandlerService do RSpec.describe MergeRequests::PushOptionsHandlerService do
include ProjectForksHelper include ProjectForksHelper
let(:user) { create(:user) } let_it_be(:project) { create(:project, :public, :repository) }
let(:project) { create(:project, :public, :repository) } let_it_be(:user) { create(:user, developer_projects: [project]) }
let(:forked_project) { fork_project(project, user, repository: true) } let_it_be(:forked_project) { fork_project(project, user, repository: true) }
let(:service) { described_class.new(project, user, changes, push_options) } let(:service) { described_class.new(project, user, changes, push_options) }
let(:source_branch) { 'fix' } let(:source_branch) { 'fix' }
let(:target_branch) { 'feature' } let(:target_branch) { 'feature' }
...@@ -21,28 +22,14 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do ...@@ -21,28 +22,14 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do
let(:deleted_branch_changes) { "d14d6c0abdd253381df51a723d58691b2ee1ab08 #{Gitlab::Git::BLANK_SHA} refs/heads/#{source_branch}" } let(:deleted_branch_changes) { "d14d6c0abdd253381df51a723d58691b2ee1ab08 #{Gitlab::Git::BLANK_SHA} refs/heads/#{source_branch}" }
let(:default_branch_changes) { "d14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/#{project.default_branch}" } let(:default_branch_changes) { "d14d6c0abdd253381df51a723d58691b2ee1ab08 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/#{project.default_branch}" }
before do
project.add_developer(user)
end
shared_examples_for 'a service that can create a merge request' do shared_examples_for 'a service that can create a merge request' do
subject(:last_mr) { MergeRequest.last } subject(:last_mr) { MergeRequest.last }
it 'creates a merge request' do it 'creates a merge request with the correct target branch and assigned user' do
expect { service.execute }.to change { MergeRequest.count }.by(1)
end
it 'sets the correct target branch' do
branch = push_options[:target] || project.default_branch branch = push_options[:target] || project.default_branch
service.execute expect { service.execute }.to change { MergeRequest.count }.by(1)
expect(last_mr.target_branch).to eq(branch) expect(last_mr.target_branch).to eq(branch)
end
it 'assigns the MR to the user' do
service.execute
expect(last_mr.assignees).to contain_exactly(user) expect(last_mr.assignees).to contain_exactly(user)
end end
...@@ -54,15 +41,10 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do ...@@ -54,15 +41,10 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do
allow(forked_project).to receive(:empty_repo?).and_return(false) allow(forked_project).to receive(:empty_repo?).and_return(false)
end end
it 'sets the correct source project' do it 'sets the correct source and target project' do
service.execute service.execute
expect(last_mr.source_project).to eq(forked_project) expect(last_mr.source_project).to eq(forked_project)
end
it 'sets the correct target project' do
service.execute
expect(last_mr.target_project).to eq(project) expect(last_mr.target_project).to eq(project)
end end
end end
...@@ -746,6 +728,7 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do ...@@ -746,6 +728,7 @@ RSpec.describe MergeRequests::PushOptionsHandlerService do
end end
describe 'when MRs are not enabled' do describe 'when MRs are not enabled' do
let(:project) { create(:project, :public, :repository).tap { |pr| pr.add_developer(user) } }
let(:push_options) { { create: true } } let(:push_options) { { create: true } }
let(:changes) { new_branch_changes } let(:changes) { new_branch_changes }
......
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