mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Remove support for deprecated validation message interpolation format
This commit is contained in:
@@ -75,5 +75,4 @@ module ActiveRecord
|
||||
end
|
||||
end
|
||||
|
||||
require 'active_record/i18n_interpolation_deprecation'
|
||||
I18n.load_path << File.dirname(__FILE__) + '/active_record/locale/en.yml'
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
# Deprecates the use of the former message interpolation syntax in activerecord
|
||||
# as in "must have %d characters". The new syntax uses explicit variable names
|
||||
# as in "{{value}} must have {{count}} characters".
|
||||
|
||||
require 'i18n/backend/simple'
|
||||
module I18n
|
||||
module Backend
|
||||
class Simple
|
||||
DEPRECATED_INTERPOLATORS = { '%d' => '{{count}}', '%s' => '{{value}}' }
|
||||
|
||||
protected
|
||||
def interpolate_with_deprecated_syntax(locale, string, values = {})
|
||||
return string unless string.is_a?(String)
|
||||
|
||||
string = string.gsub(/%d|%s/) do |s|
|
||||
instead = DEPRECATED_INTERPOLATORS[s]
|
||||
ActiveSupport::Deprecation.warn "using #{s} in messages is deprecated; use #{instead} instead."
|
||||
instead
|
||||
end
|
||||
|
||||
interpolate_without_deprecated_syntax(locale, string, values)
|
||||
end
|
||||
alias_method_chain :interpolate, :deprecated_syntax
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -38,35 +38,17 @@ class ActiveRecordValidationsI18nTests < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def test_default_error_messages_is_deprecated
|
||||
assert_deprecated('ActiveRecord::Errors.default_error_messages') do
|
||||
ActiveRecord::Errors.default_error_messages
|
||||
def test_percent_s_interpolation_syntax_in_error_messages_was_deprecated
|
||||
assert_not_deprecated do
|
||||
default = "%s interpolation syntax was deprecated"
|
||||
assert_equal default, I18n.t(:does_not_exist, :default => default, :value => 'this')
|
||||
end
|
||||
end
|
||||
|
||||
def test_percent_s_interpolation_syntax_in_error_messages_still_works
|
||||
ActiveSupport::Deprecation.silence do
|
||||
result = I18n.t :does_not_exist, :default => "%s interpolation syntax is deprecated", :value => 'this'
|
||||
assert_equal result, "this interpolation syntax is deprecated"
|
||||
end
|
||||
end
|
||||
|
||||
def test_percent_s_interpolation_syntax_in_error_messages_is_deprecated
|
||||
assert_deprecated('using %s in messages') do
|
||||
I18n.t :does_not_exist, :default => "%s interpolation syntax is deprected", :value => 'this'
|
||||
end
|
||||
end
|
||||
|
||||
def test_percent_d_interpolation_syntax_in_error_messages_still_works
|
||||
ActiveSupport::Deprecation.silence do
|
||||
result = I18n.t :does_not_exist, :default => "%d interpolation syntaxes are deprecated", :count => 2
|
||||
assert_equal result, "2 interpolation syntaxes are deprecated"
|
||||
end
|
||||
end
|
||||
|
||||
def test_percent_d_interpolation_syntax_in_error_messages_is_deprecated
|
||||
assert_deprecated('using %d in messages') do
|
||||
I18n.t :does_not_exist, :default => "%d interpolation syntaxes are deprected", :count => 2
|
||||
def test_percent_d_interpolation_syntax_in_error_messages_was_deprecated
|
||||
assert_not_deprecated do
|
||||
default = "%d interpolation syntaxes are deprecated"
|
||||
assert_equal default, I18n.t(:does_not_exist, :default => default, :count => 2)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user