Skip to content

Commit

Permalink
Improve dummy app configuration
Browse files Browse the repository at this point in the history
- Fix a config deprecation
- Add a custom deprecator because `ActiveSupport::Deprecation.warn` is
  deprecated
  • Loading branch information
tagliala committed Jul 28, 2023
1 parent 8232633 commit 6c835be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/route_translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'route_translator/extensions'
require 'route_translator/translator'
require 'route_translator/host'
require 'route_translator/version'

module RouteTranslator
extend RouteTranslator::Host
Expand Down Expand Up @@ -39,7 +40,7 @@ def resolve_host_locale_config_conflicts
def check_deprecations
return if @config.i18n_use_slash_separator

ActiveSupport::Deprecation.warn <<~MSG
deprecator.warn <<~MSG
`i18n_use_slash_separator` set to `false` is deprecated and will be
removed in the next major release of Route Translator to match
Rails' ActiveRecord nested model syntax.
Expand Down Expand Up @@ -90,4 +91,8 @@ def locale_from_params(params)
locale = params[config.locale_param_key]&.to_sym
locale if I18n.available_locales.include?(locale)
end

def deprecator
@deprecator ||= ActiveSupport::Deprecation.new(RouteTranslator::VERSION, 'RouteTranslator')
end
end
1 change: 1 addition & 0 deletions test/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ module Dummy
class Application < Rails::Application
config.active_support.deprecation = :log
config.eager_load = false
config.active_support.cache_format_version = 7.0 if Rails.version >= '7.0'
end
end
6 changes: 3 additions & 3 deletions test/integration/i18n_slash_separator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ def teardown
end

def test_deprecation_when_default
assert_deprecated('i18n_use_slash_separator') do
assert_deprecated('i18n_use_slash_separator', RouteTranslator.deprecator) do
RouteTranslator.config
end
end

def test_deprecation_when_false
config_i18n_use_slash_separator false

assert_deprecated('i18n_use_slash_separator') do
assert_deprecated('i18n_use_slash_separator', RouteTranslator.deprecator) do
RouteTranslator.config
end
end

def test_no_deprecation_when_true
config_i18n_use_slash_separator true

assert_not_deprecated do
assert_not_deprecated(RouteTranslator.deprecator) do
RouteTranslator.config
end
end
Expand Down

0 comments on commit 6c835be

Please sign in to comment.