summaryrefslogtreecommitdiff
path: root/spec/models/work_items/widgets/description_spec.rb
blob: c24dc9cfb9c93e6fafad5f1f1b62554ac73b19c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe WorkItems::Widgets::Description do
  let_it_be(:user) { create(:user) }
  let_it_be(:work_item, refind: true) do
    create(:work_item, description: 'Title', last_edited_at: 10.days.ago, last_edited_by: user)
  end

  describe '.type' do
    subject { described_class.type }

    it { is_expected.to eq(:description) }
  end

  describe '#type' do
    subject { described_class.new(work_item).type }

    it { is_expected.to eq(:description) }
  end

  describe '#description' do
    subject { described_class.new(work_item).description }

    it { is_expected.to eq(work_item.description) }
  end

  describe '#edited?' do
    subject { described_class.new(work_item).edited? }

    it { is_expected.to be_truthy }
  end

  describe '#last_edited_at' do
    subject { described_class.new(work_item).last_edited_at }

    it { is_expected.to eq(work_item.last_edited_at) }
  end

  describe '#last_edited_by' do
    subject { described_class.new(work_item).last_edited_by }

    context 'when the work item is edited' do
      context 'when last edited user still exists in the DB' do
        it { is_expected.to eq(user) }
      end

      context 'when last edited user no longer exists' do
        before do
          work_item.update!(last_edited_by: nil)
        end

        it { is_expected.to eq(User.ghost) }
      end
    end

    context 'when the work item is not edited yet' do
      before do
        work_item.update!(last_edited_at: nil)
      end

      it { is_expected.to be_nil }
    end
  end
end