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/note_spec.rb
parent7a544c9ef1136ce0b52e269f54ebe74d0f26ad3d (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/note_spec.rb')
-rw-r--r--spec/models/note_spec.rb101
1 files changed, 101 insertions, 0 deletions
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 }