diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-20 13:43:29 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-20 13:43:29 +0300 |
commit | 3b1af5cc7ed2666ff18b718ce5d30fa5a2756674 (patch) | |
tree | 3bc4a40e0ee51ec27eabf917c537033c0c5b14d4 /spec/models/note_spec.rb | |
parent | 9bba14be3f2c211bf79e15769cd9b77bc73a13bc (diff) |
Add latest changes from gitlab-org/gitlab@16-1-stable-eev16.1.0-rc42
Diffstat (limited to 'spec/models/note_spec.rb')
-rw-r--r-- | spec/models/note_spec.rb | 128 |
1 files changed, 126 insertions, 2 deletions
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index f722415d428..e99d77dc0a0 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -53,8 +53,7 @@ RSpec.describe Note, feature_category: :team_planning do context 'when noteable and note project differ' do subject do - build(:note, noteable: build_stubbed(:issue), - project: build_stubbed(:project)) + build(:note, noteable: build_stubbed(:issue), project: build_stubbed(:project)) end it { is_expected.to be_invalid } @@ -933,6 +932,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 } @@ -1695,6 +1795,30 @@ RSpec.describe Note, feature_category: :team_planning do end end end + + describe '.authored_by' do + subject(:notes_by_author) { described_class.authored_by(author) } + + let(:author) { create(:user) } + + it 'returns the notes with the matching author' do + note = create(:note, author: author) + create(:note) + + expect(notes_by_author).to contain_exactly(note) + end + + context 'With ID integer' do + subject(:notes_by_author) { described_class.authored_by(author.id) } + + it 'returns the notes with the matching author' do + note = create(:note, author: author) + create(:note) + + expect(notes_by_author).to contain_exactly(note) + end + end + end end describe 'banzai_render_context' do |