|
1 | 1 | require "test_helper" |
2 | 2 |
|
3 | 3 | class EnumlingoTest < ActiveSupport::TestCase |
| 4 | + setup do |
| 5 | + @book = products(:book) |
| 6 | + @other = products(:other) |
| 7 | + end |
| 8 | + |
4 | 9 | test "it has a version number" do |
5 | 10 | assert Enumlingo::VERSION |
6 | 11 | end |
7 | 12 |
|
8 | 13 | test "it return English product kind of book" do |
9 | | - I18n.locale = "en" |
10 | | - book = products(:book) |
11 | | - |
12 | | - assert_equal "Book", book.kind_lingo |
| 14 | + assert_equal "Book", @book.kind_lingo(locale: :en) |
13 | 15 | end |
14 | 16 |
|
15 | 17 | test "it return Chinese product kind of book" do |
16 | | - I18n.locale = "zh-CN" |
17 | | - book = products(:book) |
18 | | - |
19 | | - assert_equal "书籍", book.kind_lingo |
| 18 | + assert_equal "书籍", @book.kind_lingo(locale: "zh-CN") |
20 | 19 | end |
21 | 20 |
|
22 | 21 | test "it return missing translation of product kind of book" do |
23 | | - I18n.locale = "zh-CN" |
24 | | - book = products(:other) |
25 | | - assert_equal "Translation missing: zh-CN.activerecord.attributes.product.kinds.other", book.kind_lingo |
| 22 | + assert_equal "Translation missing: zh-CN.activerecord.attributes.product.kinds.other", @other.kind_lingo(locale: "zh-CN") |
26 | 23 | end |
27 | 24 |
|
28 | 25 | test "it return options of product kind" do |
29 | | - I18n.locale = "en" |
30 | | - assert_equal [["Book", "book"], ["Food", "food"], ["Medical", "medical"], ["Other", "other"]], Product.kinds_lingo |
| 26 | + assert_equal [["Book", "book"], ["Food", "food"], ["Medical", "medical"], ["Other", "other"]], Product.kinds_lingo(locale: :en) |
31 | 27 | end |
32 | 28 |
|
33 | 29 | test "it return options of product kind in Chinese" do |
34 | | - I18n.locale = "zh-CN" |
35 | | - assert_equal [["书籍", "book"], ["食品", "food"], ["药品", "medical"], ["Translation missing: zh-CN.activerecord.attributes.product.kinds.other", "other"]], Product.kinds_lingo |
| 30 | + assert_equal [["书籍", "book"], ["食品", "food"], ["药品", "medical"], ["Translation missing: zh-CN.activerecord.attributes.product.kinds.other", "other"]], Product.kinds_lingo(locale: "zh-CN") |
36 | 31 | end |
37 | 32 |
|
38 | 33 | test "it return text of product kind" do |
39 | | - I18n.locale = "en" |
40 | | - assert_equal "Book", Product.kind_lingo(:book) |
| 34 | + assert_equal "Book", Product.kind_lingo(:book, locale: :en) |
41 | 35 | end |
42 | 36 |
|
43 | 37 | test "it return text of product kind in Chinese" do |
44 | | - I18n.locale = "zh-CN" |
45 | | - assert_equal "书籍", Product.kind_lingo(:book) |
| 38 | + assert_equal "书籍", Product.kind_lingo(:book, locale: "zh-CN") |
46 | 39 | end |
47 | 40 |
|
48 | 41 | test "return options of product kind value with custom translation" do |
49 | | - assert_equal [["Book", 0], ["Food", 1], ["Medical", 2], ["Other", 3]], Product.kinds_lingo_values(:en) |
| 42 | + assert_equal [["Book", 0], ["Food", 1], ["Medical", 2], ["Other", 3]], Product.kinds_lingo_values(locale: :en) |
50 | 43 | end |
51 | 44 | end |
0 commit comments