aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/validations
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2019-03-11 21:47:38 -0400
committerGitHub <noreply@github.com>2019-03-11 21:47:38 -0400
commitf2cd46bd043820aa732203ab6c6a54f37062aad1 (patch)
treea24548bad1ddd80b3893a52d1d4163f2d438a6d2 /activerecord/test/cases/validations
parent96242410a8ce8d2de60483002ac20526f3f64c90 (diff)
parent9ccc5e104287e45b21e4129991b1e507aa1a7dff (diff)
downloadrails-f2cd46bd043820aa732203ab6c6a54f37062aad1.tar.gz
rails-f2cd46bd043820aa732203ab6c6a54f37062aad1.tar.bz2
rails-f2cd46bd043820aa732203ab6c6a54f37062aad1.zip
Merge pull request #35424 from Korri/validation-rules-locale-fallback
Fall back to parent locale before falling back to the :errors namespace
Diffstat (limited to 'activerecord/test/cases/validations')
-rw-r--r--activerecord/test/cases/validations/i18n_generate_message_validation_test.rb20
1 files changed, 18 insertions, 2 deletions
diff --git a/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb b/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb
index 703c24b340..993c201f03 100644
--- a/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb
+++ b/activerecord/test/cases/validations/i18n_generate_message_validation_test.rb
@@ -4,16 +4,20 @@ require "cases/helper"
require "models/topic"
class I18nGenerateMessageValidationTest < ActiveRecord::TestCase
+ class Backend < I18n::Backend::Simple
+ include I18n::Backend::Fallbacks
+ end
+
def setup
Topic.clear_validators!
@topic = Topic.new
- I18n.backend = I18n::Backend::Simple.new
+ I18n.backend = Backend.new
end
def reset_i18n_load_path
@old_load_path, @old_backend = I18n.load_path.dup, I18n.backend
I18n.load_path.clear
- I18n.backend = I18n::Backend::Simple.new
+ I18n.backend = Backend.new
yield
ensure
I18n.load_path.replace @old_load_path
@@ -83,4 +87,16 @@ class I18nGenerateMessageValidationTest < ActiveRecord::TestCase
assert_equal "Custom taken message", @topic.errors.generate_message(:title, :taken, value: "title")
end
end
+
+ test "activerecord attributes scope falls back to parent locale before it falls back to the :errors namespace" do
+ reset_i18n_load_path do
+ I18n.backend.store_translations "en", activerecord: { errors: { models: { topic: { attributes: { title: { taken: "custom en message" } } } } } }
+ I18n.backend.store_translations "en-US", errors: { messages: { taken: "generic en-US fallback" } }
+
+ I18n.with_locale "en-US" do
+ assert_equal "custom en message", @topic.errors.generate_message(:title, :taken, value: "title")
+ assert_equal "generic en-US fallback", @topic.errors.generate_message(:heading, :taken, value: "heading")
+ end
+ end
+ end
end