class Ndd::RSpec::Rails::Matchers::Model::HaveATranslatedModel

Implements {#have_a_translated_model}.

Public Instance Methods

description() click to toggle source

@return [String] a description of this matcher.

# File lib/ndd/rspec/rails/matchers/model/have_a_translated_model.rb, line 24
def description
  "have a translated model name in #{locales_as_string(@tested_locales)}"
end
failure_message() click to toggle source

@return [String] details about the failure of this matcher.

# File lib/ndd/rspec/rails/matchers/model/have_a_translated_model.rb, line 29
def failure_message
  message = ''
  message << "expected '#{@model.class}' to have a translated model name\n"
  message << "but the '#{translation_key}' key was not found\n"
  message << "for the locales: #{locales_as_string(@failed_locales)}"
  message
end
matches?(model) click to toggle source

@param model [Object] the model being tested. @return [Boolean] true if the model has an associated translation, false otherwise.

# File lib/ndd/rspec/rails/matchers/model/have_a_translated_model.rb, line 14
def matches?(model)
  @model = model
  @failed_locales = []
  @tested_locales.each do |tested_locale|
    @failed_locales << tested_locale unless translated?(tested_locale, translation_key)
  end
  @failed_locales.empty?
end

Private Instance Methods

translation_key() click to toggle source

@return [String] the translation key of the model.

# File lib/ndd/rspec/rails/matchers/model/have_a_translated_model.rb, line 41
def translation_key
  "activerecord.models.#{@model.class.name.underscore}"
end