|
3 | 3 | require "rails_helper" |
4 | 4 |
|
5 | 5 | RSpec.describe Post do |
6 | | - before { SiteSetting.translator_enabled = true } |
| 6 | + before do |
| 7 | + SiteSetting.translator_enabled = true |
| 8 | + SiteSetting.create_topic_allowed_groups = Group::AUTO_GROUPS[:everyone] |
| 9 | + end |
7 | 10 |
|
8 | 11 | describe "translatable" do |
9 | 12 | fab!(:post) |
|
70 | 73 | fab!(:topic) |
71 | 74 | fab!(:user) { Fabricate(:user, groups: [group]) } |
72 | 75 |
|
73 | | - before do |
74 | | - Jobs.run_immediately! |
75 | | - SiteSetting.create_topic_allowed_groups = Group::AUTO_GROUPS[:everyone] |
76 | | - end |
| 76 | + before { Jobs.run_immediately! } |
77 | 77 |
|
78 | 78 | it "queues the post for language detection when user and posts are in the right group" do |
79 | 79 | SiteSetting.restrict_translation_by_poster_group = "#{group.id}" |
|
92 | 92 | ).to be_truthy |
93 | 93 | end |
94 | 94 |
|
| 95 | + it "does not queue bot posts for language detection" do |
| 96 | + SiteSetting.restrict_translation_by_poster_group = Group::AUTO_GROUPS[:everyone] |
| 97 | + post = |
| 98 | + PostCreator.new( |
| 99 | + Discourse.system_user, |
| 100 | + { title: "hello world topic", raw: "my name is cat", category: Fabricate(:category).id }, |
| 101 | + ).create |
| 102 | + |
| 103 | + expect( |
| 104 | + Discourse.redis.sismember(DiscourseTranslator::LANG_DETECT_NEEDED, post.id), |
| 105 | + ).to be_falsey |
| 106 | + end |
| 107 | + |
95 | 108 | context "when user and posts are not in the right group" do |
96 | 109 | it "does not queue the post for language detection" do |
97 | 110 | SiteSetting.restrict_translation_by_poster_group = "#{group.id + 1}" |
|
111 | 124 | end |
112 | 125 | end |
113 | 126 | end |
| 127 | + |
| 128 | + describe "automatic translation job" do |
| 129 | + fab!(:user) |
| 130 | + |
| 131 | + it "enqueues translate_translatable job when post cooked" do |
| 132 | + SiteSetting.automatic_translation_target_languages = "es" |
| 133 | + post = Fabricate(:post, user: user) |
| 134 | + CookedPostProcessor.new(post).post_process |
| 135 | + |
| 136 | + expect_job_enqueued( |
| 137 | + job: :translate_translatable, |
| 138 | + args: { |
| 139 | + type: "Post", |
| 140 | + translatable_id: post.id, |
| 141 | + }, |
| 142 | + ) |
| 143 | + end |
| 144 | + |
| 145 | + it "does not enqueues translate_translatable job for bot posts" do |
| 146 | + SiteSetting.automatic_translation_target_languages = "es" |
| 147 | + post = Fabricate(:post, user: Discourse.system_user) |
| 148 | + CookedPostProcessor.new(post).post_process |
| 149 | + |
| 150 | + expect( |
| 151 | + job_enqueued?( |
| 152 | + job: :translate_translatable, |
| 153 | + args: { |
| 154 | + type: "Post", |
| 155 | + translatable_id: post.id, |
| 156 | + }, |
| 157 | + ), |
| 158 | + ).to eq false |
| 159 | + end |
| 160 | + end |
114 | 161 | end |
0 commit comments