spammable_spec.rb 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
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
      expect(issue.send(:spammable_text)).to eq("#{issue.title}\n#{issue.description}")
    end
  end

  describe 'InstanceMethods' do
17 18 19 20
    before do
      allow_any_instance_of(Gitlab::AkismetHelper).to receive(:akismet_enabled?).and_return(true)
    end

21
    it 'should return the correct creator' do
22
      expect(issue.send(:owner).id).to eq(issue.author_id)
23 24 25 26 27 28 29 30
    end

    it 'should be invalid if spam' do
      issue.spam = true
      expect(issue.valid?).to be_truthy
    end

    it 'should be submittable' do
31
      create(:user_agent_detail, subject: issue)
32 33
      expect(issue.can_be_submitted?).to be_truthy
    end
34 35 36 37 38 39 40 41 42 43 44

    describe '#check_for_spam?' do
      it 'returns true for public project' do
        issue.project.update_attribute(:visibility_level, Gitlab::VisibilityLevel::PUBLIC)
        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
45 46 47 48
  end

  describe 'AkismetMethods' do
    before do
49 50
      allow_any_instance_of(Gitlab::AkismetHelper).to receive_messages(is_spam?: true, spam!: true, akismet_enabled?: true)
      allow_any_instance_of(Spammable).to receive(:can_be_submitted?).and_return(true)
51 52
    end

53
    it { expect(issue.spam_detected?(:mock_env)).to be_truthy }
54
    it { expect(issue.submit_spam).to be_truthy }
55 56
  end
end