diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-16 12:09:20 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-16 12:09:20 +0300 |
commit | 8ae36d93f1a63874b584f0488fde88c1fee999c4 (patch) | |
tree | f1788ba1a7fb00248ff008f817f6feea89304339 /spec/models | |
parent | b394e58cc2e52e17e7991e3d7b705aa383c362ee (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/concerns/spammable_spec.rb | 33 | ||||
-rw-r--r-- | spec/models/merge_request_spec.rb | 27 |
2 files changed, 46 insertions, 14 deletions
diff --git a/spec/models/concerns/spammable_spec.rb b/spec/models/concerns/spammable_spec.rb index e80b202f3c9..a18a4b067dd 100644 --- a/spec/models/concerns/spammable_spec.rb +++ b/spec/models/concerns/spammable_spec.rb @@ -3,6 +3,22 @@ require 'spec_helper' RSpec.describe Spammable, feature_category: :instance_resiliency do + before do + stub_const('SpammableModel', Class.new(ActiveRecord::Base)) + + SpammableModel.class_eval do + self.table_name = 'issues' + + include Spammable + + attr_accessor :other_attr + + attr_spammable :title, spam_title: true + attr_spammable :description, spam_description: true + end + end + + let(:spammable_model) { SpammableModel.new } let(:issue) { create(:issue, description: 'Test Desc.') } describe 'Associations' do @@ -26,16 +42,14 @@ RSpec.describe Spammable, feature_category: :instance_resiliency do describe '#check_for_spam?' do context 'when not overriden' do - let(:merge_request) { create(:merge_request) } - - subject { merge_request.check_for_spam? } + subject { spammable_model.check_for_spam? } context 'when spammable attributes have changed' do where(attr: [:title, :description]) with_them do before do - merge_request.assign_attributes(attr => 'x') + spammable_model.assign_attributes(attr => 'x') end it { is_expected.to eq(true) } @@ -44,7 +58,7 @@ RSpec.describe Spammable, feature_category: :instance_resiliency do context 'when other attributes have changed' do before do - merge_request.draft = true + spammable_model.other_attr = true end it { is_expected.to eq(false) } @@ -68,15 +82,6 @@ RSpec.describe Spammable, feature_category: :instance_resiliency do end context 'when the model is spam' do - before do - stub_const('SpammableModel', Class.new(ApplicationRecord)) - - SpammableModel.class_eval do - include Spammable - self.table_name = 'issues' - end - end - where(model: [:issue, :merge_request, :snippet, :spammable_model]) with_them do diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index f0ea8db9e81..2a35efed8e0 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -5673,4 +5673,31 @@ RSpec.describe MergeRequest, factory_default: :keep, feature_category: :code_rev subject.prepare end end + + describe '#check_for_spam?' do + let_it_be(:project) { create(:project, :public) } + let(:merge_request) { build_stubbed(:merge_request, source_project: project) } + + subject { merge_request.check_for_spam? } + + before do + merge_request.title = 'New title' + end + + it { is_expected.to eq(true) } + + context 'when project is private' do + let_it_be(:project) { create(:project, :private) } + + it { is_expected.to eq(false) } + end + + context 'when no spammable attribute has changed' do + before do + merge_request.title = merge_request.title_was + end + + it { is_expected.to eq(false) } + end + end end |