Add RemoteTranslationsCaller to new namespace

- Rename to Caller
 - Add to new namespace RemoteTranslations
 - Update references to new namespace
This commit is contained in:
taitus
2019-05-24 15:32:10 +02:00
committed by voodoorai2000
parent 510307b0bd
commit 1d3dd6f727
3 changed files with 23 additions and 23 deletions

View File

@@ -9,7 +9,7 @@ class RemoteTranslation < ApplicationRecord
after_create :enqueue_remote_translation after_create :enqueue_remote_translation
def enqueue_remote_translation def enqueue_remote_translation
RemoteTranslationsCaller.new(self).delay.call RemoteTranslations::Caller.new(self).delay.call
end end
def self.remote_translation_enqueued?(remote_translation) def self.remote_translation_enqueued?(remote_translation)

View File

@@ -1,4 +1,4 @@
class RemoteTranslationsCaller class RemoteTranslations::Caller
attr_reader :remote_translation attr_reader :remote_translation
def initialize(remote_translation) def initialize(remote_translation)

View File

@@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
describe RemoteTranslationsCaller do describe RemoteTranslations::Caller do
before do before do
RemoteTranslation.skip_callback(:create, :after, :enqueue_remote_translation) RemoteTranslation.skip_callback(:create, :after, :enqueue_remote_translation)
@@ -17,13 +17,13 @@ describe RemoteTranslationsCaller do
let(:debate) { create(:debate) } let(:debate) { create(:debate) }
let(:remote_translation) { create(:remote_translation, let(:remote_translation) { create(:remote_translation,
remote_translatable: debate, locale: :es) } remote_translatable: debate, locale: :es) }
let(:remote_translation_caller) { described_class.new(remote_translation) } let(:caller) { described_class.new(remote_translation) }
it "returns the resource with new translation persisted" do it "returns the resource with new translation persisted" do
response = ["Título traducido", "Descripción traducida"] response = ["Título traducido", "Descripción traducida"]
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
remote_translation_caller.call caller.call
expect(debate.translations.count).to eq(2) expect(debate.translations.count).to eq(2)
end end
@@ -32,7 +32,7 @@ describe RemoteTranslationsCaller do
response = ["TT", "Descripción traducida"] response = ["TT", "Descripción traducida"]
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
remote_translation_caller.call caller.call
expect(remote_translation.error_message).to eq nil expect(remote_translation.error_message).to eq nil
expect(debate.translations.count).to eq(2) expect(debate.translations.count).to eq(2)
@@ -43,7 +43,7 @@ describe RemoteTranslationsCaller do
response = ["", "Descripción traducida"] response = ["", "Descripción traducida"]
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
remote_translation_caller.call caller.call
expect(remote_translation.error_message).to include("can't be blank") expect(remote_translation.error_message).to include("can't be blank")
expect(debate.translations.count).to eq(1) expect(debate.translations.count).to eq(1)
@@ -54,7 +54,7 @@ describe RemoteTranslationsCaller do
response = ["Título traducido", "Descripción traducida"] response = ["Título traducido", "Descripción traducida"]
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
remote_translation_caller.call caller.call
expect(RemoteTranslation.count).to eq(0) expect(RemoteTranslation.count).to eq(0)
end end
@@ -65,14 +65,14 @@ describe RemoteTranslationsCaller do
let!(:proposal) { create(:proposal) } let!(:proposal) { create(:proposal) }
let(:remote_translation) { create(:remote_translation, let(:remote_translation) { create(:remote_translation,
remote_translatable: proposal, locale: :es) } remote_translatable: proposal, locale: :es) }
let(:remote_translation_caller) { described_class.new(remote_translation) } let(:caller) { described_class.new(remote_translation) }
it "returns the resource with new translation persisted" do it "returns the resource with new translation persisted" do
response = ["Título traducido", "Descripción traducida", "Pregunta traducida", response = ["Título traducido", "Descripción traducida", "Pregunta traducida",
"Resumen traducido", nil] "Resumen traducido", nil]
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
remote_translation_caller.call caller.call
expect(proposal.translations.count).to eq(2) expect(proposal.translations.count).to eq(2)
end end
@@ -81,7 +81,7 @@ describe RemoteTranslationsCaller do
response = ["TT", "Descripción traducida", "Pregunta traducida", "Resumen traducido", nil] response = ["TT", "Descripción traducida", "Pregunta traducida", "Resumen traducido", nil]
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
remote_translation_caller.call caller.call
expect(remote_translation.error_message).to eq nil expect(remote_translation.error_message).to eq nil
expect(proposal.translations.count).to eq(2) expect(proposal.translations.count).to eq(2)
@@ -92,7 +92,7 @@ describe RemoteTranslationsCaller do
response = ["", "Descripción traducida", "Pregunta traducida", "Resumen traducido", nil] response = ["", "Descripción traducida", "Pregunta traducida", "Resumen traducido", nil]
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
remote_translation_caller.call caller.call
expect(remote_translation.error_message).to include("can't be blank") expect(remote_translation.error_message).to include("can't be blank")
expect(proposal.translations.count).to eq(1) expect(proposal.translations.count).to eq(1)
@@ -104,7 +104,7 @@ describe RemoteTranslationsCaller do
"Resumen traducido", nil] "Resumen traducido", nil]
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
remote_translation_caller.call caller.call
expect(RemoteTranslation.count).to eq(0) expect(RemoteTranslation.count).to eq(0)
end end
@@ -116,13 +116,13 @@ describe RemoteTranslationsCaller do
let(:remote_translation) { create(:remote_translation, let(:remote_translation) { create(:remote_translation,
remote_translatable: budget_investment, remote_translatable: budget_investment,
locale: :es) } locale: :es) }
let(:remote_translation_caller) { described_class.new(remote_translation) } let(:caller) { described_class.new(remote_translation) }
it "returns the resource with new translation persisted" do it "returns the resource with new translation persisted" do
response = ["Título traducido", "Descripción traducida"] response = ["Título traducido", "Descripción traducida"]
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
remote_translation_caller.call caller.call
expect(budget_investment.translations.count).to eq(2) expect(budget_investment.translations.count).to eq(2)
end end
@@ -131,7 +131,7 @@ describe RemoteTranslationsCaller do
response = ["TT", "Descripción traducida"] response = ["TT", "Descripción traducida"]
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
remote_translation_caller.call caller.call
expect(remote_translation.error_message).to eq nil expect(remote_translation.error_message).to eq nil
expect(budget_investment.translations.count).to eq(2) expect(budget_investment.translations.count).to eq(2)
@@ -142,7 +142,7 @@ describe RemoteTranslationsCaller do
response = ["", "Descripción traducida"] response = ["", "Descripción traducida"]
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
remote_translation_caller.call caller.call
expect(remote_translation.error_message).to include("can't be blank") expect(remote_translation.error_message).to include("can't be blank")
expect(budget_investment.translations.count).to eq(1) expect(budget_investment.translations.count).to eq(1)
@@ -153,7 +153,7 @@ describe RemoteTranslationsCaller do
response = ["Título traducido", "Descripción traducida"] response = ["Título traducido", "Descripción traducida"]
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
remote_translation_caller.call caller.call
expect(RemoteTranslation.count).to eq(0) expect(RemoteTranslation.count).to eq(0)
end end
@@ -164,13 +164,13 @@ describe RemoteTranslationsCaller do
let(:comment) { create(:comment) } let(:comment) { create(:comment) }
let(:remote_translation) { create(:remote_translation, let(:remote_translation) { create(:remote_translation,
remote_translatable: comment, locale: :es) } remote_translatable: comment, locale: :es) }
let(:remote_translation_caller) { described_class.new(remote_translation) } let(:caller) { described_class.new(remote_translation) }
it "returns the resource with new translation persisted" do it "returns the resource with new translation persisted" do
response = ["Body traducido"] response = ["Body traducido"]
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
remote_translation_caller.call caller.call
expect(comment.translations.count).to eq(2) expect(comment.translations.count).to eq(2)
end end
@@ -179,7 +179,7 @@ describe RemoteTranslationsCaller do
response = ["BT"] response = ["BT"]
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
remote_translation_caller.call caller.call
expect(remote_translation.error_message).to eq nil expect(remote_translation.error_message).to eq nil
expect(comment.translations.count).to eq(2) expect(comment.translations.count).to eq(2)
@@ -190,7 +190,7 @@ describe RemoteTranslationsCaller do
response = [""] response = [""]
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
remote_translation_caller.call caller.call
expect(remote_translation.error_message).to include("can't be blank") expect(remote_translation.error_message).to include("can't be blank")
expect(comment.translations.count).to eq(1) expect(comment.translations.count).to eq(1)
@@ -201,7 +201,7 @@ describe RemoteTranslationsCaller do
response = ["Body traducido"] response = ["Body traducido"]
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response) expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(response)
remote_translation_caller.call caller.call
expect(RemoteTranslation.count).to eq(0) expect(RemoteTranslation.count).to eq(0)
end end