From 0619e498ee60650b751eaac5842e2779af386b56 Mon Sep 17 00:00:00 2001 From: Hayden Ball Date: Sat, 30 Jan 2021 11:58:54 +0000 Subject: [PATCH 1/2] Ensure I18n translations are loaded before storing custom translation Otherwise, the custom translation may be overwritten when the backend loads translations as part of validation --- test/date_validator_test.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/date_validator_test.rb b/test/date_validator_test.rb index fa25b14..d7c235b 100644 --- a/test/date_validator_test.rb +++ b/test/date_validator_test.rb @@ -84,6 +84,8 @@ module Validations it "allows custom validation message to be handled by I18n" do custom_message = 'Custom Date Message' + + I18n.backend.eager_load! if I18n.backend.respond_to?(:eager_load!) I18n.backend.store_translations('en', { errors: { messages: { not_a_date: custom_message }}}) TestRecord.validates :expiration_date, date: true From b94fbc9fc57b828b2a78ae0a2da7c9b829923b9f Mon Sep 17 00:00:00 2001 From: Hayden Ball Date: Mon, 28 Dec 2020 16:43:56 +0000 Subject: [PATCH 2/2] Require time zone helper for tests --- test/test_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_helper.rb b/test/test_helper.rb index 21c7da1..cf49f39 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -12,6 +12,7 @@ require 'minitest/autorun' require 'active_model' +require 'active_support/core_ext/time/zones' require 'date_validator' I18n.load_path += Dir[File.expand_path(File.join(File.dirname(__FILE__), '../config/locales', '*.yml')).to_s]