diff --git a/config/initializers/reform.rb b/config/initializers/reform.rb index be10a0671434..20d052e0b6de 100644 --- a/config/initializers/reform.rb +++ b/config/initializers/reform.rb @@ -38,6 +38,16 @@ include Reform::Form::ActiveModel::Validations end +Reform::Form::ActiveModel::Validations::Validator.class_eval do + ## + # use activerecord as the base scope instead of 'activemodel' to be compatible + # to the messages we have already stored + def self.i18n_scope + :activerecord + end +end + + require 'reform/contract' require 'open_project/patches/reform' diff --git a/spec/contracts/work_packages/base_contract_spec.rb b/spec/contracts/work_packages/base_contract_spec.rb index c074cdeac3b5..e6a982a23783 100644 --- a/spec/contracts/work_packages/base_contract_spec.rb +++ b/spec/contracts/work_packages/base_contract_spec.rb @@ -260,6 +260,18 @@ describe 'due date' do it_behaves_like 'a parent unwritable property', :due_date it_behaves_like 'a date attribute', :due_date + + it 'returns an error when trying to set it before the start date' do + work_package.start_date = Date.today + 2.days + work_package.due_date = Date.today + + contract.validate + + message = I18n.t('activerecord.errors.messages.greater_than_or_equal_to_start_date') + + expect(contract.errors[:due_date]) + .to include message + end end describe 'percentage done' do