allow freely setting the dates of manually scheduled child work packages

pull/8437/head
ulferts 4 years ago committed by Oliver Günther
parent c5ead62e0a
commit fdcc89f810
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 2
      app/contracts/work_packages/base_contract.rb
  2. 50
      spec/contracts/work_packages/base_contract_spec.rb
  3. 13
      spec/features/work_packages/scheduling/scheduling_mode_spec.rb
  4. 8
      spec/support/edit_fields/date_edit_field.rb
  5. 2
      spec/support/pages/work_packages/abstract_work_package.rb

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

@ -95,7 +95,7 @@ describe WorkPackages::BaseContract do
end
end
shared_examples 'a parent unwritable property' do |attribute|
shared_examples 'a parent unwritable property' do |attribute, schedule_sensitive: false|
before do
allow(work_package).to receive(:changed).and_return(changed_values.map(&:to_s))
end
@ -123,7 +123,11 @@ describe WorkPackages::BaseContract do
end
context 'is a parent' do
let(:schedule_manually) { false }
before do
work_package.schedule_manually = schedule_manually
allow(work_package)
.to receive(:leaf?)
.and_return(false)
@ -143,6 +147,18 @@ describe WorkPackages::BaseContract do
expect(contract.errors.symbols_for(attribute)).to match_array([:error_readonly])
end
end
if schedule_sensitive
context 'is scheduled manually' do
let(:schedule_manually) { true }
context 'has changed' do
let(:changed_values) { [attribute] }
it('is valid') { expect(contract.errors).to be_empty }
end
end
end
end
end
@ -393,11 +409,14 @@ describe WorkPackages::BaseContract do
end
describe 'start date' do
it_behaves_like 'a parent unwritable property', :start_date
it_behaves_like 'a parent unwritable property', :start_date, schedule_sensitive: true
it_behaves_like 'a date attribute', :start_date
context 'before soonest start date of parent' do
let(:schedule_manually) { false }
before do
work_package.schedule_manually = schedule_manually
work_package.parent = FactoryBot.build_stubbed(:work_package)
allow(work_package)
.to receive(:soonest_start)
@ -406,20 +425,33 @@ describe WorkPackages::BaseContract do
work_package.start_date = Date.today + 2.days
end
it 'notes the error' do
contract.validate
context 'scheduled automatically' do
it 'notes the error' do
contract.validate
message = I18n.t('activerecord.errors.models.work_package.attributes.start_date.violates_relationships',
soonest_start: Date.today + 4.days)
message = I18n.t('activerecord.errors.models.work_package.attributes.start_date.violates_relationships',
soonest_start: Date.today + 4.days)
expect(contract.errors[:start_date])
.to match_array [message]
expect(contract.errors[:start_date])
.to match_array [message]
end
end
context 'scheduled manually' do
let(:schedule_manually) { true }
it 'is valid' do
contract.validate
expect(contract.errors[:start_date])
.to be_empty
end
end
end
end
describe 'finish date' do
it_behaves_like 'a parent unwritable property', :due_date
it_behaves_like 'a parent unwritable property', :due_date, schedule_sensitive: true
it_behaves_like 'a date attribute', :due_date
it 'returns an error when trying to set it before the start date' do

@ -95,17 +95,20 @@ describe 'scheduling mode',
it 'can toggle the scheduling mode through the date modal' do
expect(wp.schedule_manually).to eq false
combined_field.activate!
combined_field.activate!(expect_open: false)
combined_field.expect_active!
# Editing the start/due dates of a parent work package is possible if the
# work package is manually scheduled
combined_field.expect_scheduling_mode manually: false
combined_field.toggle_scheduling_mode
combined_field.expect_scheduling_mode manually: true
combined_field.update(%w[2016-01-05 2016-01-10])
combined_field.save!
work_packages_page.expect_and_dismiss_notification message: 'Successful update.'
work_package.reload
expect(wp.schedule_manually).to eq true
wp.reload
expect(wp.schedule_manually).to be_truthy
expect(wp.start_date).to eql Date.parse('2016-01-05')
expect(wp.due_date).to eql Date.parse('2016-01-10')
end
end

@ -21,7 +21,11 @@ class DateEditField < EditField
end
def input_selector
"input[name=#{property_name}]"
if property_name == 'combinedDate'
"input[name=startDate]"
else
"input[name=#{property_name}]"
end
end
def property_name
@ -78,7 +82,7 @@ class DateEditField < EditField
activate_edition
within_modal do
if value.is_a?(Array)
value.each {|el| select_value(el)}
value.each { |el| select_value(el) }
else
select_value value
end

@ -192,7 +192,7 @@ module Pages
case key
when /customField(\d+)$/
work_package_custom_field(key, $1)
when :date, :startDate, :dueDate
when :date, :startDate, :dueDate, :combinedDate
DateEditField.new container, key, is_milestone: work_package.milestone?
when :description
TextEditorField.new container, key

Loading…
Cancel
Save