list_spec.rb 2.1 KB
Newer Older
D
Douglas Barbosa Alexandre 已提交
1 2 3 4 5 6 7 8
require 'rails_helper'

describe List do
  describe 'relationships' do
    it { is_expected.to belong_to(:board) }
    it { is_expected.to belong_to(:label) }
  end

9 10 11 12
  describe 'delegate methods' do
    it { is_expected.to delegate_method(:name).to(:label).with_prefix }
  end

D
Douglas Barbosa Alexandre 已提交
13 14 15 16 17 18 19
  describe 'validations' do
    it { is_expected.to validate_presence_of(:board) }
    it { is_expected.to validate_presence_of(:label) }
    it { is_expected.to validate_presence_of(:list_type) }
    it { is_expected.to validate_presence_of(:position) }
    it { is_expected.to validate_numericality_of(:position).only_integer.is_greater_than_or_equal_to(0) }

20 21
    context 'when list_type is set to backlog' do
      subject { described_class.new(list_type: :backlog) }
D
Douglas Barbosa Alexandre 已提交
22

23 24
      it { is_expected.not_to validate_presence_of(:label) }
      it { is_expected.not_to validate_presence_of(:position) }
D
Douglas Barbosa Alexandre 已提交
25 26
    end

27 28
    context 'when list_type is set to done' do
      subject { described_class.new(list_type: :done) }
D
Douglas Barbosa Alexandre 已提交
29

30 31
      it { is_expected.not_to validate_presence_of(:label) }
      it { is_expected.not_to validate_presence_of(:position) }
D
Douglas Barbosa Alexandre 已提交
32 33
    end
  end
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54

  describe '#destroy' do
    it 'can be destroyed when when list_type is set to label' do
      subject = create(:label_list)

      expect(subject.destroy).to be_truthy
    end

    it 'can not be destroyed when list_type is set to backlog' do
      subject = create(:backlog_list)

      expect(subject.destroy).to be_falsey
    end

    it 'can not be destroyed when when list_type is set to done' do
      subject = create(:done_list)

      expect(subject.destroy).to be_falsey
    end
  end

55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
  describe '#title' do
    it 'returns label name when list_type is set to label' do
      subject.list_type = :label
      subject.label = Label.new(name: 'Development')

      expect(subject.title).to eq 'Development'
    end

    it 'returns Backlog when list_type is set to backlog' do
      subject.list_type = :backlog

      expect(subject.title).to eq 'Backlog'
    end

    it 'returns Done when list_type is set to done' do
      subject.list_type = :done

      expect(subject.title).to eq 'Done'
    end
  end
D
Douglas Barbosa Alexandre 已提交
75
end