|
|
@ -67,10 +67,10 @@ describe WorkPackages::UpdateAncestorsService, type: :model do |
|
|
|
let(:children) do |
|
|
|
let(:children) do |
|
|
|
(statuses.size - 1).downto(0).map do |i| |
|
|
|
(statuses.size - 1).downto(0).map do |i| |
|
|
|
FactoryBot.create :work_package, |
|
|
|
FactoryBot.create :work_package, |
|
|
|
parent: parent, |
|
|
|
parent: parent, |
|
|
|
status: statuses[i] == :open ? open_status : closed_status, |
|
|
|
status: statuses[i] == :open ? open_status : closed_status, |
|
|
|
estimated_hours: estimated_hours[i], |
|
|
|
estimated_hours: estimated_hours[i], |
|
|
|
done_ratio: done_ratios[i] |
|
|
|
done_ratio: done_ratios[i] |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
let(:parent) { FactoryBot.create :work_package, status: open_status } |
|
|
|
let(:parent) { FactoryBot.create :work_package, status: open_status } |
|
|
@ -199,10 +199,10 @@ describe WorkPackages::UpdateAncestorsService, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
let!(:sibling) do |
|
|
|
let!(:sibling) do |
|
|
|
FactoryBot.create :work_package, |
|
|
|
FactoryBot.create :work_package, |
|
|
|
parent: parent, |
|
|
|
parent: parent, |
|
|
|
status: sibling_status, |
|
|
|
status: sibling_status, |
|
|
|
estimated_hours: sibling_estimated_hours, |
|
|
|
estimated_hours: sibling_estimated_hours, |
|
|
|
done_ratio: sibling_done_ratio |
|
|
|
done_ratio: sibling_done_ratio |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
let!(:work_package) do |
|
|
|
let!(:work_package) do |
|
|
@ -265,58 +265,79 @@ describe WorkPackages::UpdateAncestorsService, type: :model do |
|
|
|
end |
|
|
|
end |
|
|
|
let!(:parent) do |
|
|
|
let!(:parent) do |
|
|
|
FactoryBot.create :work_package, |
|
|
|
FactoryBot.create :work_package, |
|
|
|
parent: grandparent |
|
|
|
parent: grandparent |
|
|
|
end |
|
|
|
end |
|
|
|
let!(:work_package) do |
|
|
|
let!(:work_package) do |
|
|
|
FactoryBot.create :work_package, |
|
|
|
FactoryBot.create :work_package, |
|
|
|
status: status, |
|
|
|
status: status, |
|
|
|
estimated_hours: estimated_hours, |
|
|
|
estimated_hours: estimated_hours, |
|
|
|
done_ratio: done_ratio |
|
|
|
done_ratio: done_ratio |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
subject do |
|
|
|
shared_examples_for 'updates the attributes within the new hierarchy' do |
|
|
|
work_package.parent = parent |
|
|
|
before do |
|
|
|
work_package.save! |
|
|
|
subject |
|
|
|
work_package.parent_id_was |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
described_class |
|
|
|
it 'is successful' do |
|
|
|
.new(user: user, |
|
|
|
expect(subject) |
|
|
|
work_package: work_package) |
|
|
|
.to be_success |
|
|
|
.call(%i(parent)) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
it 'returns the new ancestors in the dependent results' do |
|
|
|
subject |
|
|
|
expect(subject.dependent_results.map(&:result)) |
|
|
|
end |
|
|
|
.to match_array [parent, grandparent] |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'is successful' do |
|
|
|
it 'updates the done_ratio of the new parent' do |
|
|
|
expect(subject) |
|
|
|
expect(parent.reload(select: :done_ratio).done_ratio) |
|
|
|
.to be_success |
|
|
|
.to eql done_ratio |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'returns the new ancestors in the dependent results' do |
|
|
|
it 'updates the estimated_hours of the new parent' do |
|
|
|
expect(subject.dependent_results.map(&:result)) |
|
|
|
expect(parent.reload(select: :derived_estimated_hours).derived_estimated_hours) |
|
|
|
.to match_array [parent, grandparent] |
|
|
|
.to eql estimated_hours |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'updates the done_ratio of the new parent' do |
|
|
|
it 'updates the done_ratio of the new grandparent' do |
|
|
|
expect(parent.reload(select: :done_ratio).done_ratio) |
|
|
|
expect(grandparent.reload(select: :done_ratio).done_ratio) |
|
|
|
.to eql done_ratio |
|
|
|
.to eql done_ratio |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'updates the estimated_hours of the new parent' do |
|
|
|
it 'updates the estimated_hours of the new grandparent' do |
|
|
|
expect(parent.reload(select: :derived_estimated_hours).derived_estimated_hours) |
|
|
|
expect(grandparent.reload(select: :derived_estimated_hours).derived_estimated_hours) |
|
|
|
.to eql estimated_hours |
|
|
|
.to eql estimated_hours |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'updates the done_ratio of the new grandparent' do |
|
|
|
context 'if setting the parent' do |
|
|
|
expect(grandparent.reload(select: :done_ratio).done_ratio) |
|
|
|
subject do |
|
|
|
.to eql done_ratio |
|
|
|
work_package.parent = parent |
|
|
|
|
|
|
|
work_package.save! |
|
|
|
|
|
|
|
work_package.parent_id_was |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
described_class |
|
|
|
|
|
|
|
.new(user: user, |
|
|
|
|
|
|
|
work_package: work_package) |
|
|
|
|
|
|
|
.call(%i(parent)) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it_behaves_like 'updates the attributes within the new hierarchy' |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'updates the estimated_hours of the new grandparent' do |
|
|
|
context 'if setting the parent_id' do |
|
|
|
expect(grandparent.reload(select: :derived_estimated_hours).derived_estimated_hours) |
|
|
|
subject do |
|
|
|
.to eql estimated_hours |
|
|
|
work_package.parent_id = parent.id |
|
|
|
|
|
|
|
work_package.save! |
|
|
|
|
|
|
|
work_package.parent_id_was |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
described_class |
|
|
|
|
|
|
|
.new(user: user, |
|
|
|
|
|
|
|
work_package: work_package) |
|
|
|
|
|
|
|
.call(%i(parent_id)) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it_behaves_like 'updates the attributes within the new hierarchy' |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|