-
Notifications
You must be signed in to change notification settings - Fork 52
FIX: Ensure old feature works with new and show translate button in correct scenarios #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,42 +130,92 @@ | |
| describe "when translator enabled" do | ||
| before { SiteSetting.translator_enabled = true } | ||
|
|
||
| describe "anon user" do | ||
| before { SiteSetting.restrict_translation_by_group = "#{Group::AUTO_GROUPS[:everyone]}" } | ||
| describe "when experimental_topic_translation enabled" do | ||
| before { SiteSetting.experimental_topic_translation = true } | ||
|
|
||
| it "cannot translate" do | ||
| expect(Guardian.new.can_translate?(post)).to eq(false) | ||
| describe "anon user" do | ||
| before { SiteSetting.restrict_translation_by_group = "#{Group::AUTO_GROUPS[:everyone]}" } | ||
|
|
||
| it "cannot translate" do | ||
| expect(Guardian.new.can_translate?(post)).to eq(false) | ||
| end | ||
| end | ||
|
|
||
| describe "logged in user" do | ||
| it "cannot translate when user is not in restrict_translation_by_group" do | ||
| SiteSetting.restrict_translation_by_group = "#{group.id + 1}" | ||
|
|
||
| expect(guardian.can_translate?(post)).to eq(false) | ||
| end | ||
|
|
||
| describe "user is in restrict_translation_by_group" do | ||
| before { SiteSetting.restrict_translation_by_group = "#{group.id}" } | ||
|
|
||
| describe "locale is :pt" do | ||
| before { I18n.stubs(:locale).returns(:pt) } | ||
|
|
||
| it "cannot translate when post detected locale matches i18n locale" do | ||
| post.set_detected_locale("pt") | ||
|
|
||
| expect(guardian.can_translate?(post)).to eq(false) | ||
| end | ||
|
|
||
| it "can translate when post's detected locale does not match i18n locale" do | ||
| post.set_detected_locale("jp") | ||
|
|
||
| expect(guardian.can_translate?(post)).to eq(true) | ||
| end | ||
|
|
||
| it "can translate when post does not have translation" do | ||
|
||
| post.set_detected_locale("jp") | ||
|
|
||
| expect(guardian.can_translate?(post)).to eq(true) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe "logged in user" do | ||
| it "cannot translate when user is not in restrict_translation_by_group" do | ||
| SiteSetting.restrict_translation_by_group = "#{group.id + 1}" | ||
| describe "when experimental topic translation disabled" do | ||
| before { SiteSetting.experimental_topic_translation = false } | ||
|
|
||
| describe "anon user" do | ||
| before { SiteSetting.restrict_translation_by_group = "#{Group::AUTO_GROUPS[:everyone]}" } | ||
|
|
||
| expect(guardian.can_translate?(post)).to eq(false) | ||
| it "cannot translate" do | ||
| expect(Guardian.new.can_translate?(post)).to eq(false) | ||
| end | ||
| end | ||
|
|
||
| describe "user is in restrict_translation_by_group" do | ||
| before { SiteSetting.restrict_translation_by_group = "#{group.id}" } | ||
| describe "logged in user" do | ||
| it "cannot translate when user is not in restrict_translation_by_group" do | ||
| SiteSetting.restrict_translation_by_group = "#{group.id + 1}" | ||
|
|
||
| describe "locale is :xx" do | ||
| before { I18n.stubs(:locale).returns(:pt) } | ||
| expect(guardian.can_translate?(post)).to eq(false) | ||
| end | ||
|
|
||
| it "cannot translate when post does not have detected locale" do | ||
| expect(post.detected_locale).to eq(nil) | ||
| expect(guardian.can_translate?(post)).to eq(false) | ||
| end | ||
| describe "user is in restrict_translation_by_group" do | ||
| before { SiteSetting.restrict_translation_by_group = "#{group.id}" } | ||
|
|
||
| it "cannot translate when post detected locale matches i18n locale" do | ||
| post.set_detected_locale("pt") | ||
| describe "locale is :pt" do | ||
| before { I18n.stubs(:locale).returns(:pt) } | ||
|
|
||
| expect(guardian.can_translate?(post)).to eq(false) | ||
| end | ||
| it "cannot translate if poster is not in restrict_translation_by_poster_group" do | ||
| SiteSetting.restrict_translation_by_poster_group = "#{Group::AUTO_GROUPS[:staff]}" | ||
|
|
||
| expect(guardian.can_translate?(post)).to eq(false) | ||
| end | ||
|
|
||
| it "can translate if poster is in restrict_translation_by_poster_group" do | ||
| poster = post.user | ||
| poster_group = Fabricate(:group, users: [poster]) | ||
|
|
||
| it "can translate when post detected locale does not match i18n locale" do | ||
| post.set_detected_locale("jp") | ||
| SiteSetting.restrict_translation_by_poster_group = "#{poster_group.id}" | ||
| expect(guardian.can_translate?(post)).to eq(true) | ||
|
|
||
| expect(guardian.can_translate?(post)).to eq(true) | ||
| SiteSetting.restrict_translation_by_poster_group = "" | ||
| expect(guardian.can_translate?(post)).to eq(true) | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.