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