-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add specs for proposal_published_event
- Loading branch information
1 parent
2fbbf92
commit 899f214
Showing
2 changed files
with
198 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
# frozen_string_literal: true | ||
|
||
shared_examples_for "a translated event" do | ||
context "when it is not machine machine translated" do | ||
let(:organization) { create(:organization, enable_machine_translations: false, machine_translation_display_priority: "original") } | ||
|
||
it "does not perform translation" do | ||
expect(subject.perform_translation?).to eq(false) | ||
end | ||
|
||
it "does not have a missing translation" do | ||
expect(subject.translation_missing?).to eq(false) | ||
end | ||
|
||
it "does have content available in multiple languages" do | ||
expect(subject.content_in_same_language?).to eq(false) | ||
end | ||
|
||
it "does return the original language" do | ||
expect(subject.safe_resource_text).to eq(en_version) | ||
end | ||
|
||
it "does not offer an alternate translation" do | ||
expect(subject.safe_resource_translated_text).to eq(en_version) | ||
end | ||
end | ||
|
||
context "when is machine machine translated" do | ||
let(:user) { create :user, organization: organization, locale: "ca" } | ||
|
||
around do |example| | ||
I18n.with_locale(user.locale) { example.run } | ||
end | ||
|
||
context "when priority is original" do | ||
let(:organization) { create(:organization, enable_machine_translations: true, machine_translation_display_priority: "original") } | ||
|
||
it "does perform translation" do | ||
expect(subject.perform_translation?).to eq(translatable) | ||
end | ||
|
||
it "does not have a missing translation" do | ||
expect(subject.translation_missing?).to eq(false) | ||
end | ||
|
||
it "does have content available in multiple languages" do | ||
expect(subject.content_in_same_language?).to eq(false) | ||
end | ||
|
||
it "does return the original language" do | ||
expect(subject.safe_resource_text).to eq(en_version) | ||
end | ||
|
||
it "does not offer an alternate translation" do | ||
expect(subject.safe_resource_translated_text).to eq(machine_translated) | ||
end | ||
|
||
context "when translation is not available" do | ||
let(:body) { { en: en_body } } | ||
|
||
it "does perform translation" do | ||
expect(subject.perform_translation?).to eq(translatable) | ||
end | ||
|
||
it "does have a missing translation" do | ||
expect(subject.translation_missing?).to eq(translatable) | ||
end | ||
|
||
it "does have content available in multiple languages" do | ||
expect(subject.content_in_same_language?).to eq(false) | ||
end | ||
|
||
it "does return the original language" do | ||
expect(subject.safe_resource_text).to eq(en_version) | ||
end | ||
|
||
it "does not offer an alternate translation" do | ||
expect(subject.safe_resource_translated_text).to eq(en_version) | ||
end | ||
end | ||
end | ||
|
||
context "when priority is translation" do | ||
let(:organization) { create(:organization, enable_machine_translations: true, machine_translation_display_priority: "translation") } | ||
|
||
it "does perform translation" do | ||
expect(subject.perform_translation?).to eq(translatable) | ||
end | ||
|
||
it "does not have a missing translation" do | ||
expect(subject.translation_missing?).to eq(false) | ||
end | ||
|
||
it "does have content available in multiple languages" do | ||
expect(subject.content_in_same_language?).to eq(false) | ||
end | ||
|
||
it "does return the original language" do | ||
expect(subject.safe_resource_text).to eq(en_version) | ||
end | ||
|
||
it "does not offer an alternate translation" do | ||
expect(subject.safe_resource_translated_text).to eq(machine_translated) | ||
end | ||
|
||
context "when translation is not available" do | ||
let(:body) { { en: en_body } } | ||
|
||
it "does perform translation" do | ||
expect(subject.perform_translation?).to eq(translatable) | ||
end | ||
|
||
it "does have a missing translation" do | ||
expect(subject.translation_missing?).to eq(translatable) | ||
end | ||
|
||
it "does have content available in multiple languages" do | ||
expect(subject.content_in_same_language?).to eq(false) | ||
end | ||
|
||
it "does return the original language" do | ||
expect(subject.safe_resource_text).to eq(en_version) | ||
end | ||
|
||
it "does not offer an alternate translation" do | ||
expect(subject.safe_resource_translated_text).to eq(en_version) | ||
end | ||
end | ||
end | ||
end | ||
end |