Method: Ndd::RSpec::Rails::Matchers::Model#have_a_translated_attribute

Defined in:
lib/ndd/rspec/rails/matchers/model.rb

#have_a_translated_attribute(attribute) ⇒ Ndd::RSpec::Rails::Matchers::Model::HaveATranslatedAttribute

Ensure that an attribute has an associated translation.

More precisely, ensure that

I18n.t(locale, "activerecord.attributes.{snake_case_class_name}.{snake_case_attribute_name}")

returns a value for the default locale (i.e. I18n.default_locale) or all the available locales (i.e. I18n.available_locales).

Examples:


RSpec.describe MyModel, type: :model do
  # both are equivalent
  it { is_expected.to have_a_translated_attribute(:comment) }
  it { is_expected.to have_a_translated_attribute(:comment).in_available_locales }

  it { is_expected.to have_a_translated_attribute(:comment).in_default_locale }
end

33
34
35
# File 'lib/ndd/rspec/rails/matchers/model.rb', line 33

def have_a_translated_attribute(attribute) # rubocop:disable Style/PredicateName
  HaveATranslatedAttribute.new(attribute)
end