BigW Consortium Gitlab

spammable_spec.rb 1.39 KB
Newer Older
1 2
require 'spec_helper'

3
describe Spammable do
4 5 6
  let(:issue) { create(:issue, description: 'Test Desc.') }

  describe 'Associations' do
7 8
    subject { build(:issue) }

9 10 11 12 13
    it { is_expected.to have_one(:user_agent_detail).dependent(:destroy) }
  end

  describe 'ClassMethods' do
    it 'should return correct attr_spammable' do
14
      expect(issue.spammable_text).to eq("#{issue.title}\n#{issue.description}")
15 16 17 18
    end
  end

  describe 'InstanceMethods' do
19 20
    let(:issue) { build(:issue, spam: true) }

21
    it 'should be invalid if spam' do
22
      expect(issue.valid?).to be_falsey
23 24
    end

25 26 27
    describe '#check_for_spam?' do
      it 'returns true for public project' do
        issue.project.update_attribute(:visibility_level, Gitlab::VisibilityLevel::PUBLIC)
28

29 30 31 32 33 34 35
        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
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

    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
51 52
  end
end