Welcome to mirror list, hosted at ThFree Co, Russian Federation.

update_service_spec.rb « start_and_due_date_service « widgets « work_items « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d328c541fc7f7d7e19ad1d5b0a29c712157c25d0 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe WorkItems::Widgets::StartAndDueDateService::UpdateService do
  let_it_be(:user) { create(:user) }
  let_it_be(:project) { create(:project) }
  let_it_be_with_reload(:work_item) { create(:work_item, project: project) }

  let(:widget) { work_item.widgets.find { |widget| widget.is_a?(WorkItems::Widgets::StartAndDueDate) } }

  describe '#before_update_callback' do
    let(:start_date) { Date.today }
    let(:due_date) { 1.week.from_now.to_date }

    subject(:update_params) do
      described_class.new(widget: widget, current_user: user).before_update_callback(params: params)
    end

    context 'when start and due date params are present' do
      let(:params) { { start_date: Date.today, due_date: 1.week.from_now.to_date } }

      it 'correctly sets date values' do
        expect do
          update_params
        end.to change(work_item, :start_date).from(nil).to(start_date).and(
          change(work_item, :due_date).from(nil).to(due_date)
        )
      end
    end

    context 'when date params are not present' do
      let(:params) { {} }

      it 'does not change work item date values' do
        expect do
          update_params
        end.to not_change(work_item, :start_date).from(nil).and(
          not_change(work_item, :due_date).from(nil)
        )
      end
    end

    context 'when work item had both date values already set' do
      before do
        work_item.update!(start_date: start_date, due_date: due_date)
      end

      context 'when one of the two params is null' do
        let(:params) { { start_date: nil } }

        it 'sets only one date to null' do
          expect do
            update_params
          end.to change(work_item, :start_date).from(start_date).to(nil).and(
            not_change(work_item, :due_date).from(due_date)
          )
        end
      end
    end
  end
end