|
|
|
@ -105,7 +105,6 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
instance.call(**attributes.merge(send_notifications: false).symbolize_keys) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe '#call' do |
|
|
|
|
describe 'updating subject' do |
|
|
|
|
let(:attributes) { { subject: 'New subject' } } |
|
|
|
|
|
|
|
|
@ -118,7 +117,7 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe 'updating project' do |
|
|
|
|
context 'when updating the project' do |
|
|
|
|
let(:target_project) do |
|
|
|
|
p = create(:project, |
|
|
|
|
types: target_types, |
|
|
|
@ -136,7 +135,15 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
let(:target_parent) { nil } |
|
|
|
|
let(:target_types) { [type] } |
|
|
|
|
|
|
|
|
|
describe 'with missing permissions' do |
|
|
|
|
it 'is is success and updates the project' do |
|
|
|
|
expect(subject) |
|
|
|
|
.to be_success |
|
|
|
|
|
|
|
|
|
expect(work_package.reload.project) |
|
|
|
|
.to eql target_project |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'with missing permissions' do |
|
|
|
|
let(:target_permissions) { [] } |
|
|
|
|
|
|
|
|
|
it 'is failure' do |
|
|
|
@ -162,6 +169,7 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
expect(TimeEntry.where(id: time_entries.map(&:id)).pluck(:project_id).uniq) |
|
|
|
|
.to match_array [target_project.id] |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe 'categories' do |
|
|
|
|
let(:category) do |
|
|
|
@ -190,7 +198,7 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'w/o target category' do |
|
|
|
|
context 'without a target category' do |
|
|
|
|
let!(:other_category) do |
|
|
|
|
create(:category, |
|
|
|
|
project: target_project) |
|
|
|
@ -220,7 +228,7 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
project:) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'unshared version' do |
|
|
|
|
context 'with an unshared version' do |
|
|
|
|
it 'removes the version' do |
|
|
|
|
expect(subject) |
|
|
|
|
.to be_success |
|
|
|
@ -230,7 +238,7 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'system wide shared version' do |
|
|
|
|
context 'with a system wide shared version' do |
|
|
|
|
let(:sharing) { 'system' } |
|
|
|
|
|
|
|
|
|
it 'keeps the version' do |
|
|
|
@ -242,12 +250,12 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'move work package in project hierarchy' do |
|
|
|
|
context 'when moving the work package in project hierarchy' do |
|
|
|
|
let(:target_parent) do |
|
|
|
|
project |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'unshared version' do |
|
|
|
|
context 'with an unshared version' do |
|
|
|
|
it 'removes the version' do |
|
|
|
|
expect(subject) |
|
|
|
|
.to be_success |
|
|
|
@ -257,7 +265,7 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'shared version' do |
|
|
|
|
context 'with a shared version' do |
|
|
|
|
let(:sharing) { 'tree' } |
|
|
|
|
|
|
|
|
|
it 'keeps the version' do |
|
|
|
@ -331,18 +339,46 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe 'relations' do |
|
|
|
|
let!(:relation) do |
|
|
|
|
create(:follows_relation, |
|
|
|
|
from: work_package, |
|
|
|
|
to: create(:work_package, |
|
|
|
|
project:)) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'with cross project relations allowed', with_settings: { cross_project_work_package_relations: true } do |
|
|
|
|
it 'keeps the relation' do |
|
|
|
|
expect(subject) |
|
|
|
|
.to be_success |
|
|
|
|
|
|
|
|
|
expect(Relation.find_by(id: relation.id)) |
|
|
|
|
.to eql(relation) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'with cross project relations disabled', with_settings: { cross_project_work_package_relations: false } do |
|
|
|
|
it 'deletes the relation' do |
|
|
|
|
expect(subject) |
|
|
|
|
.to be_success |
|
|
|
|
|
|
|
|
|
expect(Relation.find_by(id: relation.id)) |
|
|
|
|
.to be_nil |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe 'inheriting dates' do |
|
|
|
|
let(:attributes) { { start_date: Date.today - 8.days, due_date: Date.today + 12.days } } |
|
|
|
|
let(:attributes) { { start_date: Time.zone.today - 8.days, due_date: Time.zone.today + 12.days } } |
|
|
|
|
let(:sibling1_attributes) do |
|
|
|
|
work_package_attributes.merge(start_date: Date.today - 5.days, |
|
|
|
|
due_date: Date.today + 10.days, |
|
|
|
|
work_package_attributes.merge(start_date: Time.zone.today - 5.days, |
|
|
|
|
due_date: Time.zone.today + 10.days, |
|
|
|
|
parent: parent_work_package) |
|
|
|
|
end |
|
|
|
|
let(:sibling2_attributes) do |
|
|
|
|
work_package_attributes.merge(due_date: Date.today + 16.days, |
|
|
|
|
work_package_attributes.merge(due_date: Time.zone.today + 16.days, |
|
|
|
|
parent: parent_work_package) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
@ -561,18 +597,18 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
author_id: user.id, |
|
|
|
|
status_id: status.id, |
|
|
|
|
priority:, |
|
|
|
|
start_date: Date.today, |
|
|
|
|
due_date: Date.today + 5.days } |
|
|
|
|
start_date: Time.zone.today, |
|
|
|
|
due_date: Time.zone.today + 5.days } |
|
|
|
|
end |
|
|
|
|
let(:attributes) do |
|
|
|
|
{ start_date: Date.today + 5.days, |
|
|
|
|
due_date: Date.today + 10.days } |
|
|
|
|
{ start_date: Time.zone.today + 5.days, |
|
|
|
|
due_date: Time.zone.today + 10.days } |
|
|
|
|
end |
|
|
|
|
let(:following_attributes) do |
|
|
|
|
work_package_attributes.merge(parent: following_parent_work_package, |
|
|
|
|
subject: 'following', |
|
|
|
|
start_date: Date.today + 6.days, |
|
|
|
|
due_date: Date.today + 20.days) |
|
|
|
|
start_date: Time.zone.today + 6.days, |
|
|
|
|
due_date: Time.zone.today + 20.days) |
|
|
|
|
end |
|
|
|
|
let(:following_work_package) do |
|
|
|
|
create(:work_package, |
|
|
|
@ -582,8 +618,8 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
end |
|
|
|
|
let(:following_parent_attributes) do |
|
|
|
|
work_package_attributes.merge(subject: 'following_parent', |
|
|
|
|
start_date: Date.today + 6.days, |
|
|
|
|
due_date: Date.today + 20.days) |
|
|
|
|
start_date: Time.zone.today + 6.days, |
|
|
|
|
due_date: Time.zone.today + 20.days) |
|
|
|
|
end |
|
|
|
|
let(:following_parent_work_package) do |
|
|
|
|
create(:work_package, |
|
|
|
@ -592,8 +628,8 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
let(:following2_attributes) do |
|
|
|
|
work_package_attributes.merge(parent: following2_parent_work_package, |
|
|
|
|
subject: 'following2', |
|
|
|
|
start_date: Date.today + 21.days, |
|
|
|
|
due_date: Date.today + 25.days) |
|
|
|
|
start_date: Time.zone.today + 21.days, |
|
|
|
|
due_date: Time.zone.today + 25.days) |
|
|
|
|
end |
|
|
|
|
let(:following2_work_package) do |
|
|
|
|
create(:work_package, |
|
|
|
@ -601,8 +637,8 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
end |
|
|
|
|
let(:following2_parent_attributes) do |
|
|
|
|
work_package_attributes.merge(subject: 'following2_parent', |
|
|
|
|
start_date: Date.today + 21.days, |
|
|
|
|
due_date: Date.today + 25.days) |
|
|
|
|
start_date: Time.zone.today + 21.days, |
|
|
|
|
due_date: Time.zone.today + 25.days) |
|
|
|
|
end |
|
|
|
|
let(:following2_parent_work_package) do |
|
|
|
|
create(:work_package, |
|
|
|
@ -613,8 +649,8 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
let(:following3_attributes) do |
|
|
|
|
work_package_attributes.merge(subject: 'following3', |
|
|
|
|
parent: following3_parent_work_package, |
|
|
|
|
start_date: Date.today + 26.days, |
|
|
|
|
due_date: Date.today + 30.days) |
|
|
|
|
start_date: Time.zone.today + 26.days, |
|
|
|
|
due_date: Time.zone.today + 30.days) |
|
|
|
|
end |
|
|
|
|
let(:following3_work_package) do |
|
|
|
|
create(:work_package, |
|
|
|
@ -624,8 +660,8 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
end |
|
|
|
|
let(:following3_parent_attributes) do |
|
|
|
|
work_package_attributes.merge(subject: 'following3_parent', |
|
|
|
|
start_date: Date.today + 26.days, |
|
|
|
|
due_date: Date.today + 36.days) |
|
|
|
|
start_date: Time.zone.today + 26.days, |
|
|
|
|
due_date: Time.zone.today + 36.days) |
|
|
|
|
end |
|
|
|
|
let(:following3_parent_work_package) do |
|
|
|
|
create(:work_package, |
|
|
|
@ -634,8 +670,8 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
let(:following3_sibling_attributes) do |
|
|
|
|
work_package_attributes.merge(parent: following3_parent_work_package, |
|
|
|
|
subject: 'following3_sibling', |
|
|
|
|
start_date: Date.today + 32.days, |
|
|
|
|
due_date: Date.today + 36.days) |
|
|
|
|
start_date: Time.zone.today + 32.days, |
|
|
|
|
due_date: Time.zone.today + 36.days) |
|
|
|
|
end |
|
|
|
|
let(:following3_sibling_work_package) do |
|
|
|
|
create(:work_package, |
|
|
|
@ -653,66 +689,63 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
following3_sibling_work_package |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# rubocop:disable RSpec/ExampleLength |
|
|
|
|
# rubocop:disable RSpec/MultipleExpectations |
|
|
|
|
it 'propagates the changes to start/finish date along' do |
|
|
|
|
expect(subject) |
|
|
|
|
.to be_success |
|
|
|
|
|
|
|
|
|
work_package.reload(select: %i(start_date due_date)) |
|
|
|
|
expect(work_package.start_date) |
|
|
|
|
.to eql Date.today + 5.days |
|
|
|
|
.to eql Time.zone.today + 5.days |
|
|
|
|
|
|
|
|
|
expect(work_package.due_date) |
|
|
|
|
.to eql Date.today + 10.days |
|
|
|
|
.to eql Time.zone.today + 10.days |
|
|
|
|
|
|
|
|
|
following_work_package.reload(select: %i(start_date due_date)) |
|
|
|
|
expect(following_work_package.start_date) |
|
|
|
|
.to eql Date.today + 11.days |
|
|
|
|
|
|
|
|
|
.to eql Time.zone.today + 11.days |
|
|
|
|
expect(following_work_package.due_date) |
|
|
|
|
.to eql Date.today + 25.days |
|
|
|
|
.to eql Time.zone.today + 25.days |
|
|
|
|
|
|
|
|
|
following_parent_work_package.reload(select: %i(start_date due_date)) |
|
|
|
|
expect(following_parent_work_package.start_date) |
|
|
|
|
.to eql Date.today + 11.days |
|
|
|
|
|
|
|
|
|
.to eql Time.zone.today + 11.days |
|
|
|
|
expect(following_parent_work_package.due_date) |
|
|
|
|
.to eql Date.today + 25.days |
|
|
|
|
.to eql Time.zone.today + 25.days |
|
|
|
|
|
|
|
|
|
following2_parent_work_package.reload(select: %i(start_date due_date)) |
|
|
|
|
expect(following2_parent_work_package.start_date) |
|
|
|
|
.to eql Date.today + 26.days |
|
|
|
|
|
|
|
|
|
.to eql Time.zone.today + 26.days |
|
|
|
|
expect(following2_parent_work_package.due_date) |
|
|
|
|
.to eql Date.today + 30.days |
|
|
|
|
.to eql Time.zone.today + 30.days |
|
|
|
|
|
|
|
|
|
following2_work_package.reload(select: %i(start_date due_date)) |
|
|
|
|
expect(following2_work_package.start_date) |
|
|
|
|
.to eql Date.today + 26.days |
|
|
|
|
|
|
|
|
|
.to eql Time.zone.today + 26.days |
|
|
|
|
expect(following2_work_package.due_date) |
|
|
|
|
.to eql Date.today + 30.days |
|
|
|
|
.to eql Time.zone.today + 30.days |
|
|
|
|
|
|
|
|
|
following3_work_package.reload(select: %i(start_date due_date)) |
|
|
|
|
expect(following3_work_package.start_date) |
|
|
|
|
.to eql Date.today + 31.days |
|
|
|
|
|
|
|
|
|
.to eql Time.zone.today + 31.days |
|
|
|
|
expect(following3_work_package.due_date) |
|
|
|
|
.to eql Date.today + 35.days |
|
|
|
|
.to eql Time.zone.today + 35.days |
|
|
|
|
|
|
|
|
|
following3_parent_work_package.reload(select: %i(start_date due_date)) |
|
|
|
|
expect(following3_parent_work_package.start_date) |
|
|
|
|
.to eql Date.today + 31.days |
|
|
|
|
|
|
|
|
|
.to eql Time.zone.today + 31.days |
|
|
|
|
expect(following3_parent_work_package.due_date) |
|
|
|
|
.to eql Date.today + 36.days |
|
|
|
|
.to eql Time.zone.today + 36.days |
|
|
|
|
|
|
|
|
|
following3_sibling_work_package.reload(select: %i(start_date due_date)) |
|
|
|
|
expect(following3_sibling_work_package.start_date) |
|
|
|
|
.to eql Date.today + 32.days |
|
|
|
|
|
|
|
|
|
.to eql Time.zone.today + 32.days |
|
|
|
|
expect(following3_sibling_work_package.due_date) |
|
|
|
|
.to eql Date.today + 36.days |
|
|
|
|
.to eql Time.zone.today + 36.days |
|
|
|
|
end |
|
|
|
|
# rubocop:enable RSpec/ExampleLength |
|
|
|
|
# rubocop:enable RSpec/MultipleExpectations |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe 'rescheduling work packages forward follows/hierarchy relations' do |
|
|
|
@ -734,18 +767,20 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
author_id: user.id, |
|
|
|
|
status_id: status.id, |
|
|
|
|
priority:, |
|
|
|
|
start_date: Date.today, |
|
|
|
|
due_date: Date.today + 5.days } |
|
|
|
|
start_date: Time.zone.today, |
|
|
|
|
due_date: Time.zone.today + 5.days } |
|
|
|
|
end |
|
|
|
|
let(:attributes) do |
|
|
|
|
{ start_date: Date.today - 5.days, |
|
|
|
|
due_date: Date.today } |
|
|
|
|
{ |
|
|
|
|
start_date: Time.zone.today - 5.days, |
|
|
|
|
due_date: Time.zone.today |
|
|
|
|
} |
|
|
|
|
end |
|
|
|
|
let(:following_attributes) do |
|
|
|
|
work_package_attributes.merge(parent: following_parent_work_package, |
|
|
|
|
subject: 'following', |
|
|
|
|
start_date: Date.today + 6.days, |
|
|
|
|
due_date: Date.today + 20.days) |
|
|
|
|
start_date: Time.zone.today + 6.days, |
|
|
|
|
due_date: Time.zone.today + 20.days) |
|
|
|
|
end |
|
|
|
|
let(:following_work_package) do |
|
|
|
|
create(:work_package, |
|
|
|
@ -755,8 +790,8 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
end |
|
|
|
|
let(:following_parent_attributes) do |
|
|
|
|
work_package_attributes.merge(subject: 'following_parent', |
|
|
|
|
start_date: Date.today + 6.days, |
|
|
|
|
due_date: Date.today + 20.days) |
|
|
|
|
start_date: Time.zone.today + 6.days, |
|
|
|
|
due_date: Time.zone.today + 20.days) |
|
|
|
|
end |
|
|
|
|
let(:following_parent_work_package) do |
|
|
|
|
create(:work_package, |
|
|
|
@ -764,8 +799,8 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
end |
|
|
|
|
let(:other_attributes) do |
|
|
|
|
work_package_attributes.merge(subject: 'other', |
|
|
|
|
start_date: Date.today + 10.days, |
|
|
|
|
due_date: Date.today + 18.days) |
|
|
|
|
start_date: Time.zone.today + 10.days, |
|
|
|
|
due_date: Time.zone.today + 18.days) |
|
|
|
|
end |
|
|
|
|
let(:other_work_package) do |
|
|
|
|
create(:work_package, |
|
|
|
@ -774,8 +809,8 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
let(:following2_attributes) do |
|
|
|
|
work_package_attributes.merge(parent: following2_parent_work_package, |
|
|
|
|
subject: 'following2', |
|
|
|
|
start_date: Date.today + 24.days, |
|
|
|
|
due_date: Date.today + 28.days) |
|
|
|
|
start_date: Time.zone.today + 24.days, |
|
|
|
|
due_date: Time.zone.today + 28.days) |
|
|
|
|
end |
|
|
|
|
let(:following2_work_package) do |
|
|
|
|
create(:work_package, |
|
|
|
@ -783,8 +818,8 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
end |
|
|
|
|
let(:following2_parent_attributes) do |
|
|
|
|
work_package_attributes.merge(subject: 'following2_parent', |
|
|
|
|
start_date: Date.today + 24.days, |
|
|
|
|
due_date: Date.today + 28.days) |
|
|
|
|
start_date: Time.zone.today + 24.days, |
|
|
|
|
due_date: Time.zone.today + 28.days) |
|
|
|
|
end |
|
|
|
|
let(:following2_parent_work_package) do |
|
|
|
|
following2 = create(:work_package, |
|
|
|
@ -802,8 +837,8 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
end |
|
|
|
|
let(:following3_attributes) do |
|
|
|
|
work_package_attributes.merge(subject: 'following3', |
|
|
|
|
start_date: Date.today + 29.days, |
|
|
|
|
due_date: Date.today + 33.days) |
|
|
|
|
start_date: Time.zone.today + 29.days, |
|
|
|
|
due_date: Time.zone.today + 33.days) |
|
|
|
|
end |
|
|
|
|
let(:following3_work_package) do |
|
|
|
|
create(:work_package, |
|
|
|
@ -822,52 +857,48 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
following3_work_package |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# rubocop:disable RSpec/ExampleLength |
|
|
|
|
it 'propagates the changes to start/finish date along' do |
|
|
|
|
expect(subject) |
|
|
|
|
.to be_success |
|
|
|
|
|
|
|
|
|
work_package.reload(select: %i(start_date due_date)) |
|
|
|
|
expect(work_package.start_date) |
|
|
|
|
.to eql Date.today - 5.days |
|
|
|
|
|
|
|
|
|
.to eql Time.zone.today - 5.days |
|
|
|
|
expect(work_package.due_date) |
|
|
|
|
.to eql Date.today |
|
|
|
|
.to eql Time.zone.today |
|
|
|
|
|
|
|
|
|
following_work_package.reload(select: %i(start_date due_date)) |
|
|
|
|
expect(following_work_package.start_date) |
|
|
|
|
.to eql Date.today + 1.day |
|
|
|
|
|
|
|
|
|
.to eql Time.zone.today + 1.day |
|
|
|
|
expect(following_work_package.due_date) |
|
|
|
|
.to eql Date.today + 15.days |
|
|
|
|
.to eql Time.zone.today + 15.days |
|
|
|
|
|
|
|
|
|
following_parent_work_package.reload(select: %i(start_date due_date)) |
|
|
|
|
expect(following_parent_work_package.start_date) |
|
|
|
|
.to eql Date.today + 1.day |
|
|
|
|
|
|
|
|
|
.to eql Time.zone.today + 1.day |
|
|
|
|
expect(following_parent_work_package.due_date) |
|
|
|
|
.to eql Date.today + 15.days |
|
|
|
|
.to eql Time.zone.today + 15.days |
|
|
|
|
|
|
|
|
|
following2_parent_work_package.reload(select: %i(start_date due_date)) |
|
|
|
|
expect(following2_parent_work_package.start_date) |
|
|
|
|
.to eql Date.today + 22.days |
|
|
|
|
|
|
|
|
|
.to eql Time.zone.today + 22.days |
|
|
|
|
expect(following2_parent_work_package.due_date) |
|
|
|
|
.to eql Date.today + 26.days |
|
|
|
|
.to eql Time.zone.today + 26.days |
|
|
|
|
|
|
|
|
|
following2_work_package.reload(select: %i(start_date due_date)) |
|
|
|
|
expect(following2_work_package.start_date) |
|
|
|
|
.to eql Date.today + 22.days |
|
|
|
|
|
|
|
|
|
.to eql Time.zone.today + 22.days |
|
|
|
|
expect(following2_work_package.due_date) |
|
|
|
|
.to eql Date.today + 26.days |
|
|
|
|
.to eql Time.zone.today + 26.days |
|
|
|
|
|
|
|
|
|
following3_work_package.reload(select: %i(start_date due_date)) |
|
|
|
|
expect(following3_work_package.start_date) |
|
|
|
|
.to eql Date.today + 27.days |
|
|
|
|
|
|
|
|
|
.to eql Time.zone.today + 27.days |
|
|
|
|
expect(following3_work_package.due_date) |
|
|
|
|
.to eql Date.today + 31.days |
|
|
|
|
.to eql Time.zone.today + 31.days |
|
|
|
|
end |
|
|
|
|
# rubocop:enable RSpec/ExampleLength |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe 'changing the parent' do |
|
|
|
@ -879,8 +910,8 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
author_id: user.id, |
|
|
|
|
status_id: status.id, |
|
|
|
|
priority:, |
|
|
|
|
start_date: Date.today + 3.days, |
|
|
|
|
due_date: Date.today + 9.days |
|
|
|
|
start_date: Time.zone.today + 3.days, |
|
|
|
|
due_date: Time.zone.today + 9.days |
|
|
|
|
} |
|
|
|
|
end |
|
|
|
|
let(:attributes) { { parent: new_parent_work_package } } |
|
|
|
@ -892,8 +923,8 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
work_package_attributes.merge( |
|
|
|
|
subject: 'former sibling', |
|
|
|
|
parent: former_parent_work_package, |
|
|
|
|
start_date: Date.today + 3.days, |
|
|
|
|
due_date: Date.today + 6.days |
|
|
|
|
start_date: Time.zone.today + 3.days, |
|
|
|
|
due_date: Time.zone.today + 6.days |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
let(:former_sibling_work_package) do |
|
|
|
@ -907,16 +938,16 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
status_id: status.id, |
|
|
|
|
priority:, |
|
|
|
|
parent: former_parent_work_package, |
|
|
|
|
start_date: Date.today + 7.days, |
|
|
|
|
due_date: Date.today + 9.days } |
|
|
|
|
start_date: Time.zone.today + 7.days, |
|
|
|
|
due_date: Time.zone.today + 9.days } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
let(:new_parent_attributes) do |
|
|
|
|
work_package_attributes.merge( |
|
|
|
|
subject: 'new parent', |
|
|
|
|
parent: nil, |
|
|
|
|
start_date: Date.today + 10.days, |
|
|
|
|
due_date: Date.today + 12.days |
|
|
|
|
start_date: Time.zone.today + 10.days, |
|
|
|
|
due_date: Time.zone.today + 12.days |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
let(:new_parent_work_package) do |
|
|
|
@ -927,8 +958,8 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
work_package_attributes.merge( |
|
|
|
|
subject: 'new sibling', |
|
|
|
|
parent: new_parent_work_package, |
|
|
|
|
start_date: Date.today + 10.days, |
|
|
|
|
due_date: Date.today + 12.days |
|
|
|
|
start_date: Time.zone.today + 10.days, |
|
|
|
|
due_date: Time.zone.today + 12.days |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
let(:new_sibling_work_package) do |
|
|
|
@ -978,8 +1009,8 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
work_package_attributes.merge( |
|
|
|
|
subject: 'new parent', |
|
|
|
|
parent: nil, |
|
|
|
|
start_date: Date.today + 8.days, |
|
|
|
|
due_date: Date.today + 14.days |
|
|
|
|
start_date: Time.zone.today + 8.days, |
|
|
|
|
due_date: Time.zone.today + 14.days |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
let(:attributes) { { parent: new_parent_work_package } } |
|
|
|
@ -991,8 +1022,8 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
work_package_attributes.merge( |
|
|
|
|
subject: 'new parent predecessor', |
|
|
|
|
parent: nil, |
|
|
|
|
start_date: Date.today + 1.day, |
|
|
|
|
due_date: Date.today + 4.days |
|
|
|
|
start_date: Time.zone.today + 1.day, |
|
|
|
|
due_date: Time.zone.today + 4.days |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
let(:new_parent_predecessor_work_package) do |
|
|
|
@ -1007,8 +1038,8 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
author_id: user.id, |
|
|
|
|
status_id: status.id, |
|
|
|
|
priority:, |
|
|
|
|
start_date: Date.today, |
|
|
|
|
due_date: Date.today + 3.days } |
|
|
|
|
start_date: Time.zone.today, |
|
|
|
|
due_date: Time.zone.today + 3.days } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
@ -1057,8 +1088,8 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
status_id: status.id, |
|
|
|
|
priority:, |
|
|
|
|
parent: parent_work_package, |
|
|
|
|
start_date: Date.today, |
|
|
|
|
due_date: Date.today + 3.days } |
|
|
|
|
start_date: Time.zone.today, |
|
|
|
|
due_date: Time.zone.today + 3.days } |
|
|
|
|
end |
|
|
|
|
let(:attributes) { { parent: nil } } |
|
|
|
|
|
|
|
|
@ -1069,8 +1100,8 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
author_id: user.id, |
|
|
|
|
status_id: status.id, |
|
|
|
|
priority:, |
|
|
|
|
start_date: Date.today, |
|
|
|
|
due_date: Date.today + 10.days } |
|
|
|
|
start_date: Time.zone.today, |
|
|
|
|
due_date: Time.zone.today + 10.days } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
let(:parent_work_package) do |
|
|
|
@ -1080,8 +1111,8 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
let(:sibling_attributes) do |
|
|
|
|
work_package_attributes.merge( |
|
|
|
|
subject: 'sibling', |
|
|
|
|
start_date: Date.today + 4.days, |
|
|
|
|
due_date: Date.today + 10.days |
|
|
|
|
start_date: Time.zone.today + 4.days, |
|
|
|
|
due_date: Time.zone.today + 10.days |
|
|
|
|
) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
@ -1129,6 +1160,7 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
create(:attachment, container: nil, author: user) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# rubocop:disable RSpec/ExampleLength |
|
|
|
|
it 'reports on invalid attachments and replaces the existent with the new if everything is valid' do |
|
|
|
|
work_package.attachments.reload |
|
|
|
|
|
|
|
|
@ -1171,7 +1203,7 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
expect(Attachment.all) |
|
|
|
|
.to match_array [other_users_attachment] |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
# rubocop:enable RSpec/ExampleLength |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
## |
|
|
|
@ -1205,27 +1237,145 @@ describe WorkPackages::UpdateService, 'integration tests', type: :model, with_ma |
|
|
|
|
let(:project_types) { [type, new_type] } |
|
|
|
|
let(:attributes) { { type: new_type } } |
|
|
|
|
|
|
|
|
|
context 'work package does NOT have default status' do |
|
|
|
|
context 'when the work package does NOT have default status' do |
|
|
|
|
let(:status) { create(:status) } |
|
|
|
|
|
|
|
|
|
it 'assigns the default status' do |
|
|
|
|
expect(work_package).to receive(:status=).and_call_original |
|
|
|
|
expect(subject).to be_success |
|
|
|
|
|
|
|
|
|
expect(work_package.status).to eq(Status.default) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
context 'work package does have default status' do |
|
|
|
|
context 'when the work package does have default status' do |
|
|
|
|
let(:status) { create :default_status } |
|
|
|
|
let!(:workflow_type) do |
|
|
|
|
create(:workflow, type: new_type, role:, old_status_id: status.id) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'does not set the status' do |
|
|
|
|
expect(work_package).not_to receive(:status=) |
|
|
|
|
expect(subject).to be_success |
|
|
|
|
|
|
|
|
|
expect(work_package) |
|
|
|
|
.not_to be_saved_change_to_status_id |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe 'removing an invalid parent' do |
|
|
|
|
# The parent does not have a required custom field set but will need to be touched since. |
|
|
|
|
# the dates, inherited from its children (and then the only remaining child) will have to be updated. |
|
|
|
|
let!(:parent) do |
|
|
|
|
create(:work_package, |
|
|
|
|
type: project.types.first, |
|
|
|
|
project:, |
|
|
|
|
start_date: Time.zone.today - 1.day, |
|
|
|
|
due_date: Time.zone.today + 5.days) |
|
|
|
|
end |
|
|
|
|
let!(:custom_field) do |
|
|
|
|
create(:int_wp_custom_field, is_required: true, is_for_all: true, default_value: nil).tap do |cf| |
|
|
|
|
project.types.first.custom_fields << cf |
|
|
|
|
project.work_package_custom_fields << cf |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
let!(:sibling) do |
|
|
|
|
create(:work_package, |
|
|
|
|
type: project.types.first, |
|
|
|
|
project:, |
|
|
|
|
parent:, |
|
|
|
|
start_date: Time.zone.today + 1.day, |
|
|
|
|
due_date: Time.zone.today + 5.days, |
|
|
|
|
"custom_field_#{custom_field.id}": 5) |
|
|
|
|
end |
|
|
|
|
let!(:attributes) { { parent: nil } } |
|
|
|
|
|
|
|
|
|
let(:work_package_attributes) do |
|
|
|
|
{ |
|
|
|
|
start_date: Time.zone.today - 1.day, |
|
|
|
|
due_date: Time.zone.today + 1.day, |
|
|
|
|
project:, |
|
|
|
|
type: project.types.first, |
|
|
|
|
parent:, |
|
|
|
|
"custom_field_#{custom_field.id}": 8 |
|
|
|
|
} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'removes the parent successfully and reschedules the parent' do |
|
|
|
|
expect(subject).to be_success |
|
|
|
|
|
|
|
|
|
expect(work_package.reload.parent).to be_nil |
|
|
|
|
|
|
|
|
|
expect(parent.reload.start_date) |
|
|
|
|
.to eql(sibling.start_date) |
|
|
|
|
expect(parent.due_date) |
|
|
|
|
.to eql(sibling.due_date) |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe 'updating an invalid work package' do |
|
|
|
|
# The work package does not have a required custom field set. |
|
|
|
|
let(:custom_field) do |
|
|
|
|
create(:int_wp_custom_field, is_required: true, is_for_all: true, default_value: nil).tap do |cf| |
|
|
|
|
project.types.first.custom_fields << cf |
|
|
|
|
project.work_package_custom_fields << cf |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
let(:attributes) { { subject: 'A new subject' } } |
|
|
|
|
|
|
|
|
|
let(:work_package_attributes) do |
|
|
|
|
{ |
|
|
|
|
subject: 'The old subject', |
|
|
|
|
project:, |
|
|
|
|
type: project.types.first |
|
|
|
|
} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
before do |
|
|
|
|
# Creating the custom field after the work package is already saved. |
|
|
|
|
work_package |
|
|
|
|
custom_field |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'is a failure and does not save the change' do |
|
|
|
|
expect(subject).to be_failure |
|
|
|
|
|
|
|
|
|
expect(work_package.reload.subject) |
|
|
|
|
.to eql work_package_attributes[:subject] |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
describe 'updating the type (custom field resetting)' do |
|
|
|
|
let(:project_types) { [type, new_type] } |
|
|
|
|
let(:new_type) { create(:type) } |
|
|
|
|
let!(:custom_field_of_current_type) do |
|
|
|
|
create(:int_wp_custom_field, default_value: nil).tap do |cf| |
|
|
|
|
type.custom_fields << cf |
|
|
|
|
project.work_package_custom_fields << cf |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
let!(:custom_field_of_new_type) do |
|
|
|
|
create(:int_wp_custom_field, default_value: 8).tap do |cf| |
|
|
|
|
new_type.custom_fields << cf |
|
|
|
|
project.work_package_custom_fields << cf |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
let(:attributes) do |
|
|
|
|
{ type: new_type } |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
let(:work_package_attributes) do |
|
|
|
|
{ |
|
|
|
|
type:, |
|
|
|
|
project:, |
|
|
|
|
"custom_field_#{custom_field_of_current_type.id}": 5 |
|
|
|
|
} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'is success, removes the existing custom field value and sets the default for the new one' do |
|
|
|
|
expect(subject).to be_success |
|
|
|
|
|
|
|
|
|
expect(work_package.reload.custom_values.pluck(:custom_field_id, :value)) |
|
|
|
|
.to eq [[custom_field_of_new_type.id, "8"]] |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|