adjust contract to allow setting dates on manually scheduled parent wps

pull/8437/head
ulferts 4 years ago committed by Oliver Günther
parent 7065c162fd
commit c5ead62e0a
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 4
      app/contracts/work_packages/base_contract.rb
  2. 14
      spec/features/work_packages/scheduling/scheduling_mode_spec.rb
  3. 70
      spec/lib/api/v3/work_packages/schema/specific_work_package_schema_spec.rb

@ -84,7 +84,7 @@ module WorkPackages
attribute :start_date,
writeable: ->(*) {
model.leaf?
model.leaf? || model.schedule_manually?
} do
if start_before_soonest_start?
message = I18n.t('activerecord.errors.models.work_package.attributes.start_date.violates_relationships',
@ -96,7 +96,7 @@ module WorkPackages
attribute :due_date,
writeable: ->(*) {
model.leaf?
model.leaf? || model.schedule_manually?
}
validates :due_date,

@ -84,7 +84,7 @@ describe 'scheduling mode',
let(:user) { FactoryBot.create :admin }
let(:work_packages_page) { Pages::SplitWorkPackage.new(wp, project) }
let(:start_date) { work_packages_page.edit_field(:startDate) }
let(:combined_field) { work_packages_page.edit_field(:combinedDate) }
before do
login_as(user)
@ -95,14 +95,14 @@ describe 'scheduling mode',
it 'can toggle the scheduling mode through the date modal' do
expect(wp.schedule_manually).to eq false
start_date.activate!
start_date.expect_active!
combined_field.activate!
combined_field.expect_active!
start_date.expect_scheduling_mode manually: false
start_date.toggle_scheduling_mode
start_date.expect_scheduling_mode manually: true
combined_field.expect_scheduling_mode manually: false
combined_field.toggle_scheduling_mode
combined_field.expect_scheduling_mode manually: true
start_date.save!
combined_field.save!
work_packages_page.expect_and_dismiss_notification message: 'Successful update.'
work_package.reload

@ -208,30 +208,74 @@ describe ::API::V3::WorkPackages::Schema::SpecificWorkPackageSchema do
end
context 'start date' do
it 'is not writable when the work package is a parent' do
allow(work_package).to receive(:leaf?).and_return(false)
expect(subject.writable?(:start_date)).to be false
context 'work package is parent' do
before do
allow(work_package)
.to receive(:leaf?)
.and_return(false)
end
context 'scheduled automatically' do
it 'is not writable' do
expect(subject.writable?(:start_date)).to be false
end
end
context 'scheduled manually' do
before do
work_package.schedule_manually = true
end
it 'is writable' do
expect(subject.writable?(:start_date)).to be true
end
end
end
it 'is writable when the work package is a leaf' do
allow(work_package).to receive(:leaf?).and_return(true)
expect(subject.writable?(:start_date)).to be true
context 'work package is a leaf' do
it 'is writable' do
allow(work_package).to receive(:leaf?).and_return(true)
expect(subject.writable?(:start_date)).to be true
end
end
end
context 'finish date' do
it 'is not writable when the work package is a parent' do
allow(work_package).to receive(:leaf?).and_return(false)
expect(subject.writable?(:due_date)).to be false
context 'due date' do
context 'work package is parent' do
before do
allow(work_package)
.to receive(:leaf?)
.and_return(false)
end
context 'scheduled automatically' do
it 'is not writable' do
expect(subject.writable?(:due_date)).to be false
end
end
context 'scheduled manually' do
before do
work_package.schedule_manually = true
end
it 'is writable' do
expect(subject.writable?(:due_date)).to be true
end
end
end
it 'is writable when the work package is a leaf' do
allow(work_package).to receive(:leaf?).and_return(true)
expect(subject.writable?(:due_date)).to be true
context 'work package is a leaf' do
it 'is writable' do
allow(work_package).to receive(:leaf?).and_return(true)
expect(subject.writable?(:due_date)).to be true
end
end
end
context 'date' do
# As a date only exists on milestones, which can have no children
# we do not need to check for differences caused by scheduling modes.
before do
allow(work_package.type).to receive(:is_milestone?).and_return(true)
end

Loading…
Cancel
Save