Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 13:34:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-02-18 13:34:06 +0300
commit859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch)
treed7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/services/issues
parent446d496a6d000c73a304be52587cd9bbc7493136 (diff)
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/services/issues')
-rw-r--r--spec/services/issues/close_service_spec.rb3
-rw-r--r--spec/services/issues/create_service_spec.rb176
-rw-r--r--spec/services/issues/update_service_spec.rb2
3 files changed, 36 insertions, 145 deletions
diff --git a/spec/services/issues/close_service_spec.rb b/spec/services/issues/close_service_spec.rb
index dc545f57d23..3cf45143594 100644
--- a/spec/services/issues/close_service_spec.rb
+++ b/spec/services/issues/close_service_spec.rb
@@ -84,6 +84,7 @@ RSpec.describe Issues::CloseService do
let!(:external_issue_tracker) { create(:jira_service, project: project) }
it 'closes the issue on the external issue tracker' do
+ project.reload
expect(project.external_issue_tracker).to receive(:close_issue)
described_class.new(project, user).close_issue(external_issue)
@@ -94,6 +95,7 @@ RSpec.describe Issues::CloseService do
let!(:external_issue_tracker) { create(:jira_service, project: project, active: false) }
it 'does not close the issue on the external issue tracker' do
+ project.reload
expect(project.external_issue_tracker).not_to receive(:close_issue)
described_class.new(project, user).close_issue(external_issue)
@@ -104,6 +106,7 @@ RSpec.describe Issues::CloseService do
let!(:external_issue_tracker) { create(:bugzilla_service, project: project) }
it 'does not close the issue on the external issue tracker' do
+ project.reload
expect(project.external_issue_tracker).not_to receive(:close_issue)
described_class.new(project, user).close_issue(external_issue)
diff --git a/spec/services/issues/create_service_spec.rb b/spec/services/issues/create_service_spec.rb
index cc6a49fc4cf..e42e9722297 100644
--- a/spec/services/issues/create_service_spec.rb
+++ b/spec/services/issues/create_service_spec.rb
@@ -452,162 +452,50 @@ RSpec.describe Issues::CreateService do
end
context 'checking spam' do
- include_context 'includes Spam constants'
+ let(:request) { double(:request) }
+ let(:api) { true }
+ let(:captcha_response) { 'abc123' }
+ let(:spam_log_id) { 1 }
- let(:title) { 'Legit issue' }
- let(:description) { 'please fix' }
- let(:opts) do
+ let(:params) do
{
- title: title,
- description: description,
- request: double(:request, env: {})
+ title: 'Spam issue',
+ request: request,
+ api: api,
+ captcha_response: captcha_response,
+ spam_log_id: spam_log_id
}
end
- subject { described_class.new(project, user, opts) }
-
- before do
- stub_feature_flags(allow_possible_spam: false)
+ subject do
+ described_class.new(project, user, params)
end
- context 'when reCAPTCHA was verified' do
- let(:log_user) { user }
- let(:spam_logs) { create_list(:spam_log, 2, user: log_user, title: title) }
- let(:target_spam_log) { spam_logs.last }
-
- before do
- opts[:recaptcha_verified] = true
- opts[:spam_log_id] = target_spam_log.id
-
- expect(Spam::SpamVerdictService).not_to receive(:new)
- end
-
- it 'does not mark an issue as spam' do
- expect(issue).not_to be_spam
- end
-
- it 'creates a valid issue' do
- expect(issue).to be_valid
- end
-
- it 'does not assign a spam_log to the issue' do
- expect(issue.spam_log).to be_nil
- end
-
- it 'marks related spam_log as recaptcha_verified' do
- expect { issue }.to change { target_spam_log.reload.recaptcha_verified }.from(false).to(true)
- 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
- expect { issue }.not_to change { target_spam_log.reload.recaptcha_verified }
- end
+ before do
+ allow_next_instance_of(UserAgentDetailService) do |instance|
+ allow(instance).to receive(:create)
end
end
- context 'when reCAPTCHA was not verified' do
- before do
- expect_next_instance_of(Spam::SpamActionService) do |spam_service|
- expect(spam_service).to receive_messages(check_for_spam?: true)
- end
- end
-
- context 'when SpamVerdictService requires reCAPTCHA' do
- before do
- expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service|
- expect(verdict_service).to receive(:execute).and_return(CONDITIONAL_ALLOW)
- end
- end
-
- it 'does not mark the issue as spam' do
- expect(issue).not_to be_spam
- 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
- before do
- expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service|
- expect(verdict_service).to receive(:execute).and_return(DISALLOW)
- end
- end
-
- context 'when allow_possible_spam feature flag is false' do
- it 'marks the issue as spam' do
- expect(issue).to be_spam
- end
-
- it 'does not mark the issue as needing reCAPTCHA' do
- expect(issue.needs_recaptcha?).to be_falsey
- 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 allow_possible_spam feature flag is true' do
- before do
- stub_feature_flags(allow_possible_spam: true)
- end
-
- it 'does not mark the issue as spam' do
- expect(issue).not_to be_spam
- end
-
- it 'does not mark the issue as needing reCAPTCHA' do
- expect(issue.needs_recaptcha?).to be_falsey
- end
-
- it 'creates a valid issue' do
- expect(issue).to be_valid
- 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
+ it 'executes SpamActionService' do
+ spam_params = Spam::SpamParams.new(
+ api: api,
+ captcha_response: captcha_response,
+ spam_log_id: spam_log_id
+ )
+ expect_next_instance_of(
+ Spam::SpamActionService,
+ {
+ spammable: an_instance_of(Issue),
+ request: request,
+ user: user,
+ action: :create
+ }
+ ) do |instance|
+ expect(instance).to receive(:execute).with(spam_params: spam_params)
end
- context 'when the SpamVerdictService allows creation' do
- before do
- expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service|
- expect(verdict_service).to receive(:execute).and_return(ALLOW)
- end
- end
-
- it 'does not mark an issue as spam' do
- expect(issue).not_to be_spam
- end
-
- it 'creates a valid issue' do
- expect(issue).to be_valid
- end
-
- it 'does not assign a spam_log to an issue' do
- expect(issue.spam_log).to be_nil
- end
- end
+ subject.execute
end
end
end
diff --git a/spec/services/issues/update_service_spec.rb b/spec/services/issues/update_service_spec.rb
index 06a6a52bc41..fd42a84e405 100644
--- a/spec/services/issues/update_service_spec.rb
+++ b/spec/services/issues/update_service_spec.rb
@@ -711,7 +711,7 @@ RSpec.describe Issues::UpdateService, :mailer do
}
service = described_class.new(project, user, params)
- expect(service).not_to receive(:spam_check)
+ expect(Spam::SpamActionService).not_to receive(:new)
service.execute(issue)
end