2019-03-30 07:23:56 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-29 00:02:56 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-04-25 12:28:55 +00:00
|
|
|
describe Spammable do
|
2016-07-29 00:02:56 +00:00
|
|
|
let(:issue) { create(:issue, description: 'Test Desc.') }
|
|
|
|
|
|
|
|
describe 'Associations' do
|
2017-04-25 12:28:55 +00:00
|
|
|
subject { build(:issue) }
|
|
|
|
|
2016-07-29 00:02:56 +00:00
|
|
|
it { is_expected.to have_one(:user_agent_detail).dependent(:destroy) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'ClassMethods' do
|
2019-04-05 08:43:27 +00:00
|
|
|
it 'returns correct attr_spammable' do
|
2016-08-09 17:43:47 +00:00
|
|
|
expect(issue.spammable_text).to eq("#{issue.title}\n#{issue.description}")
|
2016-07-29 00:02:56 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'InstanceMethods' do
|
2017-02-10 10:41:22 +00:00
|
|
|
let(:issue) { build(:issue, spam: true) }
|
|
|
|
|
2019-04-05 08:43:27 +00:00
|
|
|
it 'is invalid if spam' do
|
2016-08-05 22:10:08 +00:00
|
|
|
expect(issue.valid?).to be_falsey
|
2016-07-29 00:02:56 +00:00
|
|
|
end
|
|
|
|
|
2016-07-30 04:18:32 +00:00
|
|
|
describe '#check_for_spam?' do
|
|
|
|
it 'returns true for public project' do
|
|
|
|
issue.project.update_attribute(:visibility_level, Gitlab::VisibilityLevel::PUBLIC)
|
2017-02-14 19:07:11 +00:00
|
|
|
|
2016-07-30 04:18:32 +00:00
|
|
|
expect(issue.check_for_spam?).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false for other visibility levels' do
|
|
|
|
expect(issue.check_for_spam?).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
2017-02-10 10:41:22 +00:00
|
|
|
|
|
|
|
describe '#submittable_as_spam_by?' do
|
|
|
|
let(:admin) { build(:admin) }
|
|
|
|
let(:user) { build(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(issue).to receive(:submittable_as_spam?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'tests if the user can submit spam' do
|
|
|
|
expect(issue.submittable_as_spam_by?(admin)).to be(true)
|
|
|
|
expect(issue.submittable_as_spam_by?(user)).to be(false)
|
|
|
|
expect(issue.submittable_as_spam_by?(nil)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2016-07-29 00:02:56 +00:00
|
|
|
end
|
|
|
|
end
|