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>2023-06-09 12:10:14 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-06-09 12:10:14 +0300
commit8b50d36626f3a71a2d8552a316d700510559b0de (patch)
tree154f4b0391d0943438f577559a8adad32885bfe1 /spec/models
parent7a544c9ef1136ce0b52e269f54ebe74d0f26ad3d (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/concerns/spammable_spec.rb37
-rw-r--r--spec/models/note_spec.rb101
-rw-r--r--spec/models/sent_notification_spec.rb19
3 files changed, 148 insertions, 9 deletions
diff --git a/spec/models/concerns/spammable_spec.rb b/spec/models/concerns/spammable_spec.rb
index 44cf87aa1c1..457c831e27c 100644
--- a/spec/models/concerns/spammable_spec.rb
+++ b/spec/models/concerns/spammable_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Spammable do
+RSpec.describe Spammable, feature_category: :instance_resiliency do
let(:issue) { create(:issue, description: 'Test Desc.') }
describe 'Associations' do
@@ -59,6 +59,18 @@ RSpec.describe Spammable do
end
end
+ context 'when the model needs recaptcha but does not support it' do
+ subject { invalidate_if_spam(needs_recaptcha: true) }
+
+ before do
+ allow(issue).to receive(:supports_recaptcha?).and_return(false)
+ end
+
+ it 'has an error that discards the spammable' do
+ expect(subject.errors.messages[:base]).to match_array /has been discarded/
+ end
+ end
+
context 'if the model is spam and also needs recaptcha' do
subject { invalidate_if_spam(is_spam: true, needs_recaptcha: true) }
@@ -112,11 +124,26 @@ RSpec.describe Spammable do
end
describe '#needs_recaptcha!' do
- it 'adds `needs_recaptcha` flag' do
- issue.needs_recaptcha!
+ context 'when recaptcha is supported' do
+ it 'adds `needs_recaptcha` flag' do
+ issue.needs_recaptcha!
+
+ expect(issue.spam).to be_falsey
+ expect(issue.needs_recaptcha).to be_truthy
+ end
+ end
- expect(issue.spam).to be_falsey
- expect(issue.needs_recaptcha).to be_truthy
+ context 'when recaptcha is not supported' do
+ before do
+ allow(issue).to receive(:supports_recaptcha?).and_return(false)
+ end
+
+ it 'marks the object as spam' do
+ issue.needs_recaptcha!
+
+ expect(issue.spam).to be_truthy
+ expect(issue.needs_recaptcha).to be_falsey
+ end
end
end
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 1453ce9709f..f82235916f2 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -933,6 +933,107 @@ RSpec.describe Note, feature_category: :team_planning do
end
end
+ describe '#check_for_spam' do
+ let_it_be(:project) { create(:project, :public) }
+ let_it_be(:group) { create(:group, :public) }
+ let(:issue) { create(:issue, project: project) }
+ let(:note) { create(:note, note: "test", noteable: issue, project: project) }
+ let(:note_text) { 'content changed' }
+
+ subject do
+ note.assign_attributes(note: note_text)
+ note.check_for_spam?(user: note.author)
+ end
+
+ before do
+ allow(issue).to receive(:group).and_return(group)
+ end
+
+ context 'when note is public' do
+ it 'returns true' do
+ is_expected.to be_truthy
+ end
+ end
+
+ context 'when note is public and spammable attributes are not changed' do
+ let(:note_text) { 'test' }
+
+ it 'returns false' do
+ is_expected.to be_falsey
+ end
+ end
+
+ context 'when project does not exist' do
+ before do
+ allow(note).to receive(:project).and_return(nil)
+ end
+
+ it 'returns true' do
+ is_expected.to be_truthy
+ end
+ end
+
+ context 'when project is not public' do
+ before do
+ allow(project).to receive(:public?).and_return(false)
+ end
+
+ it 'returns false' do
+ is_expected.to be_falsey
+ end
+ end
+
+ context 'when group is not public' do
+ before do
+ allow(group).to receive(:public?).and_return(false)
+ end
+
+ it 'returns false' do
+ is_expected.to be_falsey
+ end
+ end
+
+ context 'when note is confidential' do
+ before do
+ allow(note).to receive(:confidential?).and_return(true)
+ end
+
+ it 'returns false' do
+ is_expected.to be_falsey
+ end
+ end
+
+ context 'when noteable is confidential' do
+ before do
+ allow(issue).to receive(:confidential?).and_return(true)
+ end
+
+ it 'returns false' do
+ is_expected.to be_falsey
+ end
+ end
+
+ context 'when noteable is not public' do
+ before do
+ allow(issue).to receive(:public?).and_return(false)
+ end
+
+ it 'returns false' do
+ is_expected.to be_falsey
+ end
+ end
+
+ context 'when note is a system note' do
+ before do
+ allow(note).to receive(:system?).and_return(true)
+ end
+
+ it 'returns false' do
+ is_expected.to be_falsey
+ end
+ end
+ end
+
describe ".grouped_diff_discussions" do
let!(:merge_request) { create(:merge_request) }
let(:project) { merge_request.project }
diff --git a/spec/models/sent_notification_spec.rb b/spec/models/sent_notification_spec.rb
index 8194150532d..5b31e8e5e3c 100644
--- a/spec/models/sent_notification_spec.rb
+++ b/spec/models/sent_notification_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe SentNotification do
+RSpec.describe SentNotification, :request_store do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
@@ -46,21 +46,31 @@ RSpec.describe SentNotification do
end
end
+ shared_examples 'a non-sticky write' do
+ it 'writes without sticking to primary' do
+ subject
+
+ expect(Gitlab::Database::LoadBalancing::Session.current.use_primary?).to be false
+ end
+ end
+
describe '.record' do
- let(:issue) { create(:issue) }
+ let_it_be(:issue) { create(:issue) }
subject { described_class.record(issue, user.id) }
it_behaves_like 'a successful sent notification'
+ it_behaves_like 'a non-sticky write'
end
describe '.record_note' do
subject { described_class.record_note(note, note.author.id) }
context 'for a discussion note' do
- let(:note) { create(:diff_note_on_merge_request) }
+ let_it_be(:note) { create(:diff_note_on_merge_request) }
it_behaves_like 'a successful sent notification'
+ it_behaves_like 'a non-sticky write'
it 'sets in_reply_to_discussion_id' do
expect(subject.in_reply_to_discussion_id).to eq(note.discussion_id)
@@ -68,9 +78,10 @@ RSpec.describe SentNotification do
end
context 'for an individual note' do
- let(:note) { create(:note_on_merge_request) }
+ let_it_be(:note) { create(:note_on_merge_request) }
it_behaves_like 'a successful sent notification'
+ it_behaves_like 'a non-sticky write'
it 'sets in_reply_to_discussion_id' do
expect(subject.in_reply_to_discussion_id).to eq(note.discussion_id)