|
76 | 76 |
|
77 | 77 | job.execute({}) |
78 | 78 | end |
| 79 | + |
| 80 | + describe "with public content limitation" do |
| 81 | + fab!(:private_category) { Fabricate(:private_category, group: Group[:staff]) } |
| 82 | + fab!(:private_topic) { Fabricate(:topic, category: private_category) } |
| 83 | + fab!(:private_post) { Fabricate(:post, topic: private_topic, locale: nil) } |
| 84 | + |
| 85 | + before { SiteSetting.automatic_translation_backfill_limit_to_public_content = true } |
| 86 | + |
| 87 | + it "only processes posts from public categories" do |
| 88 | + DiscourseTranslator::PostLocaleDetector.expects(:detect_locale).with(post).once |
| 89 | + DiscourseTranslator::PostLocaleDetector.expects(:detect_locale).with(private_post).never |
| 90 | + |
| 91 | + job.execute({}) |
| 92 | + end |
| 93 | + |
| 94 | + it "processes all posts when setting is disabled" do |
| 95 | + SiteSetting.automatic_translation_backfill_limit_to_public_content = false |
| 96 | + |
| 97 | + DiscourseTranslator::PostLocaleDetector.expects(:detect_locale).with(post).once |
| 98 | + DiscourseTranslator::PostLocaleDetector.expects(:detect_locale).with(private_post).once |
| 99 | + |
| 100 | + job.execute({}) |
| 101 | + end |
| 102 | + end |
| 103 | + |
| 104 | + describe "with max age limit" do |
| 105 | + fab!(:old_post) { Fabricate(:post, locale: nil, created_at: 10.days.ago) } |
| 106 | + fab!(:new_post) { Fabricate(:post, locale: nil, created_at: 2.days.ago) } |
| 107 | + |
| 108 | + before { SiteSetting.automatic_translation_backfill_max_age_days = 5 } |
| 109 | + |
| 110 | + it "only processes posts within the age limit" do |
| 111 | + # other posts |
| 112 | + DiscourseTranslator::PostLocaleDetector.expects(:detect_locale).at_least_once |
| 113 | + |
| 114 | + DiscourseTranslator::PostLocaleDetector.expects(:detect_locale).with(new_post).once |
| 115 | + DiscourseTranslator::PostLocaleDetector.expects(:detect_locale).with(old_post).never |
| 116 | + |
| 117 | + job.execute({}) |
| 118 | + end |
| 119 | + |
| 120 | + it "processes all posts when setting is disabled" do |
| 121 | + SiteSetting.automatic_translation_backfill_max_age_days = 0 |
| 122 | + |
| 123 | + # other posts |
| 124 | + DiscourseTranslator::PostLocaleDetector.expects(:detect_locale).at_least_once |
| 125 | + |
| 126 | + DiscourseTranslator::PostLocaleDetector.expects(:detect_locale).with(new_post).once |
| 127 | + DiscourseTranslator::PostLocaleDetector.expects(:detect_locale).with(old_post).once |
| 128 | + |
| 129 | + job.execute({}) |
| 130 | + end |
| 131 | + end |
79 | 132 | end |
0 commit comments