File: i18n_test.rb

package info (click to toggle)
rails 2%3A7.2.2.1%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 43,352 kB
  • sloc: ruby: 349,799; javascript: 30,703; yacc: 46; sql: 43; sh: 29; makefile: 27
file content (46 lines) | stat: -rw-r--r-- 1,822 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true

require "cases/helper"
require "models/topic"
require "models/reply"

class ActiveRecordI18nTests < ActiveRecord::TestCase
  def setup
    I18n.backend = I18n::Backend::Simple.new
  end

  def test_translated_model_attributes
    I18n.backend.store_translations "en", activerecord: { attributes: { topic: { title: "topic title attribute" } } }
    assert_equal "topic title attribute", Topic.human_attribute_name("title")
  end

  def test_translated_model_attributes_with_symbols
    I18n.backend.store_translations "en", activerecord: { attributes: { topic: { title: "topic title attribute" } } }
    assert_equal "topic title attribute", Topic.human_attribute_name(:title)
  end

  def test_translated_model_attributes_with_sti
    I18n.backend.store_translations "en", activerecord: { attributes: { reply: { title: "reply title attribute" } } }
    assert_equal "reply title attribute", Reply.human_attribute_name("title")
  end

  def test_translated_model_attributes_with_sti_fallback
    I18n.backend.store_translations "en", activerecord: { attributes: { topic: { title: "topic title attribute" } } }
    assert_equal "topic title attribute", Reply.human_attribute_name("title")
  end

  def test_translated_model_names
    I18n.backend.store_translations "en", activerecord: { models: { topic: "topic model" } }
    assert_equal "topic model", Topic.model_name.human
  end

  def test_translated_model_names_with_sti
    I18n.backend.store_translations "en", activerecord: { models: { reply: "reply model" } }
    assert_equal "reply model", Reply.model_name.human
  end

  def test_translated_model_names_with_sti_fallback
    I18n.backend.store_translations "en", activerecord: { models: { topic: "topic model" } }
    assert_equal "topic model", Reply.model_name.human
  end
end