|
128 | 128 | end |
129 | 129 |
|
130 | 130 | describe "when translator enabled" do |
131 | | - before { SiteSetting.translator_enabled = true } |
| 131 | + before do |
| 132 | + SiteSetting.translator_enabled = true |
| 133 | + I18n.locale = :pt |
| 134 | + end |
132 | 135 |
|
133 | | - describe "when experimental_topic_translation enabled" do |
134 | | - before { SiteSetting.experimental_topic_translation = true } |
| 136 | + describe "anon user" do |
| 137 | + before { SiteSetting.restrict_translation_by_group = "#{Group::AUTO_GROUPS[:everyone]}" } |
135 | 138 |
|
136 | | - describe "anon user" do |
137 | | - before { SiteSetting.restrict_translation_by_group = "#{Group::AUTO_GROUPS[:everyone]}" } |
| 139 | + it "cannot translate" do |
| 140 | + SiteSetting.experimental_topic_translation = true |
| 141 | + expect(Guardian.new.can_translate?(post)).to eq(false) |
138 | 142 |
|
139 | | - it "cannot translate" do |
140 | | - expect(Guardian.new.can_translate?(post)).to eq(false) |
141 | | - end |
| 143 | + SiteSetting.experimental_topic_translation = false |
| 144 | + expect(Guardian.new.can_translate?(post)).to eq(false) |
142 | 145 | end |
| 146 | + end |
| 147 | + |
| 148 | + it "cannot translate when post detected locale matches i18n locale" do |
| 149 | + post.set_detected_locale("pt") |
| 150 | + |
| 151 | + SiteSetting.experimental_topic_translation = true |
| 152 | + expect(guardian.can_translate?(post)).to eq(false) |
| 153 | + |
| 154 | + SiteSetting.experimental_topic_translation = false |
| 155 | + expect(guardian.can_translate?(post)).to eq(false) |
| 156 | + end |
| 157 | + |
| 158 | + describe "when experimental_topic_translation enabled" do |
| 159 | + before { SiteSetting.experimental_topic_translation = true } |
143 | 160 |
|
144 | 161 | describe "logged in user" do |
145 | 162 | it "cannot translate when user is not in restrict_translation_by_group" do |
|
151 | 168 | describe "user is in restrict_translation_by_group" do |
152 | 169 | before { SiteSetting.restrict_translation_by_group = "#{group.id}" } |
153 | 170 |
|
154 | | - describe "locale is :pt" do |
155 | | - before { I18n.stubs(:locale).returns(:pt) } |
156 | | - |
157 | | - it "cannot translate when post detected locale matches i18n locale" do |
158 | | - post.set_detected_locale("pt") |
159 | | - |
160 | | - expect(guardian.can_translate?(post)).to eq(false) |
161 | | - end |
162 | | - |
163 | | - it "can translate when post's detected locale does not match i18n locale" do |
164 | | - post.set_detected_locale("jp") |
165 | | - |
166 | | - expect(guardian.can_translate?(post)).to eq(true) |
167 | | - end |
168 | | - |
169 | | - it "cannot translate when post has translation for user locale" do |
170 | | - post.set_detected_locale("jp") |
171 | | - post.set_translation("pt", "Olá, mundo!") |
| 171 | + it "cannot translate when post has translation for user locale" do |
| 172 | + post.set_detected_locale("jp") |
| 173 | + post.set_translation("pt", "Olá, mundo!") |
172 | 174 |
|
173 | | - expect(guardian.can_translate?(post)).to eq(false) |
174 | | - end |
| 175 | + expect(guardian.can_translate?(post)).to eq(false) |
| 176 | + end |
175 | 177 |
|
176 | | - it "can translate when post does not have translation for user locale" do |
177 | | - post.set_detected_locale("jp") |
| 178 | + it "can translate when post does not have translation for user locale" do |
| 179 | + post.set_detected_locale("jp") |
178 | 180 |
|
179 | | - expect(guardian.can_translate?(post)).to eq(true) |
180 | | - end |
| 181 | + expect(guardian.can_translate?(post)).to eq(true) |
181 | 182 | end |
182 | 183 | end |
183 | 184 | end |
|
186 | 187 | describe "when experimental topic translation disabled" do |
187 | 188 | before { SiteSetting.experimental_topic_translation = false } |
188 | 189 |
|
189 | | - describe "anon user" do |
190 | | - before { SiteSetting.restrict_translation_by_group = "#{Group::AUTO_GROUPS[:everyone]}" } |
| 190 | + it "cannot translate when user is not in restrict_translation_by_group" do |
| 191 | + SiteSetting.restrict_translation_by_group = "#{group.id + 1}" |
191 | 192 |
|
192 | | - it "cannot translate" do |
193 | | - expect(Guardian.new.can_translate?(post)).to eq(false) |
194 | | - end |
| 193 | + expect(guardian.can_translate?(post)).to eq(false) |
195 | 194 | end |
196 | 195 |
|
197 | | - describe "logged in user" do |
198 | | - it "cannot translate when user is not in restrict_translation_by_group" do |
199 | | - SiteSetting.restrict_translation_by_group = "#{group.id + 1}" |
200 | | - |
201 | | - expect(guardian.can_translate?(post)).to eq(false) |
202 | | - end |
203 | | - |
204 | | - describe "user is in restrict_translation_by_group" do |
205 | | - before { SiteSetting.restrict_translation_by_group = "#{group.id}" } |
206 | | - |
207 | | - describe "locale is :pt" do |
208 | | - before { I18n.stubs(:locale).returns(:pt) } |
209 | | - |
210 | | - it "cannot translate when post detected locale matches i18n locale" do |
211 | | - post.set_detected_locale("pt") |
212 | | - |
213 | | - expect(guardian.can_translate?(post)).to eq(false) |
214 | | - end |
| 196 | + describe "user is in restrict_translation_by_group" do |
| 197 | + before { SiteSetting.restrict_translation_by_group = "#{group.id}" } |
215 | 198 |
|
216 | | - it "can translate when post's detected locale does not match i18n locale" do |
217 | | - post.set_detected_locale("jp") |
| 199 | + it "can translate when post's detected locale does not match i18n locale, regardless of translation presence" do |
| 200 | + post.set_detected_locale("jp") |
| 201 | + expect(guardian.can_translate?(post)).to eq(true) |
218 | 202 |
|
219 | | - expect(guardian.can_translate?(post)).to eq(true) |
220 | | - end |
| 203 | + post.set_translation("pt", "Olá, mundo!") |
| 204 | + expect(guardian.can_translate?(post)).to eq(true) |
| 205 | + end |
221 | 206 |
|
222 | | - it "cannot translate if poster is not in restrict_translation_by_poster_group" do |
223 | | - SiteSetting.restrict_translation_by_poster_group = "#{Group::AUTO_GROUPS[:staff]}" |
| 207 | + it "cannot translate if poster is not in restrict_translation_by_poster_group" do |
| 208 | + SiteSetting.restrict_translation_by_poster_group = "#{Group::AUTO_GROUPS[:staff]}" |
224 | 209 |
|
225 | | - expect(guardian.can_translate?(post)).to eq(false) |
226 | | - end |
| 210 | + expect(guardian.can_translate?(post)).to eq(false) |
| 211 | + end |
227 | 212 |
|
228 | | - it "can translate if poster is in restrict_translation_by_poster_group" do |
229 | | - poster = post.user |
230 | | - poster_group = Fabricate(:group, users: [poster]) |
| 213 | + it "can translate if poster is in restrict_translation_by_poster_group" do |
| 214 | + poster = post.user |
| 215 | + poster_group = Fabricate(:group, users: [poster]) |
231 | 216 |
|
232 | | - SiteSetting.restrict_translation_by_poster_group = "#{poster_group.id}" |
233 | | - expect(guardian.can_translate?(post)).to eq(true) |
| 217 | + SiteSetting.restrict_translation_by_poster_group = "#{poster_group.id}" |
| 218 | + expect(guardian.can_translate?(post)).to eq(true) |
234 | 219 |
|
235 | | - SiteSetting.restrict_translation_by_poster_group = "" |
236 | | - expect(guardian.can_translate?(post)).to eq(true) |
237 | | - end |
238 | | - end |
| 220 | + SiteSetting.restrict_translation_by_poster_group = "" |
| 221 | + expect(guardian.can_translate?(post)).to eq(true) |
239 | 222 | end |
240 | 223 | end |
241 | 224 | end |
|
0 commit comments