Skip to content
Snippets Groups Projects
Verified Commit aeafb54a authored by Kassio Borges's avatar Kassio Borges :three: Committed by GitLab
Browse files

Revert "Merge branch 'kassio/ensure-legacy-epic-dates-are-the-same-as-workitems' into 'master' "

This reverts commit 2435ee04, reversing
changes made to f6897b9b.
parent 7d395150
No related branches found
No related tags found
2 merge requests!180727Resolve "Extend job archival mechanism to the whole pipeline",!180619Extract WorkItem Roll up dates logic to be reusable on LegacyEpics
Showing
with 644 additions and 138 deletions
# frozen_string_literal: true
module WorkItems
class RollupableDates
include ::Gitlab::Utils::StrongMemoize
def initialize(source, can_rollup:)
@source = source
@can_rollup = can_rollup
end
def fixed?
return true unless @can_rollup
return true if source.start_date_is_fixed && source.start_date_fixed.present?
return true if source.due_date_is_fixed && source.due_date_fixed.present?
return true if source.start_date_is_fixed && source.due_date_is_fixed
false
end
strong_memoize_attr :fixed?
def start_date
return source.start_date_fixed if fixed?
source.start_date
end
def start_date_fixed
source.start_date_fixed
end
def due_date
return source.due_date_fixed if fixed?
source.due_date
end
def due_date_fixed
source.due_date_fixed
end
private
attr_reader :source
end
end
WorkItems::RollupableDates.prepend_mod
......@@ -39,7 +39,7 @@ def sorting_keys
# rubocop:disable Gitlab/NoCodeCoverageComment -- overridden and tested in EE
# :nocov:
def fixed?
true
rollupable_dates.fixed?
end
def can_rollup?
......@@ -51,23 +51,24 @@ def can_rollup?
def start_date
return work_item&.start_date unless dates_source_present?
dates_source.start_date_fixed
rollupable_dates.start_date
end
def due_date
return work_item&.due_date unless dates_source_present?
dates_source.due_date_fixed
rollupable_dates.due_date
end
private
def dates_source
return DatesSource.new if work_item.blank?
work_item.dates_source || work_item.build_dates_source
def rollupable_dates
WorkItems::RollupableDates.new(
work_item.dates_source || work_item.build_dates_source,
can_rollup: can_rollup?
)
end
strong_memoize_attr :dates_source
strong_memoize_attr :rollupable_dates
def dates_source_present?
return false if work_item&.dates_source.blank?
......@@ -77,6 +78,7 @@ def dates_source_present?
.slice(:start_date, :start_date_fixed, :due_date, :due_date_fixed)
.any? { |_, value| value.present? }
end
strong_memoize_attr :dates_source_present?
end
end
end
......
......@@ -120,13 +120,11 @@ def preloads
start_date_from_inherited_source: [:start_date_sourcing_milestone, :start_date_sourcing_epic],
due_date_from_milestones: [:due_date_sourcing_milestone],
due_date_from_inherited_source: [:due_date_sourcing_milestone, :due_date_sourcing_epic],
linked_work_items: [:work_item],
work_item: [:dates_source]
linked_work_items: [:work_item]
}
end
def find_epics(args)
Gitlab::QueryLimiting.disable!('https://gitlab.com/gitlab-org/gitlab/-/issues/501712', new_threshold: 300)
apply_lookahead(EpicsFinder.new(context[:current_user], args).execute)
end
......
......@@ -118,10 +118,10 @@ module Epic
scope :with_web_entity_associations, -> { preload(:author, group: [:ip_restrictions, :route]) }
scope :with_api_entity_associations, -> do
preload(:author, :sync_object, { work_item: :dates_source }, :labels, :parent, group: [:saml_provider, :route])
preload(:author, :sync_object, :labels, :parent, group: [:saml_provider, :route])
end
scope :preload_for_indexing, -> do
includes(:author, :sync_object, { work_item: :dates_source }, :group, :start_date_sourcing_epic, :due_date_sourcing_epic,
includes(:author, :sync_object, :group, :start_date_sourcing_epic, :due_date_sourcing_epic,
:start_date_sourcing_milestone, :due_date_sourcing_milestone)
end
scope :preload_group_and_routables, -> { preload(group: [:route, :ip_restrictions, :saml_provider]) }
......
# frozen_string_literal: true
module EE
module WorkItems
module RollupableDates
def start_date_sourcing_milestone
return if fixed?
source.start_date_sourcing_milestone
end
def start_date_sourcing_work_item
return if fixed?
source.try(:start_date_sourcing_work_item) ||
source.try(:start_date_sourcing_epic)&.work_item
end
def start_date_sourcing_epic
return if fixed?
source.try(:start_date_sourcing_epic) ||
source.try(:start_date_sourcing_work_item)&.synced_epic
end
def due_date_sourcing_milestone
return if fixed?
source.due_date_sourcing_milestone
end
def due_date_sourcing_work_item
return if fixed?
source.try(:due_date_sourcing_work_item) ||
source.try(:due_date_sourcing_epic)&.work_item
end
def due_date_sourcing_epic
return if fixed?
source.try(:due_date_sourcing_epic) ||
source.try(:due_date_sourcing_work_item)&.synced_epic
end
end
end
end
......@@ -14,59 +14,27 @@ def sync_params
end
end
def start_date
return super if fixed?
return work_item&.start_date unless dates_source_present?
dates_source.start_date
override :can_rollup?
def can_rollup?
work_item&.work_item_type&.allowed_child_types.present?
end
strong_memoize_attr :can_rollup?
def start_date_sourcing_work_item
return if fixed?
dates_source.start_date_sourcing_work_item
rollupable_dates.start_date_sourcing_work_item
end
def start_date_sourcing_milestone
return if fixed?
dates_source.start_date_sourcing_milestone
end
def due_date
return super if fixed?
return work_item&.due_date unless dates_source_present?
dates_source.due_date
rollupable_dates.start_date_sourcing_milestone
end
def due_date_sourcing_work_item
return if fixed?
dates_source.due_date_sourcing_work_item
rollupable_dates.due_date_sourcing_work_item
end
def due_date_sourcing_milestone
return if fixed?
dates_source.due_date_sourcing_milestone
end
override :fixed?
def fixed?
return true unless can_rollup?
return true if dates_source.start_date_is_fixed && dates_source.start_date_fixed.present?
return true if dates_source.due_date_is_fixed && dates_source.due_date_fixed.present?
dates_source.start_date_is_fixed && dates_source.due_date_is_fixed
end
strong_memoize_attr :fixed?
override :can_rollup?
def can_rollup?
work_item&.work_item_type&.allowed_child_types.present?
rollupable_dates.due_date_sourcing_milestone
end
strong_memoize_attr :can_rollup?
end
end
end
......
......@@ -56,24 +56,24 @@ def subscribed?
:due_date_is_fixed?
def start_date
start_and_due_date_widget.start_date
rollupable_dates.start_date
end
alias_method :start_date_fixed, :start_date
def due_date
start_and_due_date_widget.due_date
rollupable_dates.due_date
end
alias_method :due_date_fixed, :due_date
def start_date_is_fixed?
start_and_due_date_widget.fixed?
rollupable_dates.fixed?
end
alias_method :due_date_is_fixed?, :start_date_is_fixed?
private
def start_and_due_date_widget
@start_and_due_date_widget ||= epic.work_item.get_widget(:start_and_due_date)
def rollupable_dates
@rollupable_dates ||= WorkItems::RollupableDates.new(epic, can_rollup: true)
end
def initial_data
......
......@@ -74,10 +74,6 @@ def child_epics
use :child_epic_id
end
post ':id/(-/)epics/:epic_iid/epics/:child_epic_id' do
# To present epic dates using WorkItems logic, we need to load the associated WorkItem and
# WorkItems::DatesSource
Gitlab::QueryLimiting.disable!('https://gitlab.com/gitlab-org/gitlab/-/issues/501712', new_threshold: 200)
authorize_create_epic_tree_relation!
target_child_epic = Epic.find_by_id(declared_params[:child_epic_id])
......
......@@ -318,9 +318,6 @@ class Epics < ::API::Base
:start_date, :end_date
end
put ':id/(-/)epics/:epic_iid' do
# To present epic dates using WorkItems logic, we need to load the associated WorkItem and
# WorkItems::DatesSource
Gitlab::QueryLimiting.disable!('https://gitlab.com/gitlab-org/gitlab/-/issues/501712', new_threshold: 200)
authorize_can_admin_epic!
# Setting updated_at is allowed only for admins and owners
......
......@@ -89,11 +89,9 @@
describe 'use work item logic to present dates' do
using RSpec::Parameterized::TableSyntax
let_it_be(:epic) { create(:epic) }
let_it_be(:work_items_dates_source) do
create(
:work_items_dates_source,
work_item: epic.work_item,
let_it_be(:epic) do
build_stubbed(
:epic,
start_date: 1.day.ago,
start_date_fixed: 2.days.ago,
start_date_is_fixed: true,
......@@ -103,8 +101,6 @@
)
end
let(:widget) { epic.work_item.get_widget(:start_and_due_date) }
where(:field, :result) do
:start_date | 2.days.ago.to_date
:start_date_fixed | 2.days.ago.to_date
......
# frozen_string_literal: true
require "spec_helper"
RSpec.describe WorkItems::RollupableDates, feature_category: :team_planning do
let_it_be(:sourcing_milestone) { create(:milestone) }
let_it_be(:sourcing_work_item) { create(:work_item, :epic) }
let_it_be(:sourcing_epic) { create(:epic, work_item: sourcing_work_item) }
context 'when using legacy epics' do
let(:source) { build_stubbed(:epic) }
it_behaves_like 'rollupable dates - when can_rollup is false' do
subject(:rollupable_dates) { described_class.new(source, can_rollup: false) }
describe '#start_date_sourcing_milestone' do
before do
source.assign_attributes(start_date_sourcing_milestone_id: sourcing_milestone.id)
end
specify { expect(rollupable_dates.start_date_sourcing_milestone).to be_nil }
end
describe '#start_date_sourcing_epic' do
before do
source.assign_attributes(start_date_sourcing_epic_id: sourcing_epic.id)
end
specify { expect(rollupable_dates.start_date_sourcing_epic).to be_nil }
end
describe '#start_date_sourcing_work_item' do
before do
source.assign_attributes(start_date_sourcing_epic_id: sourcing_epic.id)
end
specify { expect(rollupable_dates.start_date_sourcing_work_item).to be_nil }
end
end
it_behaves_like 'rollupable dates - when can_rollup is true' do
subject(:rollupable_dates) { described_class.new(source, can_rollup: true) }
describe '#start_date_sourcing_milestone' do
before do
source.assign_attributes(start_date_sourcing_milestone_id: sourcing_milestone.id)
end
specify { expect(rollupable_dates.start_date_sourcing_milestone).to eq(sourcing_milestone) }
end
describe '#start_date_sourcing_epic' do
before do
source.assign_attributes(start_date_sourcing_epic_id: sourcing_epic.id)
end
specify { expect(rollupable_dates.start_date_sourcing_epic).to eq(sourcing_epic) }
end
describe '#start_date_sourcing_work_item' do
context 'when source does not have a sourcing epic id' do
before do
source.assign_attributes(start_date_sourcing_epic_id: nil)
end
specify { expect(rollupable_dates.start_date_sourcing_work_item).to be_nil }
end
context 'when source has a sourcing epic' do
before do
source.assign_attributes(start_date_sourcing_epic_id: sourcing_epic.id)
end
specify { expect(rollupable_dates.start_date_sourcing_work_item).to eq(sourcing_epic.work_item) }
end
end
describe '#due_date_sourcing_milestone' do
before do
source.assign_attributes(due_date_sourcing_milestone_id: sourcing_milestone.id)
end
specify { expect(rollupable_dates.due_date_sourcing_milestone).to eq(sourcing_milestone) }
end
describe '#due_date_sourcing_epic' do
before do
source.assign_attributes(due_date_sourcing_epic_id: sourcing_epic.id)
end
specify { expect(rollupable_dates.due_date_sourcing_epic).to eq(sourcing_epic) }
end
describe '#due_date_sourcing_work_item' do
context 'when source does not have a sourcing epic id' do
before do
source.assign_attributes(due_date_sourcing_epic_id: nil)
end
specify { expect(rollupable_dates.due_date_sourcing_work_item).to be_nil }
end
context 'when source has a sourcing epic' do
before do
source.assign_attributes(due_date_sourcing_epic_id: sourcing_epic.id)
end
specify { expect(rollupable_dates.due_date_sourcing_work_item).to eq(sourcing_epic.work_item) }
end
end
end
end
context 'when using work item dates source' do
let(:source) { build_stubbed(:work_items_dates_source) }
it_behaves_like 'rollupable dates - when can_rollup is false' do
subject(:rollupable_dates) { described_class.new(source, can_rollup: false) }
describe '#start_date_sourcing_milestone' do
before do
source.assign_attributes(start_date_sourcing_milestone_id: sourcing_milestone.id)
end
specify { expect(rollupable_dates.start_date_sourcing_milestone).to be_nil }
end
describe '#start_date_sourcing_epic' do
before do
source.assign_attributes(start_date_sourcing_work_item_id: sourcing_work_item.id)
end
specify { expect(rollupable_dates.start_date_sourcing_epic).to be_nil }
end
describe '#start_date_sourcing_work_item' do
before do
source.assign_attributes(start_date_sourcing_work_item_id: sourcing_work_item.id)
end
specify { expect(rollupable_dates.start_date_sourcing_work_item).to be_nil }
end
describe '#due_date_sourcing_epic' do
before do
source.assign_attributes(due_date_sourcing_work_item_id: sourcing_work_item.id)
end
specify { expect(rollupable_dates.due_date_sourcing_epic).to be_nil }
end
describe '#due_date_sourcing_work_item' do
before do
source.assign_attributes(due_date_sourcing_work_item_id: sourcing_work_item.id)
end
specify { expect(rollupable_dates.due_date_sourcing_work_item).to be_nil }
end
end
it_behaves_like 'rollupable dates - when can_rollup is true' do
subject(:rollupable_dates) { described_class.new(source, can_rollup: true) }
describe '#start_date_sourcing_milestone' do
before do
source.assign_attributes(start_date_sourcing_milestone_id: sourcing_milestone.id)
end
specify { expect(rollupable_dates.start_date_sourcing_milestone).to eq(sourcing_milestone) }
end
describe '#start_date_sourcing_epic' do
context 'when source does not have a sourcing work_item id' do
before do
source.assign_attributes(start_date_sourcing_work_item_id: nil)
end
specify { expect(rollupable_dates.start_date_sourcing_epic).to be_nil }
end
context 'when source has a sourcing work_item' do
before do
source.assign_attributes(start_date_sourcing_work_item_id: sourcing_work_item.id)
end
specify { expect(rollupable_dates.start_date_sourcing_epic).to eq(sourcing_epic) }
end
end
describe '#start_date_sourcing_work_item' do
before do
source.assign_attributes(start_date_sourcing_work_item_id: sourcing_work_item.id)
end
specify { expect(rollupable_dates.start_date_sourcing_work_item).to eq(sourcing_work_item) }
end
describe '#due_date_sourcing_epic' do
context 'when source does not have a sourcing work_item id' do
before do
source.assign_attributes(due_date_sourcing_work_item_id: nil)
end
specify { expect(rollupable_dates.due_date_sourcing_epic).to be_nil }
end
context 'when source has a sourcing work_item' do
before do
source.assign_attributes(due_date_sourcing_work_item_id: sourcing_work_item.id)
end
specify { expect(rollupable_dates.due_date_sourcing_epic).to eq(sourcing_epic) }
end
end
describe '#due_date_sourcing_work_item' do
before do
source.assign_attributes(due_date_sourcing_work_item_id: sourcing_work_item.id)
end
specify { expect(rollupable_dates.due_date_sourcing_work_item).to eq(sourcing_work_item) }
end
end
end
end
......@@ -120,14 +120,13 @@
end
end
describe 'use work item logic to present dates' do
describe 'use work item logic to present dates', :freeze_time do
using RSpec::Parameterized::TableSyntax
let_it_be(:epic) { create(:epic, :with_synced_work_item) }
let_it_be(:work_items_dates_source) do
create(
:work_items_dates_source,
work_item: epic.work_item,
let_it_be(:epic) do
build_stubbed(
:epic,
:with_synced_work_item,
start_date: 1.day.ago,
start_date_fixed: 2.days.ago,
start_date_is_fixed: true,
......@@ -137,8 +136,6 @@
)
end
let(:widget) { epic.work_item.get_widget(:start_and_due_date) }
where(:field, :result) do
:start_date | 2.days.ago.to_date
:start_date_fixed | 2.days.ago.to_date
......
......@@ -100,10 +100,9 @@ def get_epics
create_list(:epic, 2, parent: epic)
# Executes extra queries
# `SELECT COUNT(*) FROM "award_emoji"...` - https://gitlab.com/gitlab-org/gitlab/-/issues/382164
# Loads associate WorkItem and WorkItems::DatesSource - https://gitlab.com/gitlab-org/gitlab/-/issues/501712
expect { get_epics }.not_to exceed_all_query_limit(control).with_threshold(11)
# Executes 2 extra `SELECT COUNT(*) FROM "award_emoji"...` per child
# See https://gitlab.com/gitlab-org/gitlab/-/issues/382164
expect { get_epics }.not_to exceed_all_query_limit(control).with_threshold(4)
end
end
end
......
......@@ -117,9 +117,7 @@
create_list(:epic, 2, group: subgroup_1, parent_id: epic1.id)
create_list(:epic, 2, group: subgroup_2, parent_id: epic2.id)
expect { get api(url, personal_access_token: pat), params: params }
.not_to exceed_all_query_limit(control)
.with_threshold(50)
expect { get api(url, personal_access_token: pat), params: params }.not_to exceed_all_query_limit(control)
expect(response).to have_gitlab_http_status(:ok)
end
......@@ -147,9 +145,9 @@
label_2 = create(:group_label)
create_list(:labeled_epic, 4, group: group, labels: [label_2])
expect { get api(url, personal_access_token: pat), params: params }
.not_to exceed_all_query_limit(control)
.with_threshold(15)
expect do
get api(url, personal_access_token: pat), params: params
end.not_to exceed_all_query_limit(control)
end
it 'returns labels with details' do
......@@ -688,7 +686,7 @@
before do
# TODO: remove threshold after epic-work item sync
# issue: https://gitlab.com/gitlab-org/gitlab/-/issues/438295
allow(Gitlab::QueryLimiting::Transaction).to receive(:threshold).and_return(150)
allow(Gitlab::QueryLimiting::Transaction).to receive(:threshold).and_return(140)
stub_licensed_features(epics: true, subepics: true)
group.add_developer(user)
end
......@@ -915,7 +913,7 @@
it 'creates a new epic with labels param as array' do
# TODO: remove threshold after epic-work item sync
# issue: https://gitlab.com/gitlab-org/gitlab/-/issues/438295
allow(Gitlab::QueryLimiting::Transaction).to receive(:threshold).and_return(180)
allow(Gitlab::QueryLimiting::Transaction).to receive(:threshold).and_return(160)
params[:labels] = ['label1', 'label2', 'foo, bar', '&,?']
post api(url, user), params: params
......@@ -1009,7 +1007,7 @@
before do
# TODO: reduce threshold after epic-work item sync
# issue: https://gitlab.com/gitlab-org/gitlab/-/issues/438295
allow(Gitlab::QueryLimiting::Transaction).to receive(:threshold).and_return(189)
allow(Gitlab::QueryLimiting::Transaction).to receive(:threshold).and_return(190)
group.add_developer(user)
end
......
# frozen_string_literal: true
require "spec_helper"
RSpec.describe WorkItems::RollupableDates, :freeze_time, feature_category: :team_planning do
context 'when using work item dates source' do
let(:source) { build_stubbed(:work_items_dates_source) }
it_behaves_like 'rollupable dates - when can_rollup is false' do
subject(:rollupable_dates) { described_class.new(source, can_rollup: false) }
end
it_behaves_like 'rollupable dates - when can_rollup is true' do
subject(:rollupable_dates) { described_class.new(source, can_rollup: true) }
end
end
end
......@@ -23,67 +23,55 @@
specify { expect(described_class.quick_action_commands).to contain_exactly(:due, :remove_due_date) }
end
describe '#fixed?' do
specify { expect(widget.fixed?).to be(true) }
end
context 'when on FOSS', unless: Gitlab.ee? do
let(:work_item) { build_stubbed(:work_item, start_date: Time.zone.today, due_date: 1.week.from_now) }
describe '#can_rollup?' do
specify { expect(widget.can_rollup?).to be(false) }
end
describe '#fixed?' do
specify { expect(widget.fixed?).to be(true) }
end
context 'when on FOSS', unless: Gitlab.ee? do
context 'and work_item does not exist' do
describe '#can_rollup?' do
specify { expect(widget.can_rollup?).to be(false) }
end
context 'and work_item does not have a dates_source' do
describe '#start_date' do
specify { expect(widget.start_date).to be_nil }
specify { expect(widget.start_date).to eq(work_item.start_date) }
end
describe '#due_date' do
specify { expect(widget.due_date).to be_nil }
specify { expect(widget.due_date).to eq(work_item.due_date) }
end
end
context 'and work_item exists' do
let(:work_item) { build_stubbed(:work_item, start_date: Time.zone.today, due_date: 1.week.from_now) }
context 'and work_item does not have a dates_source' do
describe '#start_date' do
specify { expect(widget.start_date).to eq(work_item.start_date) }
end
context 'and work_item does have an empty dates_source' do
before do
work_item.build_dates_source
end
describe '#due_date' do
specify { expect(widget.due_date).to eq(work_item.due_date) }
end
describe '#start_date' do
specify { expect(widget.start_date).to eq(work_item.start_date) }
end
context 'and work_item does have an empty dates_source' do
before do
work_item.build_dates_source
end
describe '#due_date' do
specify { expect(widget.due_date).to eq(work_item.due_date) }
end
end
describe '#start_date' do
specify { expect(widget.start_date).to eq(work_item.start_date) }
end
context 'and work_item does have a non empty dates_source' do
let!(:dates_source) do
work_item.build_dates_source(
start_date_fixed: work_item.start_date - 1.day,
due_date_fixed: work_item.due_date + 1.day
)
end
describe '#due_date' do
specify { expect(widget.due_date).to eq(work_item.due_date) }
end
describe '#start_date' do
specify { expect(widget.start_date).to eq(dates_source.start_date_fixed) }
end
context 'and work_item does have a non empty dates_source' do
let!(:dates_source) do
work_item.build_dates_source(
start_date_fixed: work_item.start_date - 1.day,
due_date_fixed: work_item.due_date + 1.day
)
end
describe '#start_date' do
specify { expect(widget.start_date).to eq(dates_source.start_date_fixed) }
end
describe '#due_date' do
specify { expect(widget.due_date).to eq(dates_source.due_date_fixed) }
end
describe '#due_date' do
specify { expect(widget.due_date).to eq(dates_source.due_date_fixed) }
end
end
end
......
# frozen_string_literal: true
RSpec.shared_examples_for 'rollupable dates - when can_rollup is false' do
using RSpec::Parameterized::TableSyntax
describe '#fixed?' do
# Rules defined on https://gitlab.com/groups/gitlab-org/-/epics/11409#rules
where(:start_date_is_fixed, :start_date_fixed, :due_date_is_fixed, :due_date_fixed) do
false | nil | false | nil
false | nil | false | 2.days.from_now
false | 2.days.ago | false | nil
false | 2.days.ago | false | 2.days.from_now
true | 2.days.ago | false | nil
false | nil | true | 2.days.from_now
true | nil | true | nil
true | 2.days.ago | true | 2.days.from_now
end
with_them do
before do
source.assign_attributes(
start_date: nil,
start_date_is_fixed: start_date_is_fixed,
start_date_fixed: start_date_fixed,
due_date: nil,
due_date_is_fixed: due_date_is_fixed,
due_date_fixed: due_date_fixed
)
end
# regardless of the conditions, it's always fixed.
specify { expect(rollupable_dates.fixed?).to be(true) }
end
end
describe '#start_date' do
where(:due_date_is_fixed, :due_date_fixed, :start_date_is_fixed, :start_date, :start_date_fixed) do
false | nil | false | nil | nil
false | nil | false | nil | 1.day.ago.to_date
false | nil | false | 2.days.ago.to_date | nil
false | nil | false | 2.days.ago.to_date | 3.days.ago.to_date
false | nil | true | 2.days.ago.to_date | nil
false | nil | true | 2.days.ago.to_date | 3.days.ago.to_date
true | 1.day.from_now | false | 2.days.ago.to_date | 1.day.ago.to_date
end
with_them do
before do
source.assign_attributes(
start_date: start_date,
start_date_fixed: start_date_fixed,
start_date_is_fixed: start_date_is_fixed,
due_date: nil,
due_date_fixed: due_date_fixed,
due_date_is_fixed: due_date_is_fixed
)
end
specify { expect(rollupable_dates.start_date).to eq(start_date_fixed) }
end
end
describe '#due_date' do
where(:start_date_is_fixed, :start_date_fixed, :due_date_is_fixed, :due_date, :due_date_fixed) do
false | nil | false | nil | nil
false | nil | false | nil | 1.day.ago.to_date
false | nil | false | 2.days.ago.to_date | nil
false | nil | false | 2.days.ago.to_date | 3.days.ago.to_date
false | nil | true | 2.days.ago.to_date | nil
false | nil | true | 2.days.ago.to_date | 3.days.ago.to_date
true | 1.day.from_now | false | 2.days.ago.to_date | 1.day.ago.to_date
end
with_them do
before do
source.assign_attributes(
start_date: nil,
start_date_fixed: start_date_fixed,
start_date_is_fixed: start_date_is_fixed,
due_date: due_date,
due_date_fixed: due_date_fixed,
due_date_is_fixed: due_date_is_fixed
)
end
specify { expect(rollupable_dates.due_date).to eq(due_date_fixed) }
end
end
describe '#start_date_fixed' do
let(:date) { Time.zone.today }
before do
source.start_date_fixed = date
end
it 'delegates to the source' do
expect(rollupable_dates.start_date_fixed).to eq(date)
end
end
describe '#due_date_fixed' do
let(:date) { Time.zone.today }
before do
source.due_date_fixed = date
end
it 'delegates to the source' do
expect(rollupable_dates.due_date_fixed).to eq(date)
end
end
end
RSpec.shared_examples_for 'rollupable dates - when can_rollup is true' do
using RSpec::Parameterized::TableSyntax
describe '#fixed?' do
# Rules defined on https://gitlab.com/groups/gitlab-org/-/epics/11409#rules
where(:start_date_is_fixed, :start_date_fixed, :due_date_is_fixed, :due_date_fixed, :expected) do
# when nothing is set, it's not fixed
false | nil | false | nil | false
# when dates_source dates are set, ignore work_item dates and
# calculate based only on dates sources values
false | nil | false | 2.days.from_now | false
false | 2.days.ago | false | nil | false
false | 2.days.ago | false | 2.days.from_now | false
# if only one _is_fixed is true and has value, it's fixed
true | 2.days.ago | false | nil | true
false | nil | true | 2.days.from_now | true
# if both _is_fixed is true, it's fixed
true | nil | true | nil | true
end
with_them do
before do
source.assign_attributes(
start_date: nil,
start_date_is_fixed: start_date_is_fixed,
start_date_fixed: start_date_fixed,
due_date: nil,
due_date_is_fixed: due_date_is_fixed,
due_date_fixed: due_date_fixed
)
end
specify { expect(rollupable_dates.fixed?).to eq(expected) }
end
end
describe '#start_date' do
where(:due_date_is_fixed, :due_date_fixed, :start_date_is_fixed, :start_date, :start_date_fixed, :expected) do
false | nil | false | nil | nil | nil
false | nil | false | nil | 1.day.ago.to_date | nil
false | nil | false | 2.days.ago.to_date | nil | 2.days.ago.to_date
false | nil | false | 2.days.ago.to_date | 3.days.ago.to_date | 2.days.ago.to_date
false | nil | true | 2.days.ago.to_date | nil | 2.days.ago.to_date
false | nil | true | 2.days.ago.to_date | 3.days.ago.to_date | 3.days.ago.to_date
# If due_date_is_fixed and due_date_fixed has a value
true | 1.day.from_now | false | 2.days.ago.to_date | 1.day.ago.to_date | 1.day.ago.to_date
end
with_them do
before do
source.assign_attributes(
start_date: start_date,
start_date_fixed: start_date_fixed,
start_date_is_fixed: start_date_is_fixed,
due_date: nil,
due_date_fixed: due_date_fixed,
due_date_is_fixed: due_date_is_fixed
)
end
specify { expect(rollupable_dates.start_date).to eq(expected) }
end
end
describe '#due_date' do
where(:start_date_is_fixed, :start_date_fixed, :due_date_is_fixed, :due_date, :due_date_fixed, :expected) do
false | nil | false | nil | nil | nil
false | nil | false | nil | 1.day.ago.to_date | nil
false | nil | false | 2.days.ago.to_date | nil | 2.days.ago.to_date
false | nil | false | 2.days.ago.to_date | 3.days.ago.to_date | 2.days.ago.to_date
false | nil | true | 2.days.ago.to_date | nil | 2.days.ago.to_date
false | nil | true | 2.days.ago.to_date | 3.days.ago.to_date | 3.days.ago.to_date
# If start_date_is_fixed and start_date_fixed has a value
true | 1.day.from_now | false | 2.days.ago.to_date | 1.day.ago.to_date | 1.day.ago.to_date
end
with_them do
before do
source.assign_attributes(
start_date: nil,
start_date_fixed: start_date_fixed,
start_date_is_fixed: start_date_is_fixed,
due_date: due_date,
due_date_fixed: due_date_fixed,
due_date_is_fixed: due_date_is_fixed
)
end
specify { expect(rollupable_dates.due_date).to eq(expected) }
end
end
describe '#start_date_fixed' do
let(:date) { Time.zone.today }
before do
source.start_date_fixed = date
end
it 'delegates to the source' do
expect(rollupable_dates.start_date_fixed).to eq(date)
end
end
describe '#due_date_fixed' do
let(:date) { Time.zone.today }
before do
source.due_date_fixed = date
end
it 'delegates to the source' do
expect(rollupable_dates.due_date_fixed).to eq(date)
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment