|
2 | 2 |
|
3 | 3 | describe DiscourseTranslator::TopicTranslator do |
4 | 4 | describe ".translate" do |
5 | | - fab!(:topic) { Fabricate(:topic, title: "this is a cat topic :)") } |
| 5 | + fab!(:topic) do |
| 6 | + Fabricate( |
| 7 | + :topic, |
| 8 | + title: "this is a cat topic :)", |
| 9 | + excerpt: "cats are great. how many do you have?", |
| 10 | + ) |
| 11 | + end |
6 | 12 | let(:translator) { mock } |
7 | 13 | let(:translated_title) { "これは猫の話題です :)" } |
| 14 | + let(:translated_excerpt) { "猫は素晴らしいですね。何匹飼っていますか?" } |
8 | 15 | let(:fancy_title) { "これは猫の話題です :slight_smile:" } |
9 | 16 | let(:target_locale) { "ja" } |
10 | 17 |
|
11 | 18 | before do |
12 | 19 | DiscourseTranslator::Provider::TranslatorProvider.stubs(:get).returns(translator) |
13 | 20 | translator.stubs(:translate_topic!).with(topic, :ja).returns(translated_title) |
| 21 | + translator.stubs(:translate_text!).with(topic.excerpt, :ja).returns(translated_excerpt) |
14 | 22 | end |
15 | 23 |
|
16 | 24 | it "returns nil if topic is blank" do |
|
30 | 38 |
|
31 | 39 | it "translates with topic and locale" do |
32 | 40 | translator.expects(:translate_topic!).with(topic, :ja).returns(translated_title) |
| 41 | + translator.expects(:translate_text!).with(topic.excerpt, :ja).returns(translated_title) |
33 | 42 |
|
34 | 43 | described_class.translate(topic, "ja") |
35 | 44 | end |
36 | 45 |
|
37 | 46 | it "normalizes dashes to underscores and symbol type for locale" do |
38 | 47 | translator.expects(:translate_topic!).with(topic, :zh_CN).returns("这是一个猫主题 :)") |
| 48 | + translator.expects(:translate_text!).with(topic.excerpt, :zh_CN).returns("这是一个猫主题 :)") |
39 | 49 |
|
40 | 50 | described_class.translate(topic, "zh-CN") |
41 | 51 | end |
|
48 | 58 | topic_id: topic.id, |
49 | 59 | locale: target_locale, |
50 | 60 | title: translated_title, |
| 61 | + excerpt: translated_excerpt, |
51 | 62 | fancy_title: fancy_title, |
52 | 63 | localizer_user_id: Discourse.system_user.id, |
53 | 64 | ) |
|
61 | 72 | topic:, |
62 | 73 | locale: "ja", |
63 | 74 | title: "old title", |
| 75 | + excerpt: "old excerpt", |
64 | 76 | fancy_title: "old_fancy_title", |
65 | 77 | ) |
66 | 78 | expect { |
67 | 79 | expect(described_class.translate(topic, "ja")).to have_attributes( |
68 | 80 | id: localization.id, |
69 | 81 | title: translated_title, |
70 | 82 | fancy_title: fancy_title, |
| 83 | + excerpt: translated_excerpt, |
71 | 84 | ) |
72 | 85 | expect(localization.reload).to have_attributes( |
73 | 86 | title: translated_title, |
74 | 87 | fancy_title: fancy_title, |
| 88 | + excerpt: translated_excerpt, |
75 | 89 | ) |
76 | 90 | }.to_not change { TopicLocalization.count } |
77 | 91 | end |
|
0 commit comments