class Ndd::RSpec::Rails::Matchers::Model::HaveATranslatedAttribute
Implements {#have_a_translated_attribute}.
Public Class Methods
new(attribute)
click to toggle source
@param attribute [String|Symbol] the attribute to test.
Calls superclass method
# File lib/ndd/rspec/rails/matchers/model/have_a_translated_attribute.rb, line 13 def initialize(attribute) super() @attribute = attribute end
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_attribute.rb, line 30 def description "have a translated attribute name for '#{@attribute}' 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_attribute.rb, line 35 def failure_message message = '' message << "expected '#{@model.class}' to have a translated attribute name for '#{@attribute}'\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 attribute has an associated translation, false otherwise.
# File lib/ndd/rspec/rails/matchers/model/have_a_translated_attribute.rb, line 20 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 attribute.
# File lib/ndd/rspec/rails/matchers/model/have_a_translated_attribute.rb, line 47 def translation_key model_key = @model.class.name.underscore attribute_key = @attribute.to_s "activerecord.attributes.#{model_key}.#{attribute_key}" end