I18n deprecation warning when using ActiveModel without Rails

Eva

When I run Rspec on my models, I get this warning:

[deprecated] I18n.enforce_available_locales will default to true in the future. If you really want to skip validation of your locale you can set I18n.enforce_available_locales = false to avoid this message.

I saw a similar question where the solution was to set config.i18n.enforce_available_locales or I18n.config.enforce_available_locales in my config/application.rb file. I tried both, but I still get the warning.

The test that gives me the deprecation warning does not use any Rails except for ActiveModel. Instead of requiring the default spec_helper, I created my own spec_helper that does not involve any Rails at all. I also tried setting enforce_available_locales in my custom spec_helper, but I got an uninitialized constant error.

How do I get rid of the deprecation warning?

Edit: Here's the exact code in my config/application.rb from one of my attempts with enforce_available_locales

require File.expand_path('../boot', __FILE__)

# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)

module Microblog
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de
    I18n.config.enforce_available_locales = true
  end
end
Eva

What seems to work is adding these lines to my spec_helper:

require 'i18n'
I18n.config.enforce_available_locales = true

Because my tests don't use Rails, the Application class goes untouched, so enforce_available_locales must go in the spec_helper itself. The first line gets rid of the uninitialized constant error.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Deprecation warning using this.refs

How do I resolve the deprecation warning "Method to_hash is deprecated and will be removed in Rails 5.1"

Rails I18n validation deprecation warning

Deprecation warning when using has_many :through :uniq in Rails 4

Rails 4.2 DEPRECATION WARNING: `serialized_attributes` is deprecated without replacement,

ActiveRecord::Migration deprecation warning - asks for Rails version, but I'm not using Rails

Rails 5.1 testing changed attributes Deprecation Warning

Rails language name using I18n locale

Rails 5.1.1 deprecation warning changed_attributes

I18n warning when key is overriden

MomentJS Using Locale If Deprecation Format Warning Provided

Rails Upgrade 3.2 to 4.0: Model deprecation warning

Dangerous query method deprecation warning on Rails 5.2.3

Deprecation warning when connecting to mongoose

deprecation warning when running rails server for associations

rails Getting an DEPRECATION WARNING in my log file

Rails4 Deprecation Warning

How to configure locale aliases using i18n & rails?

Linking when using I18n Ruby on Rails

Translation For Dynamic Data Using Rails I18n

Deprecation warning for using (*args) with method

Deprecation warning when using Compass Rails

Rails 5 deprecation warning for tests

DEPRECATION WARNING in rails 4

:conditions deprecation warning rails4

Rails 5: DEPRECATION WARNING: You are passing an instance of ActiveRecord::Base to `exists?`. ..I have no idea

DEPRECATION WARNING: Calling `<<` to an ActiveModel::Errors message array in order to add an error is deprecated. in ruby

Rails i18n ActiveModel: Translate error message for absence validation

{{ yesterday_ds }} deprecation warning, but what should I be using instead?