2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-04-02 06:38:35 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Issues::CreateService do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2014-04-02 06:38:35 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2016-04-21 07:40:52 -04:00
|
|
|
describe '#execute' do
|
|
|
|
let(:issue) { described_class.new(project, user, opts).execute }
|
2017-05-04 08:11:15 -04:00
|
|
|
let(:assignee) { create(:user) }
|
|
|
|
let(:milestone) { create(:milestone, project: project) }
|
2016-04-21 06:25:21 -04:00
|
|
|
|
2016-04-21 07:40:52 -04:00
|
|
|
context 'when params are valid' do
|
|
|
|
let(:labels) { create_pair(:label, project: project) }
|
2016-04-21 06:46:48 -04:00
|
|
|
|
2014-04-02 06:38:35 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
|
|
|
project.add_maintainer(assignee)
|
2016-04-21 06:25:21 -04:00
|
|
|
end
|
2016-02-15 13:13:52 -05:00
|
|
|
|
2016-04-21 06:25:21 -04:00
|
|
|
let(:opts) do
|
|
|
|
{ title: 'Awesome issue',
|
2016-02-15 13:13:52 -05:00
|
|
|
description: 'please fix',
|
2017-05-04 08:11:15 -04:00
|
|
|
assignee_ids: [assignee.id],
|
2016-04-21 06:46:48 -04:00
|
|
|
label_ids: labels.map(&:id),
|
2016-09-27 05:29:06 -04:00
|
|
|
milestone_id: milestone.id,
|
|
|
|
due_date: Date.tomorrow }
|
2014-04-02 06:38:35 -04:00
|
|
|
end
|
|
|
|
|
2016-09-27 05:29:06 -04:00
|
|
|
it 'creates the issue with the given params' do
|
|
|
|
expect(issue).to be_persisted
|
|
|
|
expect(issue.title).to eq('Awesome issue')
|
2017-05-04 08:11:15 -04:00
|
|
|
expect(issue.assignees).to eq [assignee]
|
2016-09-27 05:29:06 -04:00
|
|
|
expect(issue.labels).to match_array labels
|
|
|
|
expect(issue.milestone).to eq milestone
|
|
|
|
expect(issue.due_date).to eq Date.tomorrow
|
|
|
|
end
|
|
|
|
|
2017-09-19 07:55:56 -04:00
|
|
|
it 'refreshes the number of open issues', :use_clean_rails_memory_store_caching do
|
2017-08-17 11:21:25 -04:00
|
|
|
expect { issue }.to change { project.open_issues_count }.from(0).to(1)
|
|
|
|
end
|
|
|
|
|
2016-09-27 05:29:06 -04:00
|
|
|
context 'when current user cannot admin issues in the project' do
|
|
|
|
let(:guest) { create(:user) }
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2016-09-27 05:29:06 -04:00
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_guest(guest)
|
2016-09-27 05:29:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'filters out params that cannot be set without the :admin_issue permission' do
|
|
|
|
issue = described_class.new(project, guest, opts).execute
|
|
|
|
|
|
|
|
expect(issue).to be_persisted
|
|
|
|
expect(issue.title).to eq('Awesome issue')
|
2017-01-28 19:14:56 -05:00
|
|
|
expect(issue.description).to eq('please fix')
|
2017-05-04 08:11:15 -04:00
|
|
|
expect(issue.assignees).to be_empty
|
2016-09-27 05:29:06 -04:00
|
|
|
expect(issue.labels).to be_empty
|
|
|
|
expect(issue.milestone).to be_nil
|
|
|
|
expect(issue.due_date).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2016-02-15 13:13:52 -05:00
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
it 'creates a pending todo for new assignee' do
|
2016-02-15 13:13:52 -05:00
|
|
|
attributes = {
|
|
|
|
project: project,
|
|
|
|
author: user,
|
|
|
|
user: assignee,
|
2016-04-21 06:25:21 -04:00
|
|
|
target_id: issue.id,
|
|
|
|
target_type: issue.class.name,
|
2016-02-20 08:59:59 -05:00
|
|
|
action: Todo::ASSIGNED,
|
2016-02-15 13:13:52 -05:00
|
|
|
state: :pending
|
|
|
|
}
|
|
|
|
|
2016-02-20 08:59:59 -05:00
|
|
|
expect(Todo.where(attributes).count).to eq 1
|
2016-02-15 13:13:52 -05:00
|
|
|
end
|
2016-04-21 06:20:05 -04:00
|
|
|
|
2016-09-19 16:21:39 -04:00
|
|
|
context 'when label belongs to project group' do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:group_labels) { create_pair(:group_label, group: group) }
|
|
|
|
|
|
|
|
let(:opts) do
|
|
|
|
{
|
|
|
|
title: 'Title',
|
|
|
|
description: 'Description',
|
|
|
|
label_ids: group_labels.map(&:id)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.update(group: group)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns group labels' do
|
|
|
|
expect(issue.labels).to match_array group_labels
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-21 07:40:52 -04:00
|
|
|
context 'when label belongs to different project' do
|
2016-04-21 06:20:05 -04:00
|
|
|
let(:label) { create(:label) }
|
2016-04-21 06:25:21 -04:00
|
|
|
|
2016-04-21 06:20:05 -04:00
|
|
|
let(:opts) do
|
|
|
|
{ title: 'Title',
|
|
|
|
description: 'Description',
|
|
|
|
label_ids: [label.id] }
|
|
|
|
end
|
|
|
|
|
2016-05-23 14:16:35 -04:00
|
|
|
it 'does not assign label' do
|
2016-05-23 19:37:59 -04:00
|
|
|
expect(issue.labels).not_to include label
|
2016-04-21 06:20:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-28 14:09:35 -04:00
|
|
|
context 'when labels is nil' do
|
|
|
|
let(:opts) do
|
|
|
|
{ title: 'Title',
|
|
|
|
description: 'Description',
|
|
|
|
labels: nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not assign label' do
|
|
|
|
expect(issue.labels).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when labels is nil and label_ids is present' do
|
|
|
|
let(:opts) do
|
|
|
|
{ title: 'Title',
|
|
|
|
description: 'Description',
|
|
|
|
labels: nil,
|
|
|
|
label_ids: labels.map(&:id) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns group labels' do
|
|
|
|
expect(issue.labels).to match_array labels
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-21 07:40:52 -04:00
|
|
|
context 'when milestone belongs to different project' do
|
2016-04-21 06:20:05 -04:00
|
|
|
let(:milestone) { create(:milestone) }
|
2016-04-21 06:25:21 -04:00
|
|
|
|
2016-04-21 06:20:05 -04:00
|
|
|
let(:opts) do
|
|
|
|
{ title: 'Title',
|
|
|
|
description: 'Description',
|
|
|
|
milestone_id: milestone.id }
|
|
|
|
end
|
|
|
|
|
2016-04-21 06:25:21 -04:00
|
|
|
it 'does not assign milestone' do
|
2016-05-23 19:37:59 -04:00
|
|
|
expect(issue.milestone).not_to eq milestone
|
2016-04-21 06:20:05 -04:00
|
|
|
end
|
|
|
|
end
|
2016-08-12 15:05:10 -04:00
|
|
|
|
2017-05-10 16:54:10 -04:00
|
|
|
context 'when assignee is set' do
|
|
|
|
let(:opts) do
|
|
|
|
{ title: 'Title',
|
|
|
|
description: 'Description',
|
|
|
|
assignees: [assignee] }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'invalidates open issues counter for assignees when issue is assigned' do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(assignee)
|
2017-05-10 16:54:10 -04:00
|
|
|
|
|
|
|
described_class.new(project, user, opts).execute
|
|
|
|
|
|
|
|
expect(assignee.assigned_open_issues_count).to eq 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-01 05:09:49 -04:00
|
|
|
context 'when duplicate label titles are given' do
|
|
|
|
let(:label) { create(:label, project: project) }
|
|
|
|
|
|
|
|
let(:opts) do
|
|
|
|
{ title: 'Title',
|
|
|
|
description: 'Description',
|
|
|
|
labels: [label.title, label.title] }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns the label once' do
|
|
|
|
expect(issue.labels).to contain_exactly(label)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-30 18:11:46 -04:00
|
|
|
it 'executes issue hooks when issue is not confidential' do
|
|
|
|
opts = { title: 'Title', description: 'Description', confidential: false }
|
|
|
|
|
|
|
|
expect(project).to receive(:execute_hooks).with(an_instance_of(Hash), :issue_hooks)
|
|
|
|
expect(project).to receive(:execute_services).with(an_instance_of(Hash), :issue_hooks)
|
|
|
|
|
|
|
|
described_class.new(project, user, opts).execute
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'executes confidential issue hooks when issue is confidential' do
|
2016-08-12 15:05:10 -04:00
|
|
|
opts = { title: 'Title', description: 'Description', confidential: true }
|
|
|
|
|
2016-08-30 18:11:46 -04:00
|
|
|
expect(project).to receive(:execute_hooks).with(an_instance_of(Hash), :confidential_issue_hooks)
|
|
|
|
expect(project).to receive(:execute_services).with(an_instance_of(Hash), :confidential_issue_hooks)
|
2016-08-12 15:05:10 -04:00
|
|
|
|
|
|
|
described_class.new(project, user, opts).execute
|
|
|
|
end
|
2020-02-13 19:09:07 -05:00
|
|
|
|
|
|
|
context 'after_save callback to store_mentions' do
|
|
|
|
context 'when mentionable attributes change' do
|
|
|
|
let(:opts) { { title: 'Title', description: "Description with #{user.to_reference}" } }
|
|
|
|
|
|
|
|
it 'saves mentions' do
|
|
|
|
expect_next_instance_of(Issue) do |instance|
|
|
|
|
expect(instance).to receive(:store_mentions!).and_call_original
|
|
|
|
end
|
|
|
|
expect(issue.user_mentions.count).to eq 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when save fails' do
|
|
|
|
let(:opts) { { title: '', label_ids: labels.map(&:id), milestone_id: milestone.id } }
|
|
|
|
|
|
|
|
it 'does not call store_mentions' do
|
|
|
|
expect_next_instance_of(Issue) do |instance|
|
|
|
|
expect(instance).not_to receive(:store_mentions!).and_call_original
|
|
|
|
end
|
|
|
|
expect(issue.valid?).to be false
|
|
|
|
expect(issue.user_mentions.count).to eq 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-03-04 19:07:49 -05:00
|
|
|
|
|
|
|
it 'deletes milestone issues count cache' do
|
|
|
|
expect_next_instance_of(Milestones::IssuesCountService, milestone) do |service|
|
|
|
|
expect(service).to receive(:delete_cache).and_call_original
|
|
|
|
end
|
|
|
|
|
|
|
|
issue
|
|
|
|
end
|
2014-04-02 06:38:35 -04:00
|
|
|
end
|
2016-06-30 11:34:19 -04:00
|
|
|
|
2017-05-04 08:11:15 -04:00
|
|
|
context 'issue create service' do
|
|
|
|
context 'assignees' do
|
2017-06-14 14:18:56 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-06-14 14:18:56 -04:00
|
|
|
end
|
2017-05-04 08:11:15 -04:00
|
|
|
|
|
|
|
it 'removes assignee when user id is invalid' do
|
|
|
|
opts = { title: 'Title', description: 'Description', assignee_ids: [-1] }
|
|
|
|
|
|
|
|
issue = described_class.new(project, user, opts).execute
|
|
|
|
|
|
|
|
expect(issue.assignees).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes assignee when user id is 0' do
|
2019-01-16 07:09:29 -05:00
|
|
|
opts = { title: 'Title', description: 'Description', assignee_ids: [0] }
|
2017-05-04 08:11:15 -04:00
|
|
|
|
|
|
|
issue = described_class.new(project, user, opts).execute
|
|
|
|
|
|
|
|
expect(issue.assignees).to be_empty
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'saves assignee when user id is valid' do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(assignee)
|
2017-05-04 08:11:15 -04:00
|
|
|
opts = { title: 'Title', description: 'Description', assignee_ids: [assignee.id] }
|
|
|
|
|
|
|
|
issue = described_class.new(project, user, opts).execute
|
|
|
|
|
|
|
|
expect(issue.assignees).to eq([assignee])
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when issuable feature is private" do
|
|
|
|
before do
|
|
|
|
project.project_feature.update(issues_access_level: ProjectFeature::PRIVATE,
|
|
|
|
merge_requests_access_level: ProjectFeature::PRIVATE)
|
|
|
|
end
|
|
|
|
|
|
|
|
levels = [Gitlab::VisibilityLevel::INTERNAL, Gitlab::VisibilityLevel::PUBLIC]
|
|
|
|
|
|
|
|
levels.each do |level|
|
|
|
|
it "removes not authorized assignee when project is #{Gitlab::VisibilityLevel.level_name(level)}" do
|
|
|
|
project.update(visibility_level: level)
|
|
|
|
opts = { title: 'Title', description: 'Description', assignee_ids: [assignee.id] }
|
|
|
|
|
|
|
|
issue = described_class.new(project, user, opts).execute
|
|
|
|
|
|
|
|
expect(issue.assignees).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-12-14 16:39:53 -05:00
|
|
|
|
2017-05-31 01:50:53 -04:00
|
|
|
it_behaves_like 'new issuable record that supports quick actions'
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2017-05-31 01:50:53 -04:00
|
|
|
context 'Quick actions' do
|
2017-05-04 08:11:15 -04:00
|
|
|
context 'with assignee and milestone in params and command' do
|
|
|
|
let(:opts) do
|
|
|
|
{
|
|
|
|
assignee_ids: [create(:user).id],
|
|
|
|
milestone_id: 1,
|
|
|
|
title: 'Title',
|
|
|
|
description: %(/assign @#{assignee.username}\n/milestone %"#{milestone.name}")
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
|
|
|
project.add_maintainer(assignee)
|
2017-05-04 08:11:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns and sets milestone to issuable from command' do
|
|
|
|
expect(issue).to be_persisted
|
|
|
|
expect(issue.assignees).to eq([assignee])
|
|
|
|
expect(issue.milestone).to eq(milestone)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
context 'resolving discussions' do
|
2017-03-09 20:29:11 -05:00
|
|
|
let(:discussion) { create(:diff_note_on_merge_request).to_discussion }
|
2016-10-26 17:21:50 -04:00
|
|
|
let(:merge_request) { discussion.noteable }
|
|
|
|
let(:project) { merge_request.source_project }
|
|
|
|
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
describe 'for a single discussion' do
|
2017-03-10 03:19:12 -05:00
|
|
|
let(:opts) { { discussion_to_resolve: discussion.id, merge_request_to_resolve_discussions_of: merge_request.iid } }
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
it 'resolves the discussion' do
|
|
|
|
described_class.new(project, user, opts).execute
|
|
|
|
discussion.first_note.reload
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
expect(discussion.resolved?).to be(true)
|
|
|
|
end
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
it 'added a system note to the discussion' do
|
|
|
|
described_class.new(project, user, opts).execute
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
reloaded_discussion = MergeRequest.find(merge_request.id).discussions.first
|
|
|
|
|
|
|
|
expect(reloaded_discussion.last_note.system).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns the title and description for the issue' do
|
|
|
|
issue = described_class.new(project, user, opts).execute
|
|
|
|
|
|
|
|
expect(issue.title).not_to be_nil
|
|
|
|
expect(issue.description).not_to be_nil
|
|
|
|
end
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
it 'can set nil explicitly to the title and description' do
|
|
|
|
issue = described_class.new(project, user,
|
2017-03-10 03:19:12 -05:00
|
|
|
merge_request_to_resolve_discussions_of: merge_request,
|
2016-12-22 07:31:12 -05:00
|
|
|
description: nil,
|
|
|
|
title: nil).execute
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
expect(issue.description).to be_nil
|
|
|
|
expect(issue.title).to be_nil
|
|
|
|
end
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
describe 'for a merge request' do
|
2017-03-10 03:19:12 -05:00
|
|
|
let(:opts) { { merge_request_to_resolve_discussions_of: merge_request.iid } }
|
2016-12-22 07:31:12 -05:00
|
|
|
|
|
|
|
it 'resolves the discussion' do
|
|
|
|
described_class.new(project, user, opts).execute
|
|
|
|
discussion.first_note.reload
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
expect(discussion.resolved?).to be(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'added a system note to the discussion' do
|
|
|
|
described_class.new(project, user, opts).execute
|
|
|
|
|
|
|
|
reloaded_discussion = MergeRequest.find(merge_request.id).discussions.first
|
|
|
|
|
|
|
|
expect(reloaded_discussion.last_note.system).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'assigns the title and description for the issue' do
|
|
|
|
issue = described_class.new(project, user, opts).execute
|
|
|
|
|
|
|
|
expect(issue.title).not_to be_nil
|
|
|
|
expect(issue.description).not_to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'can set nil explicitly to the title and description' do
|
|
|
|
issue = described_class.new(project, user,
|
2017-03-10 03:19:12 -05:00
|
|
|
merge_request_to_resolve_discussions_of: merge_request,
|
2016-12-22 07:31:12 -05:00
|
|
|
description: nil,
|
|
|
|
title: nil).execute
|
|
|
|
|
|
|
|
expect(issue.description).to be_nil
|
|
|
|
expect(issue.title).to be_nil
|
|
|
|
end
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
end
|
2017-01-27 11:25:39 -05:00
|
|
|
|
|
|
|
context 'checking spam' do
|
2020-04-21 11:21:10 -04:00
|
|
|
include_context 'includes Spam constants'
|
|
|
|
|
2020-04-13 23:09:39 -04:00
|
|
|
let(:title) { 'Legit issue' }
|
|
|
|
let(:description) { 'please fix' }
|
2017-01-27 11:25:39 -05:00
|
|
|
let(:opts) do
|
|
|
|
{
|
2020-04-13 23:09:39 -04:00
|
|
|
title: title,
|
|
|
|
description: description,
|
2017-01-27 11:25:39 -05:00
|
|
|
request: double(:request, env: {})
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
subject { described_class.new(project, user, opts) }
|
|
|
|
|
2017-01-27 11:25:39 -05:00
|
|
|
before do
|
2019-09-24 23:06:21 -04:00
|
|
|
stub_feature_flags(allow_possible_spam: false)
|
2017-01-27 11:25:39 -05:00
|
|
|
end
|
|
|
|
|
2020-04-21 14:09:31 -04:00
|
|
|
context 'when reCAPTCHA was verified' do
|
2017-01-27 11:25:39 -05:00
|
|
|
let(:log_user) { user }
|
2020-04-13 23:09:39 -04:00
|
|
|
let(:spam_logs) { create_list(:spam_log, 2, user: log_user, title: title) }
|
2020-04-06 23:09:15 -04:00
|
|
|
let(:target_spam_log) { spam_logs.last }
|
2017-01-27 11:25:39 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
opts[:recaptcha_verified] = true
|
2020-04-06 23:09:15 -04:00
|
|
|
opts[:spam_log_id] = target_spam_log.id
|
2017-01-27 11:25:39 -05:00
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
expect(Spam::SpamVerdictService).not_to receive(:new)
|
2017-01-27 11:25:39 -05:00
|
|
|
end
|
|
|
|
|
2020-04-06 23:09:15 -04:00
|
|
|
it 'does not mark an issue as spam' do
|
2017-01-27 11:25:39 -05:00
|
|
|
expect(issue).not_to be_spam
|
|
|
|
end
|
|
|
|
|
2020-04-13 23:09:39 -04:00
|
|
|
it 'creates a valid issue' do
|
2020-04-06 23:09:15 -04:00
|
|
|
expect(issue).to be_valid
|
2017-01-27 11:25:39 -05:00
|
|
|
end
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
it 'does not assign a spam_log to the issue' do
|
2017-01-27 11:25:39 -05:00
|
|
|
expect(issue.spam_log).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'marks related spam_log as recaptcha_verified' do
|
2020-04-13 23:09:39 -04:00
|
|
|
expect { issue }.to change { target_spam_log.reload.recaptcha_verified }.from(false).to(true)
|
2017-01-27 11:25:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when spam log does not belong to a user' do
|
|
|
|
let(:log_user) { create(:user) }
|
|
|
|
|
|
|
|
it 'does not mark spam_log as recaptcha_verified' do
|
2020-04-13 23:09:39 -04:00
|
|
|
expect { issue }.not_to change { target_spam_log.reload.recaptcha_verified }
|
2017-01-27 11:25:39 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-21 14:09:31 -04:00
|
|
|
context 'when reCAPTCHA was not verified' do
|
2019-09-24 23:06:21 -04:00
|
|
|
before do
|
2020-04-21 11:21:10 -04:00
|
|
|
expect_next_instance_of(Spam::SpamActionService) do |spam_service|
|
2019-09-24 23:06:21 -04:00
|
|
|
expect(spam_service).to receive_messages(check_for_spam?: true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
context 'when SpamVerdictService requires reCAPTCHA' do
|
|
|
|
before do
|
|
|
|
expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service|
|
2020-05-25 23:08:02 -04:00
|
|
|
expect(verdict_service).to receive(:execute).and_return(CONDITIONAL_ALLOW)
|
2020-04-21 11:21:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-22 05:09:36 -04:00
|
|
|
it 'does not mark the issue as spam' do
|
|
|
|
expect(issue).not_to be_spam
|
2020-04-21 11:21:10 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'marks the issue as needing reCAPTCHA' do
|
|
|
|
expect(issue.needs_recaptcha?).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'invalidates the issue' do
|
|
|
|
expect(issue).to be_invalid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a new spam_log' do
|
|
|
|
expect { issue }
|
|
|
|
.to have_spam_log(title: title, description: description, user_id: user.id, noteable_type: 'Issue')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when SpamVerdictService disallows creation' do
|
2017-01-27 11:25:39 -05:00
|
|
|
before do
|
2020-04-21 11:21:10 -04:00
|
|
|
expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service|
|
|
|
|
expect(verdict_service).to receive(:execute).and_return(DISALLOW)
|
2019-09-24 23:06:21 -04:00
|
|
|
end
|
2017-01-27 11:25:39 -05:00
|
|
|
end
|
|
|
|
|
2020-04-13 23:09:39 -04:00
|
|
|
context 'when allow_possible_spam feature flag is false' do
|
2020-04-22 05:09:36 -04:00
|
|
|
it 'marks the issue as spam' do
|
2019-09-24 23:06:21 -04:00
|
|
|
expect(issue).to be_spam
|
|
|
|
end
|
2017-01-27 11:25:39 -05:00
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
it 'does not mark the issue as needing reCAPTCHA' do
|
|
|
|
expect(issue.needs_recaptcha?).to be_falsey
|
|
|
|
end
|
|
|
|
|
2019-09-24 23:06:21 -04:00
|
|
|
it 'invalidates the issue' do
|
|
|
|
expect(issue).to be_invalid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a new spam_log' do
|
|
|
|
expect { issue }
|
2020-04-13 23:09:39 -04:00
|
|
|
.to have_spam_log(title: title, description: description, user_id: user.id, noteable_type: 'Issue')
|
2019-09-24 23:06:21 -04:00
|
|
|
end
|
2017-01-27 11:25:39 -05:00
|
|
|
end
|
|
|
|
|
2020-04-13 23:09:39 -04:00
|
|
|
context 'when allow_possible_spam feature flag is true' do
|
2019-09-24 23:06:21 -04:00
|
|
|
before do
|
|
|
|
stub_feature_flags(allow_possible_spam: true)
|
|
|
|
end
|
|
|
|
|
2020-04-13 23:09:39 -04:00
|
|
|
it 'does not mark the issue as spam' do
|
2019-09-24 23:06:21 -04:00
|
|
|
expect(issue).not_to be_spam
|
|
|
|
end
|
|
|
|
|
2020-04-22 05:09:36 -04:00
|
|
|
it 'does not mark the issue as needing reCAPTCHA' do
|
|
|
|
expect(issue.needs_recaptcha?).to be_falsey
|
|
|
|
end
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
it 'creates a valid issue' do
|
2019-09-24 23:06:21 -04:00
|
|
|
expect(issue).to be_valid
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a new spam_log' do
|
|
|
|
expect { issue }
|
2020-04-13 23:09:39 -04:00
|
|
|
.to have_spam_log(title: title, description: description, user_id: user.id, noteable_type: 'Issue')
|
2019-09-24 23:06:21 -04:00
|
|
|
end
|
2017-01-27 11:25:39 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
context 'when the SpamVerdictService allows creation' do
|
2017-01-27 11:25:39 -05:00
|
|
|
before do
|
2020-04-21 11:21:10 -04:00
|
|
|
expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service|
|
|
|
|
expect(verdict_service).to receive(:execute).and_return(ALLOW)
|
2019-09-24 23:06:21 -04:00
|
|
|
end
|
2017-01-27 11:25:39 -05:00
|
|
|
end
|
|
|
|
|
2020-04-06 23:09:15 -04:00
|
|
|
it 'does not mark an issue as spam' do
|
2017-01-27 11:25:39 -05:00
|
|
|
expect(issue).not_to be_spam
|
|
|
|
end
|
|
|
|
|
2020-04-13 23:09:39 -04:00
|
|
|
it 'creates a valid issue' do
|
|
|
|
expect(issue).to be_valid
|
2017-01-27 11:25:39 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not assign a spam_log to an issue' do
|
|
|
|
expect(issue.spam_log).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-04-02 06:38:35 -04:00
|
|
|
end
|
|
|
|
end
|