diff options
Diffstat (limited to 'spec/models/work_items/widgets/description_spec.rb')
-rw-r--r-- | spec/models/work_items/widgets/description_spec.rb | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/spec/models/work_items/widgets/description_spec.rb b/spec/models/work_items/widgets/description_spec.rb index 8359db31bff..c24dc9cfb9c 100644 --- a/spec/models/work_items/widgets/description_spec.rb +++ b/spec/models/work_items/widgets/description_spec.rb @@ -3,7 +3,10 @@ require 'spec_helper' RSpec.describe WorkItems::Widgets::Description do - let_it_be(:work_item) { create(:work_item, description: '# Title') } + 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 } @@ -22,4 +25,42 @@ RSpec.describe WorkItems::Widgets::Description do 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 |