diff options
Diffstat (limited to 'spec/services/issues/create_service_spec.rb')
-rw-r--r-- | spec/services/issues/create_service_spec.rb | 86 |
1 files changed, 74 insertions, 12 deletions
diff --git a/spec/services/issues/create_service_spec.rb b/spec/services/issues/create_service_spec.rb index bd50d6b1001..7a251e03e51 100644 --- a/spec/services/issues/create_service_spec.rb +++ b/spec/services/issues/create_service_spec.rb @@ -110,6 +110,31 @@ describe Issues::CreateService do end end + 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 + context 'when milestone belongs to different project' do let(:milestone) { create(:milestone) } @@ -368,6 +393,8 @@ describe Issues::CreateService do end context 'checking spam' do + include_context 'includes Spam constants' + let(:title) { 'Legit issue' } let(:description) { 'please fix' } let(:opts) do @@ -378,11 +405,13 @@ describe Issues::CreateService do } end + subject { described_class.new(project, user, opts) } + before do stub_feature_flags(allow_possible_spam: false) end - context 'when recaptcha was verified' do + 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 } @@ -391,7 +420,7 @@ describe Issues::CreateService do opts[:recaptcha_verified] = true opts[:spam_log_id] = target_spam_log.id - expect(Spam::AkismetService).not_to receive(:new) + expect(Spam::SpamVerdictService).not_to receive(:new) end it 'does not mark an issue as spam' do @@ -402,7 +431,7 @@ describe Issues::CreateService do expect(issue).to be_valid end - it 'does not assign a spam_log to an issue' do + it 'does not assign a spam_log to the issue' do expect(issue.spam_log).to be_nil end @@ -419,17 +448,42 @@ describe Issues::CreateService do end end - context 'when recaptcha was not verified' do + context 'when reCAPTCHA was not verified' do before do - expect_next_instance_of(Spam::SpamCheckService) do |spam_service| + expect_next_instance_of(Spam::SpamActionService) do |spam_service| expect(spam_service).to receive_messages(check_for_spam?: true) end end - context 'when akismet detects spam' do + context 'when SpamVerdictService requires reCAPTCHA' do before do - expect_next_instance_of(Spam::AkismetService) do |akismet_service| - expect(akismet_service).to receive_messages(spam?: true) + expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service| + expect(verdict_service).to receive(:execute).and_return(REQUIRE_RECAPTCHA) + 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 @@ -438,6 +492,10 @@ describe Issues::CreateService 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 @@ -457,7 +515,11 @@ describe Issues::CreateService do expect(issue).not_to be_spam end - it '​creates a valid issue' do + 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 @@ -468,10 +530,10 @@ describe Issues::CreateService do end end - context 'when akismet does not detect spam' do + context 'when the SpamVerdictService allows creation' do before do - expect_next_instance_of(Spam::AkismetService) do |akismet_service| - expect(akismet_service).to receive_messages(spam?: false) + expect_next_instance_of(Spam::SpamVerdictService) do |verdict_service| + expect(verdict_service).to receive(:execute).and_return(ALLOW) end end |