Commit 06bb783f authored by Mark Chao's avatar Mark Chao

Update epic date fields when Epic/Issue/Milestone is updated

1. When milestone's dates changes
2. When issue changes milestone
3. When epic's issues change
4. When Epic changes date fields

Convert use of any_instance as it does not work with prepend
parent 695d71d4
......@@ -2,6 +2,7 @@
module Issues
class UpdateService < Issues::BaseService
prepend EE::Issues::UpdateService
include SpamCheckService
def execute(issue)
......
......@@ -2,6 +2,8 @@
module Milestones
class UpdateService < Milestones::BaseService
prepend EE::Milestones::UpdateService
def execute(milestone)
state = params[:state_event]
......
module EE
module Issues
module UpdateService
extend ::Gitlab::Utils::Override
override :execute
def execute(issue)
result = super
if (params.include?(:milestone) || params.include?(:milestone_id)) && issue.epic
issue.epic.update_dates
end
result
end
end
end
end
module EE
module Milestones
module UpdateService
extend ::Gitlab::Utils::Override
override :execute
def execute(milestone)
super
milestone.issues.includes(epic: :group).each do |issue|
if issue.epic
issue.epic.update_dates
end
end
milestone
end
end
end
end
module EpicIssues
class CreateService < IssuableLinks::CreateService
def execute
result = super
issuable.update_dates
result
end
private
def relate_issues(referenced_issue)
......
module EpicIssues
class DestroyService < IssuableLinks::DestroyService
def execute
result = super
link.epic.update_dates
result
end
private
def source
......
......@@ -7,6 +7,10 @@ module Epics
update(epic)
if (params.keys & [:start_date_fixed, :start_date_is_fixed, :due_date_fixed, :due_date_is_fixed]).present?
epic.update_dates
end
epic
end
......
require 'spec_helper'
describe Issues::UpdateService do
let(:issue) { create(:issue) }
let(:user) { issue.author }
let(:project) { issue.project }
describe 'execute' do
def update_issue(opts)
described_class.new(project, user, opts).execute(issue)
end
context 'refresh epic dates' do
let(:epic) { create(:epic) }
let(:issue) { create(:issue, epic: epic) }
context 'updating milestone' do
let(:milestone) { create(:milestone) }
it 'calls epic#update_dates' do
expect(epic).to receive(:update_dates).twice
update_issue(milestone: milestone)
update_issue(milestone_id: nil)
end
end
context 'updating other fields' do
it 'does not call epic#update_dates' do
expect(epic).not_to receive(:update_dates)
update_issue(title: 'foo')
end
end
end
end
end
......@@ -268,6 +268,13 @@ describe EpicIssues::CreateService do
include_examples 'returns an error'
end
context 'refresh epic dates' do
it 'calls epic#update_dates' do
expect(epic).to receive(:update_dates)
assign_issue([valid_reference])
end
end
end
end
end
......@@ -75,6 +75,13 @@ describe EpicIssues::DestroyService do
is_expected.to eq(message: 'No Issue Link found', status: :error, http_status: 404)
end
end
context 'refresh epic dates' do
it 'calls epic#update_dates' do
expect(epic).to receive(:update_dates)
subject
end
end
end
end
end
......@@ -129,5 +129,21 @@ describe Epics::UpdateService do
expect(epic.due_date).to eq(nil)
end
end
context 'refresh epic dates' do
context 'date fields are updated' do
it 'calls epic#update_dates' do
expect(epic).to receive(:update_dates)
update_epic(start_date_is_fixed: true, start_date_fixed: Date.today)
end
end
context 'date fields are not updated' do
it 'does not call epic#update_dates' do
expect(epic).not_to receive(:update_dates)
update_epic(title: 'foo')
end
end
end
end
end
require 'spec_helper'
describe Milestones::UpdateService do
let(:project) { create(:project) }
let(:user) { build(:user) }
let(:milestone) { create(:milestone, project: project) }
describe '#execute' do
context 'refresh related epic dates' do
let(:epic) { create(:epic) }
let!(:issue) { create(:issue, milestone: milestone, epic: epic) }
let(:due_date) { 3.days.from_now.to_date }
it 'calls epic#update_dates' do
described_class.new(project, user, { due_date: due_date }).execute(milestone)
epic.reload
expect(epic.due_date).to eq(due_date)
end
end
end
end
require 'spec_helper'
describe Milestones::UpdateService do
let(:project) { create(:project) }
let(:user) { build(:user) }
let(:milestone) { create(:milestone, project: project) }
describe '#execute' do
context "valid params" do
before do
project.add_maintainer(user)
@milestone = described_class.new(project, user, { title: 'new_title' }).execute(milestone)
end
it { expect(@milestone).to be_valid }
it { expect(@milestone.title).to eq('new_title') }
end
end
end
......@@ -145,7 +145,9 @@ describe Notes::CreateService do
let(:note_text) { %(HELLO\n/close\n/assign @#{user.username}\nWORLD) }
it 'saves the note and does not alter the note text' do
expect_any_instance_of(Issues::UpdateService).to receive(:execute).and_call_original
service = double(:service)
allow(Issues::UpdateService).to receive(:new).and_return(service)
expect(service).to receive(:execute)
note = described_class.new(project, user, opts.merge(note: note_text)).execute
......
......@@ -4,7 +4,9 @@ shared_examples 'issues move service' do |group|
let(:params) { { board_id: board1.id, from_list_id: list1.id, to_list_id: list2.id } }
it 'delegates the label changes to Issues::UpdateService' do
expect_any_instance_of(Issues::UpdateService).to receive(:execute).with(issue).once
service = double(:service)
expect(Issues::UpdateService).to receive(:new).and_return(service)
expect(service).to receive(:execute).with(issue).once
described_class.new(parent, user, params).execute(issue)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment