-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX: Skip translations for empty or small actions posts
- Loading branch information
Showing
3 changed files
with
126 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# frozen_string_literal: true | ||
|
||
require "aws-sdk-translate" | ||
|
||
describe Jobs::DetectTranslation do | ||
before do | ||
SiteSetting.translator = "Amazon" | ||
client = Aws::Translate::Client.new(stub_responses: true) | ||
client.stub_responses( | ||
:translate_text, | ||
{ translated_text: "大丈夫", source_language_code: "en", target_language_code: "jp" }, | ||
) | ||
Aws::Translate::Client.stubs(:new).returns(client) | ||
end | ||
|
||
it "does not detect translation if translator disabled" do | ||
SiteSetting.translator_enabled = false | ||
|
||
post = Fabricate(:post) | ||
Jobs::DetectTranslation.new.execute(post_id: post.id) | ||
|
||
expect(post.custom_fields[DiscourseTranslator::DETECTED_LANG_CUSTOM_FIELD]).to be_nil | ||
end | ||
|
||
describe "translator enabled" do | ||
before { SiteSetting.translator_enabled = true } | ||
|
||
it "does not detect translation if post does not exist" do | ||
post = Fabricate(:post) | ||
post.destroy | ||
|
||
Jobs::DetectTranslation.new.execute(post_id: post.id) | ||
|
||
expect(post.custom_fields[DiscourseTranslator::DETECTED_LANG_CUSTOM_FIELD]).to be_nil | ||
end | ||
|
||
it "detects translation" do | ||
post = Fabricate(:post, raw: "this is a sample post") | ||
|
||
Jobs::DetectTranslation.new.execute(post_id: post.id) | ||
|
||
expect(post.custom_fields[DiscourseTranslator::DETECTED_LANG_CUSTOM_FIELD]).to eq("en") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters