Class: Shoulda::Matchers::ActiveModel::HaveModelTranslationsMatcher
- Inherits:
-
Object
- Object
- Shoulda::Matchers::ActiveModel::HaveModelTranslationsMatcher
- Defined in:
- lib/beyond_the_api_test_helpers/shoulda/have_model_translations.rb
Instance Method Summary collapse
- #assert_translated_attribute(attribute) ⇒ Object
- #description ⇒ Object
- #failure_message ⇒ Object (also: #failure_message_for_should)
- #failure_message_when_negated ⇒ Object (also: #failure_message_for_should_not)
-
#initialize(options = {}) ⇒ HaveModelTranslationsMatcher
constructor
A new instance of HaveModelTranslationsMatcher.
- #matches?(subject) ⇒ Boolean
- #matches_attributes? ⇒ Boolean
- #matches_model_name? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ HaveModelTranslationsMatcher
Returns a new instance of HaveModelTranslationsMatcher.
10 11 12 |
# File 'lib/beyond_the_api_test_helpers/shoulda/have_model_translations.rb', line 10 def initialize( = {}) @options = end |
Instance Method Details
#assert_translated_attribute(attribute) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/beyond_the_api_test_helpers/shoulda/have_model_translations.rb', line 36 def assert_translated_attribute(attribute) begin translated_attr = I18n.t('activerecord.attributes.' \ "#{model_class.to_s.underscore}.#{attribute}") rescue translated_attr = I18n.t("attributes.#{attribute}") end model_class.human_attribute_name(attribute) == translated_attr end |
#description ⇒ Object
56 57 58 |
# File 'lib/beyond_the_api_test_helpers/shoulda/have_model_translations.rb', line 56 def description 'have model translations' end |
#failure_message ⇒ Object Also known as: failure_message_for_should
46 47 48 |
# File 'lib/beyond_the_api_test_helpers/shoulda/have_model_translations.rb', line 46 def "Expected #{expectation} (#{@missing})" end |
#failure_message_when_negated ⇒ Object Also known as: failure_message_for_should_not
51 52 53 |
# File 'lib/beyond_the_api_test_helpers/shoulda/have_model_translations.rb', line 51 def "Did not expect #{expectation}" end |
#matches?(subject) ⇒ Boolean
14 15 16 17 |
# File 'lib/beyond_the_api_test_helpers/shoulda/have_model_translations.rb', line 14 def matches?(subject) @subject = subject matches_model_name? && matches_attributes? end |
#matches_attributes? ⇒ Boolean
27 28 29 30 31 32 33 34 |
# File 'lib/beyond_the_api_test_helpers/shoulda/have_model_translations.rb', line 27 def matches_attributes? attributes = @options[:attributes] return true unless attributes attributes.each do |attribute| return false unless assert_translated_attribute(attribute) end true end |
#matches_model_name? ⇒ Boolean
19 20 21 22 23 24 25 |
# File 'lib/beyond_the_api_test_helpers/shoulda/have_model_translations.rb', line 19 def matches_model_name? I18n.available_locales.each do |locale| I18n.locale = locale return false unless model_name.human == I18n.t("#{i18n_path}.one") return false unless model_name.human(count: 2) == I18n.t("#{i18n_path}.other") end end |