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

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

D
Douglas Barbosa Alexandre 已提交
9 10 11 12 13 14 15
  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) }

16 17
    context 'when list_type is set to closed' do
      subject { described_class.new(list_type: :closed) }
D
Douglas Barbosa Alexandre 已提交
18

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

  describe '#destroy' do
    it 'can be destroyed when when list_type is set to label' do
26
      subject = create(:list)
27 28 29 30

      expect(subject.destroy).to be_truthy
    end

31 32
    it 'can not be destroyed when when list_type is set to closed' do
      subject = create(:closed_list)
33 34 35 36 37

      expect(subject.destroy).to be_falsey
    end
  end

38
  describe '#destroyable?' do
39
    it 'returns true when list_type is set to label' do
40 41 42 43 44
      subject.list_type = :label

      expect(subject).to be_destroyable
    end

45 46
    it 'returns false when list_type is set to closed' do
      subject.list_type = :closed
47 48 49 50 51

      expect(subject).not_to be_destroyable
    end
  end

52
  describe '#movable?' do
53
    it 'returns true when list_type is set to label' do
54 55 56 57 58
      subject.list_type = :label

      expect(subject).to be_movable
    end

59 60
    it 'returns false when list_type is set to closed' do
      subject.list_type = :closed
61 62 63 64 65

      expect(subject).not_to be_movable
    end
  end

66 67 68 69 70 71 72 73
  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

74 75
    it 'returns Closed when list_type is set to closed' do
      subject.list_type = :closed
76

77
      expect(subject.title).to eq 'Closed'
78 79
    end
  end
D
Douglas Barbosa Alexandre 已提交
80
end