Merge pull request #6875 from opf/core/fix/15909/respect-current-date-setting

[15909] Respect current_date as start_date setting
pull/6880/head
ulferts 6 years ago committed by GitHub
commit 240f2d845e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/services/work_packages/set_attributes_service.rb
  2. 1
      config/settings.yml
  3. 38
      spec/services/work_packages/set_attributes_service_spec.rb
  4. 24
      spec_legacy/unit/mail_handler_spec.rb

@ -85,6 +85,10 @@ class WorkPackages::SetAttributesService
work_package.priority ||= IssuePriority.active.default
work_package.author ||= user
work_package.status ||= Status.default
if Setting.work_package_startdate_is_adddate?
work_package.start_date ||= Date.today
end
end
def set_custom_attributes(attributes)

@ -329,6 +329,7 @@ emails_header:
en: ''
work_package_startdate_is_adddate:
default: 1
format: boolean
user_default_timezone:
default: ""
users_deletable_by_admins:

@ -354,20 +354,38 @@ describe WorkPackages::SetAttributesService, type: :model do
end
end
context 'no value set on existing work package' do
let(:call_attributes) { {} }
let(:attributes) { {} }
context 'start_date with default setting', with_settings: { work_package_startdate_is_adddate: true } do
context 'no value set before for a new work package' do
let(:call_attributes) { {} }
let(:attributes) { {} }
let(:work_package) { new_work_package }
before do
work_package.priority = nil
before do
work_package.priority = nil
end
it_behaves_like 'service call' do
it "sets the default priority" do
subject
expect(work_package.priority)
.to eql default_priority
end
end
end
it_behaves_like 'service call' do
it 'stays nil' do
subject
context 'value set on new work package' do
let(:call_attributes) { { start_date: Date.today + 1.day } }
let(:attributes) { {} }
let(:work_package) { new_work_package }
expect(work_package.priority)
.to be_nil
it_behaves_like 'service call' do
it 'stays that value' do
subject
expect(work_package.start_date)
.to eq(Date.today + 1.day)
end
end
end
end

@ -241,17 +241,19 @@ describe MailHandler, type: :model do
assert_equal false, submit_email('ticket_without_from_header.eml')
end
it 'should add work package with invalid attributes' do
issue = submit_email('ticket_with_invalid_attributes.eml', allow_override: 'type,category,priority')
assert issue.is_a?(WorkPackage)
assert !issue.new_record?
issue.reload
assert_nil issue.assigned_to
assert_nil issue.start_date
assert_nil issue.due_date
assert_equal 0, issue.done_ratio
assert_equal 'Normal', issue.priority.to_s
assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
context 'without default start_date', with_settings: { work_package_startdate_is_adddate: false } do
it 'should add work package with invalid attributes' do
issue = submit_email('ticket_with_invalid_attributes.eml', allow_override: 'type,category,priority')
assert issue.is_a?(WorkPackage)
assert !issue.new_record?
issue.reload
assert_nil issue.assigned_to
assert_nil issue.start_date
assert_nil issue.due_date
assert_equal 0, issue.done_ratio
assert_equal 'Normal', issue.priority.to_s
assert issue.description.include?('Lorem ipsum dolor sit amet, consectetuer adipiscing elit.')
end
end
it 'should add work package with localized attributes' do

Loading…
Cancel
Save