Skip to content

Commit f6a46ec

Browse files
committed
Lint
1 parent 54b2699 commit f6a46ec

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed
Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,58 @@
11
# frozen_string_literal: true
22

3-
RSpec.describe Jobs::TranslateTranslatable do
4-
fab!(:post) { Fabricate(:post) }
5-
fab!(:topic) { Fabricate(:topic) }
3+
describe Jobs::TranslateTranslatable do
4+
fab!(:post)
5+
fab!(:topic)
6+
let!(:job) { Jobs::TranslateTranslatable.new }
67

78
before do
89
SiteSetting.translator_enabled = true
910
SiteSetting.translator = "Google"
1011
SiteSetting.automatic_translation_target_languages = "es|fr"
12+
allow(DiscourseTranslator::Google).to receive(:translate)
1113
end
1214

1315
describe "#execute" do
1416
it "does nothing when translator is disabled" do
1517
SiteSetting.translator_enabled = false
16-
expect(DiscourseTranslator::Google).not_to receive(:translate)
1718

18-
subject.execute(type: "Post", translatable_id: post.id)
19+
job.execute(type: "Post", translatable_id: post.id)
20+
21+
expect(DiscourseTranslator::Google).not_to have_received(:translate)
1922
end
2023

2124
it "does nothing when target languages are empty" do
2225
SiteSetting.automatic_translation_target_languages = ""
23-
expect(DiscourseTranslator::Google).not_to receive(:translate)
2426

25-
subject.execute(type: "Post", translatable_id: post.id)
27+
job.execute(type: "Post", translatable_id: post.id)
28+
29+
expect(DiscourseTranslator::Google).not_to have_received(:translate)
2630
end
2731

2832
it "translates posts to configured target languages" do
29-
expect(DiscourseTranslator::Google).to receive(:translate).with(post, :es)
30-
expect(DiscourseTranslator::Google).to receive(:translate).with(post, :fr)
31-
expect(MessageBus).to receive(:publish).with(
32-
"/topic/#{post.topic_id}",
33-
type: :revised,
34-
id: post.id,
35-
)
36-
37-
subject.execute(type: "Post", translatable_id: post.id)
33+
MessageBus.expects(:publish).with("/topic/#{post.topic.id}", type: :revised, id: post.id).once
34+
35+
job.execute(type: "Post", translatable_id: post.id)
36+
37+
expect(DiscourseTranslator::Google).to have_received(:translate).with(post, :es)
38+
expect(DiscourseTranslator::Google).to have_received(:translate).with(post, :fr)
3839
end
3940

4041
it "translates topics to configured target languages" do
41-
expect(DiscourseTranslator::Google).to receive(:translate).with(topic, :es)
42-
expect(DiscourseTranslator::Google).to receive(:translate).with(topic, :fr)
43-
expect(MessageBus).to receive(:publish).with("/topic/#{topic.id}", type: :revised, id: 1)
42+
MessageBus.expects(:publish).with("/topic/#{topic.id}", type: :revised, id: 1).once
43+
44+
job.execute(type: "Topic", translatable_id: topic.id)
4445

45-
subject.execute(type: "Topic", translatable_id: topic.id)
46+
expect(DiscourseTranslator::Google).to have_received(:translate).with(topic, :es)
47+
expect(DiscourseTranslator::Google).to have_received(:translate).with(topic, :fr)
4648
end
4749

4850
it "does nothing when translatable is not found" do
49-
expect(DiscourseTranslator::Google).not_to receive(:translate)
50-
expect(MessageBus).not_to receive(:publish)
51+
MessageBus.expects(:publish).never
52+
53+
job.execute(type: "Post", translatable_id: -1)
5154

52-
subject.execute(type: "Post", translatable_id: -1)
55+
expect(DiscourseTranslator::Google).not_to have_received(:translate)
5356
end
5457
end
5558
end

0 commit comments

Comments
 (0)