Commit 7fd0baf2 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '6543-extract-ee-specific-files-lines-for-some-discussion-tests' into 'master'

Resolve "Extract EE specific files/lines for some discussion tests"

Closes #6543

See merge request gitlab-org/gitlab-ee!10407
parents 19ef8c5d 91ec7f2b
...@@ -15,6 +15,28 @@ describe Boards::Issues::CreateService do ...@@ -15,6 +15,28 @@ describe Boards::Issues::CreateService do
project.add_developer(user) project.add_developer(user)
end end
context 'saved board configuration' do
let(:list) { create(:list, board: board, label: label, position: 0) }
it 'adds the board assignee, weight, labels and milestone to the issue' do
board_assignee = create(:user)
project.add_developer(board_assignee)
board_milestone = create(:milestone, project: project)
board_label = create(:label, project: project)
board.update!(assignee: board_assignee,
milestone: board_milestone,
label_ids: [board_label.id],
weight: 4)
issue = service.execute
expect(issue.assignees).to eq([board_assignee])
expect(issue.weight).to eq(board.weight)
expect(issue.milestone).to eq(board_milestone)
expect(issue.labels).to contain_exactly(label, board_label)
end
end
context 'assignees list' do context 'assignees list' do
before do before do
stub_licensed_features(board_assignee_lists: true) stub_licensed_features(board_assignee_lists: true)
......
...@@ -7,14 +7,33 @@ describe Issues::MoveService do ...@@ -7,14 +7,33 @@ describe Issues::MoveService do
let(:old_issue) { create(:issue, project: old_project, author: user) } let(:old_issue) { create(:issue, project: old_project, author: user) }
let(:move_service) { described_class.new(old_project, user) } let(:move_service) { described_class.new(old_project, user) }
before do
old_project.add_reporter(user)
new_project.add_reporter(user)
end
describe '#execute' do
context 'group issue hooks' do
let!(:hook) { create(:group_hook, group: new_project.group, issues_events: true) }
it 'executes group issue hooks' do
allow_any_instance_of(WebHookService).to receive(:execute)
# Ideally, we'd test that `WebHookWorker.jobs.size` increased by 1,
# but since the entire spec run takes place in a transaction, we never
# actually get to the `after_commit` hook that queues these jobs.
expect { move_service.execute(old_issue, new_project) }
.not_to raise_error # Sidekiq::Worker::EnqueueFromTransactionError
end
end
end
describe '#rewrite_epic_issue' do describe '#rewrite_epic_issue' do
context 'issue assigned to epic' do context 'issue assigned to epic' do
let!(:epic_issue) { create(:epic_issue, issue: old_issue) } let!(:epic_issue) { create(:epic_issue, issue: old_issue) }
before do before do
stub_licensed_features(epics: true) stub_licensed_features(epics: true)
old_project.add_reporter(user)
new_project.add_reporter(user)
end end
it 'updates epic issue reference' do it 'updates epic issue reference' do
......
require 'spec_helper' require 'spec_helper'
describe MergeRequestPresenter do describe MergeRequestPresenter do
let(:resource) { create :merge_request, source_project: project } let(:resource) { create(:merge_request, source_project: project) }
let(:project) { create(:project, :repository) } let(:project) { create(:project) }
let(:user) { create(:user) } let(:user) { create(:user) }
describe '#ci_status' do describe '#ci_status' do
...@@ -416,45 +416,48 @@ describe MergeRequestPresenter do ...@@ -416,45 +416,48 @@ describe MergeRequestPresenter do
end end
end end
describe '#can_push_to_source_branch' do describe '#target_branch_path' do
before do
allow(resource).to receive(:source_branch_exists?) { source_branch_exists }
allow_any_instance_of(Gitlab::UserAccess::RequestCacheExtension)
.to receive(:can_push_to_branch?)
.with(resource.source_branch)
.and_return(can_push_to_branch)
end
subject do subject do
described_class.new(resource, current_user: user).can_push_to_source_branch? described_class.new(resource, current_user: user).target_branch_path
end end
context 'when source branch exists AND user can push to source branch' do context 'when target branch exists' do
let(:source_branch_exists) { true } it 'returns path' do
let(:can_push_to_branch) { true } allow(resource).to receive(:target_branch_exists?) { true }
it 'returns true' do is_expected
is_expected.to eq(true) .to eq("/#{resource.source_project.full_path}/branches/#{resource.target_branch}")
end end
end end
context 'when source branch does not exists' do context 'when target branch does not exist' do
let(:source_branch_exists) { false } it 'returns nil' do
let(:can_push_to_branch) { true } allow(resource).to receive(:target_branch_exists?) { false }
it 'returns false' do is_expected.to be_nil
is_expected.to eq(false)
end end
end end
end
context 'when user cannot push to source branch' do describe '#source_branch_with_namespace_link' do
let(:source_branch_exists) { true } subject do
let(:can_push_to_branch) { false } described_class.new(resource, current_user: user).source_branch_with_namespace_link
end
it 'returns false' do it 'returns link' do
is_expected.to eq(false) allow(resource).to receive(:source_branch_exists?) { true }
end
is_expected
.to eq("<a href=\"/#{resource.source_project.full_path}/tree/#{resource.source_branch}\">#{resource.source_branch}</a>")
end
it 'escapes html, when source_branch does not exist' do
xss_attempt = "<img src='x' onerror=alert('bad stuff') />"
allow(resource).to receive(:source_branch) { xss_attempt }
allow(resource).to receive(:source_branch_exists?) { false }
is_expected.to eq(ERB::Util.html_escape(xss_attempt))
end end
end end
...@@ -521,87 +524,44 @@ describe MergeRequestPresenter do ...@@ -521,87 +524,44 @@ describe MergeRequestPresenter do
end end
end end
describe '#source_branch_with_namespace_link' do describe '#can_push_to_source_branch' do
subject do
described_class.new(resource, current_user: user).source_branch_with_namespace_link
end
it 'returns link' do
allow(resource).to receive(:source_branch_exists?) { true }
is_expected
.to eq("<a href=\"/#{resource.source_project.full_path}/tree/#{resource.source_branch}\">#{resource.source_branch}</a>")
end
it 'escapes html, when source_branch does not exist' do
xss_attempt = "<img src='x' onerror=alert('bad stuff') />"
allow(resource).to receive(:source_branch) { xss_attempt }
allow(resource).to receive(:source_branch_exists?) { false }
is_expected.to eq(ERB::Util.html_escape(xss_attempt))
end
end
describe '#rebase_path' do
before do before do
allow(resource).to receive(:rebase_in_progress?) { rebase_in_progress } allow(resource).to receive(:source_branch_exists?) { source_branch_exists }
allow(resource).to receive(:should_be_rebased?) { should_be_rebased }
allow_any_instance_of(Gitlab::UserAccess::RequestCacheExtension) allow_any_instance_of(Gitlab::UserAccess::RequestCacheExtension)
.to receive(:can_push_to_branch?) .to receive(:can_push_to_branch?)
.with(resource.source_branch) .with(resource.source_branch)
.and_return(can_push_to_branch) .and_return(can_push_to_branch)
end end
subject do subject do
described_class.new(resource, current_user: user).rebase_path described_class.new(resource, current_user: user).can_push_to_source_branch?
end end
context 'when can rebase' do context 'when source branch exists AND user can push to source branch' do
let(:rebase_in_progress) { false } let(:source_branch_exists) { true }
let(:can_push_to_branch) { true } let(:can_push_to_branch) { true }
let(:should_be_rebased) { true }
before do
allow(resource).to receive(:source_branch_exists?) { true }
end
it 'returns path' do it 'returns true' do
is_expected is_expected.to eq(true)
.to eq("/#{project.full_path}/merge_requests/#{resource.iid}/rebase")
end end
end end
context 'when cannot rebase' do context 'when source branch does not exists' do
context 'when rebase in progress' do let(:source_branch_exists) { false }
let(:rebase_in_progress) { true } let(:can_push_to_branch) { true }
let(:can_push_to_branch) { true }
let(:should_be_rebased) { true }
it 'returns nil' do
is_expected.to be_nil
end
end
context 'when user cannot merge' do
let(:rebase_in_progress) { false }
let(:can_push_to_branch) { false }
let(:should_be_rebased) { true }
it 'returns nil' do it 'returns false' do
is_expected.to be_nil is_expected.to eq(false)
end
end end
end
context 'should not be rebased' do context 'when user cannot push to source branch' do
let(:rebase_in_progress) { false } let(:source_branch_exists) { true }
let(:can_push_to_branch) { true } let(:can_push_to_branch) { false }
let(:should_be_rebased) { false }
it 'returns nil' do it 'returns false' do
is_expected.to be_nil is_expected.to eq(false)
end
end end
end end
end end
......
...@@ -29,23 +29,5 @@ describe Boards::Issues::CreateService do ...@@ -29,23 +29,5 @@ describe Boards::Issues::CreateService do
expect(issue.labels).to eq [label] expect(issue.labels).to eq [label]
end end
it 'adds the board assignee, weight, labels and milestone to the issue' do
board_assignee = create(:user)
project.add_developer(board_assignee)
board_milestone = create(:milestone, project: project)
board_label = create(:label, project: project)
board.update!(assignee: board_assignee,
milestone: board_milestone,
label_ids: [board_label.id],
weight: 4)
issue = service.execute
expect(issue.assignees).to eq([board_assignee])
expect(issue.weight).to eq(board.weight)
expect(issue.milestone).to eq(board_milestone)
expect(issue.labels).to contain_exactly(label, board_label)
end
end end
end end
...@@ -138,20 +138,6 @@ describe Issues::MoveService do ...@@ -138,20 +138,6 @@ describe Issues::MoveService do
.not_to raise_error # Sidekiq::Worker::EnqueueFromTransactionError .not_to raise_error # Sidekiq::Worker::EnqueueFromTransactionError
end end
end end
context 'group issue hooks' do
let!(:hook) { create(:group_hook, group: new_project.group, issues_events: true) }
it 'executes group issue hooks' do
allow_any_instance_of(WebHookService).to receive(:execute)
# Ideally, we'd test that `WebHookWorker.jobs.size` increased by 1,
# but since the entire spec run takes place in a transaction, we never
# actually get to the `after_commit` hook that queues these jobs.
expect { move_service.execute(old_issue, new_project) }
.not_to raise_error # Sidekiq::Worker::EnqueueFromTransactionError
end
end
end end
describe 'move permissions' do describe 'move 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