BigW Consortium Gitlab

spammable_spec.rb 1.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
require 'spec_helper'

describe Issue, 'Spammable' do
  let(:issue) { create(:issue, description: 'Test Desc.') }

  describe 'Associations' do
    it { is_expected.to have_one(:user_agent_detail).dependent(:destroy) }
  end

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

  describe 'InstanceMethods' do
17 18
    let(:issue) { build(:issue, spam: true) }

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

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

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

    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
49 50
  end
end