From 8d0d2fd02dc8172a2ef594dc7f7aaff17bbc7baa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Mon, 8 Jan 2018 16:20:52 +0100 Subject: [PATCH] [26829] Patch reform-rails to use activerecord i18n_scope The validator passed to AM::Error does not use the `i18n_scope` we define on either Reform::Form or the model, but is delegated from the included AM::Translations module. This in turn causes I18n to lookup the scope `:activemodel`, failing the localization. https://github.com/trailblazer/reform-rails/issues/56 https://github.com/trailblazer/reform-rails/pull/35 --- config/initializers/reform.rb | 10 ++++++++++ spec/contracts/work_packages/base_contract_spec.rb | 12 ++++++++++++ 2 files changed, 22 insertions(+) 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