|
12 | 12 |
|
13 | 13 | describe "#can_translate" do |
14 | 14 | it "returns false when translator disabled" do |
15 | | - SiteSetting.translator_enabled = true |
| 15 | + SiteSetting.translator_enabled = false |
16 | 16 | serializer = PostSerializer.new(post, scope: Guardian.new) |
17 | 17 |
|
18 | 18 | expect(serializer.can_translate).to eq(false) |
19 | 19 | end |
20 | 20 |
|
21 | 21 | describe "when translator enabled" do |
22 | | - before do |
23 | | - SiteSetting.translator_enabled = true |
24 | | - Jobs.run_later! |
25 | | - end |
| 22 | + before { SiteSetting.translator_enabled = true } |
26 | 23 |
|
27 | | - describe "when small action post" do |
28 | | - fab!(:small_action) |
29 | | - let(:serializer) { PostSerializer.new(small_action, scope: Guardian.new) } |
| 24 | + describe "anon user" do |
| 25 | + let(:serializer) { PostSerializer.new(post, scope: Guardian.new) } |
30 | 26 |
|
31 | | - it "cannot translate" do |
32 | | - expect(serializer.can_translate).to eq(false) |
| 27 | + before do |
| 28 | + SiteSetting.restrict_translation_by_group = "#{Group::AUTO_GROUPS[:everyone]}" |
| 29 | + SiteSetting.restrict_translation_by_poster_group = "" |
33 | 30 | end |
34 | | - end |
35 | | - |
36 | | - describe "when post raw is empty" do |
37 | | - fab!(:empty_post) do |
38 | | - empty_post = Fabricate.build(:post, raw: "") |
39 | | - empty_post.save!(validate: false) |
40 | | - empty_post |
41 | | - end |
42 | | - let(:serializer) { PostSerializer.new(empty_post, scope: Guardian.new) } |
43 | 31 |
|
44 | 32 | it "cannot translate" do |
45 | 33 | expect(serializer.can_translate).to eq(false) |
|
49 | 37 | describe "logged in user" do |
50 | 38 | let(:serializer) { PostSerializer.new(post, scope: Guardian.new(user)) } |
51 | 39 |
|
52 | | - describe "when user is not in restrict_translation_by_group" do |
53 | | - it "cannot translate" do |
54 | | - SiteSetting.restrict_translation_by_group = "" |
| 40 | + it "cannot translate when user is not in restrict_translation_by_group" do |
| 41 | + SiteSetting.restrict_translation_by_group = "#{group.id + 1}" |
55 | 42 |
|
56 | | - expect(serializer.can_translate).to eq(false) |
57 | | - end |
| 43 | + expect(serializer.can_translate).to eq(false) |
58 | 44 | end |
59 | 45 |
|
60 | | - describe "when post is not in restrict_translation_by_poster_group" do |
61 | | - it "cannot translate" do |
62 | | - SiteSetting.restrict_translation_by_group = "#{group.id}" |
63 | | - SiteSetting.restrict_translation_by_poster_group = "" |
| 46 | + describe "user is in restrict_translation_by_group" do |
| 47 | + before { SiteSetting.restrict_translation_by_group = "#{group.id}" } |
64 | 48 |
|
65 | | - expect(serializer.can_translate).to eq(false) |
66 | | - end |
67 | | - end |
| 49 | + it "cannot translate when post author is not in restrict_translation_by_poster_group" do |
| 50 | + SiteSetting.restrict_translation_by_poster_group = "#{group.id}" |
68 | 51 |
|
69 | | - describe "when user is in restrict_translation_by_group and poster in restrict_translation_by_poster_group" do |
70 | | - before do |
71 | | - SiteSetting.restrict_translation_by_group = "#{group.id}" |
72 | | - SiteSetting.restrict_translation_by_poster_group = "#{post_user_group.id}" |
| 52 | + expect(serializer.can_translate).to eq(false) |
73 | 53 | end |
74 | 54 |
|
75 | | - describe "when post does not have DETECTED_LANG_CUSTOM_FIELD" do |
76 | | - it "cannot translate" do |
77 | | - expect(serializer.can_translate).to eq(false) |
| 55 | + describe "post author in restrict_translation_by_poster_group and locale is :xx" do |
| 56 | + before do |
| 57 | + SiteSetting.restrict_translation_by_poster_group = "#{post_user_group.id}" |
| 58 | + I18n.stubs(:locale).returns(:pt) |
78 | 59 | end |
79 | 60 |
|
80 | | - it "adds post id to redis if detected_language is blank" do |
81 | | - post.custom_fields["detected_language"] = nil |
82 | | - post.save_custom_fields |
83 | | - |
84 | | - expect { serializer.can_translate }.to change { |
85 | | - Discourse.redis.sismember(DiscourseTranslator::LANG_DETECT_NEEDED, post.id) |
86 | | - }.from(false).to(true) |
| 61 | + it "cannot translate when post does not have DETECTED_LANG_CUSTOM_FIELD" do |
| 62 | + expect(serializer.can_translate).to eq(false) |
87 | 63 | end |
88 | | - end |
89 | 64 |
|
90 | | - describe "when post has DETECTED_LANG_CUSTOM_FIELD matches user locale" do |
91 | | - before do |
92 | | - I18n.stubs(:locale).returns(:xx) |
93 | | - post.custom_fields[DiscourseTranslator::DETECTED_LANG_CUSTOM_FIELD] = "xx" |
| 65 | + it "cannot translate when post has DETECTED_LANG_CUSTOM_FIELD matches locale" do |
| 66 | + post.custom_fields[DiscourseTranslator::DETECTED_LANG_CUSTOM_FIELD] = "pt" |
94 | 67 | post.save |
95 | | - end |
96 | 68 |
|
97 | | - it { expect(serializer.can_translate).to eq(false) } |
98 | | - end |
| 69 | + expect(serializer.can_translate).to eq(false) |
| 70 | + end |
99 | 71 |
|
100 | | - describe "when post has DETECTED_LANG_CUSTOM_FIELD does not match user locale" do |
101 | | - before do |
| 72 | + it "can translate when post has DETECTED_LANG_CUSTOM_FIELD does not match locale" do |
102 | 73 | post.custom_fields[DiscourseTranslator::DETECTED_LANG_CUSTOM_FIELD] = "jp" |
103 | 74 | post.save |
104 | | - end |
105 | 75 |
|
106 | | - it { expect(serializer.can_translate).to eq(true) } |
| 76 | + expect(serializer.can_translate).to eq(true) |
| 77 | + end |
107 | 78 | end |
108 | 79 | end |
109 | 80 | end |
|
0 commit comments