fix unsetting date on milestone work packages

pull/7403/head
ulferts 5 years ago
parent 53f0b976d0
commit 880120fe1b
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 10
      lib/api/v3/work_packages/work_package_representer.rb
  2. 3
      spec/lib/api/v3/work_packages/work_package_payload_representer_spec.rb

@ -341,12 +341,18 @@ module API
represented.milestone? represented.milestone?
} }
# Using setter: does not work in case the provided date fragment is nil.
date_property :date, date_property :date,
getter: default_date_getter(:due_date), getter: default_date_getter(:due_date),
setter: ->(fragment:, decorator:, **) { setter: ->(*) {
# handled in reader
},
reader: ->(decorator:, doc:, **) {
next unless doc.key?('date')
date = decorator date = decorator
.datetime_formatter .datetime_formatter
.parse_date(fragment, .parse_date(doc['date'],
name.to_s.camelize(:lower), name.to_s.camelize(:lower),
allow_nil: true) allow_nil: true)

@ -502,6 +502,9 @@ describe ::API::V3::WorkPackages::WorkPackagePayloadRepresenter do
allow(work_package) allow(work_package)
.to receive(:milestone?) .to receive(:milestone?)
.and_return(true) .and_return(true)
# Setting values to ensure they are later set to nil in one of the test cases
work_package.start_date = work_package.due_date = Date.today
end end
it_behaves_like 'settable ISO 8601 date only' do it_behaves_like 'settable ISO 8601 date only' do

Loading…
Cancel
Save