|
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) |
|
21 | 21 | describe "when translator enabled" do |
22 | 22 | before do |
23 | 23 | SiteSetting.translator_enabled = true |
24 | | - Jobs.run_later! |
25 | 24 | end |
26 | 25 |
|
27 | | - describe "when small action post" do |
28 | | - fab!(:small_action) |
29 | | - let(:serializer) { PostSerializer.new(small_action, scope: Guardian.new) } |
| 26 | + describe "anon user" do |
| 27 | + let(:serializer) { PostSerializer.new(post, scope: Guardian.new) } |
30 | 28 |
|
31 | | - it "cannot translate" do |
32 | | - expect(serializer.can_translate).to eq(false) |
33 | | - 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 |
| 29 | + before do |
| 30 | + SiteSetting.restrict_translation_by_group = "#{Group::AUTO_GROUPS[:everyone]}" |
| 31 | + SiteSetting.restrict_translation_by_poster_group = "" |
41 | 32 | end |
42 | | - let(:serializer) { PostSerializer.new(empty_post, scope: Guardian.new) } |
43 | 33 |
|
44 | 34 | it "cannot translate" do |
45 | 35 | expect(serializer.can_translate).to eq(false) |
|
49 | 39 | describe "logged in user" do |
50 | 40 | let(:serializer) { PostSerializer.new(post, scope: Guardian.new(user)) } |
51 | 41 |
|
52 | | - describe "when user is not in restrict_translation_by_group" do |
53 | | - it "cannot translate" do |
54 | | - SiteSetting.restrict_translation_by_group = "" |
| 42 | + it "cannot translate when user is not in restrict_translation_by_group" do |
| 43 | + SiteSetting.restrict_translation_by_group = "#{group.id + 1}" |
55 | 44 |
|
56 | | - expect(serializer.can_translate).to eq(false) |
57 | | - end |
| 45 | + expect(serializer.can_translate).to eq(false) |
58 | 46 | end |
59 | 47 |
|
60 | | - describe "when post is not in restrict_translation_by_poster_group" do |
61 | | - it "cannot translate" do |
| 48 | + describe "user is in restrict_translation_by_group" do |
| 49 | + before do |
62 | 50 | SiteSetting.restrict_translation_by_group = "#{group.id}" |
63 | | - SiteSetting.restrict_translation_by_poster_group = "" |
64 | | - |
65 | | - expect(serializer.can_translate).to eq(false) |
66 | 51 | end |
67 | | - end |
68 | 52 |
|
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}" |
| 53 | + it "cannot translate when post author is not in restrict_translation_by_poster_group" do |
| 54 | + SiteSetting.restrict_translation_by_poster_group = "#{group.id}" |
| 55 | + |
| 56 | + expect(serializer.can_translate).to eq(false) |
73 | 57 | end |
74 | 58 |
|
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) |
| 59 | + describe "post author in restrict_translation_by_poster_group and locale is :xx" do |
| 60 | + before do |
| 61 | + SiteSetting.restrict_translation_by_poster_group = "#{post_user_group.id}" |
| 62 | + I18n.stubs(:locale).returns(:pt) |
78 | 63 | end |
79 | 64 |
|
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) |
| 65 | + it "cannot translate when post does not have DETECTED_LANG_CUSTOM_FIELD" do |
| 66 | + expect(serializer.can_translate).to eq(false) |
87 | 67 | end |
88 | | - end |
89 | 68 |
|
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" |
| 69 | + it "cannot translate when post has DETECTED_LANG_CUSTOM_FIELD matches locale" do |
| 70 | + post.custom_fields[DiscourseTranslator::DETECTED_LANG_CUSTOM_FIELD] = "pt" |
94 | 71 | post.save |
95 | | - end |
96 | 72 |
|
97 | | - it { expect(serializer.can_translate).to eq(false) } |
98 | | - end |
| 73 | + expect(serializer.can_translate).to eq(false) |
| 74 | + end |
99 | 75 |
|
100 | | - describe "when post has DETECTED_LANG_CUSTOM_FIELD does not match user locale" do |
101 | | - before do |
| 76 | + it "can translate when post has DETECTED_LANG_CUSTOM_FIELD does not match locale" do |
102 | 77 | post.custom_fields[DiscourseTranslator::DETECTED_LANG_CUSTOM_FIELD] = "jp" |
103 | 78 | post.save |
104 | | - end |
105 | 79 |
|
106 | | - it { expect(serializer.can_translate).to eq(true) } |
| 80 | + expect(serializer.can_translate).to eq(true) |
| 81 | + end |
107 | 82 | end |
108 | 83 | end |
109 | 84 | end |
|
0 commit comments