Fix found Hound violations

This commit is contained in:
taitus
2019-04-23 16:56:18 +02:00
committed by voodoorai2000
parent abb81fccf4
commit d2506358ef
6 changed files with 73 additions and 67 deletions

View File

@@ -11,9 +11,9 @@ module RemotelyTranslatable
end
def remote_translation_for(resource)
{ 'remote_translatable_id' => resource.id.to_s,
'remote_translatable_type' => resource.class.to_s,
'locale' => I18n.locale }
{ "remote_translatable_id" => resource.id.to_s,
"remote_translatable_type" => resource.class.to_s,
"locale" => I18n.locale }
end
def translation_empty?(resource)

View File

@@ -8,25 +8,27 @@ class RemoteTranslationsController < ApplicationController
@remote_translations.each do |remote_translation|
RemoteTranslation.create(remote_translation) unless translations_enqueued?(remote_translation)
end
redirect_to request.referer, notice: t('remote_translations.create.enqueue_remote_translation')
redirect_to request.referer, notice: t("remote_translations.create.enqueue_remote_translation")
end
private
def remote_translations_params
params.permit(:remote_translations)
end
def remote_translations_params
params.permit(:remote_translations)
end
def set_remote_translations
decoded_remote_translations = ActiveSupport::JSON.decode(remote_translations_params["remote_translations"])
@remote_translations = decoded_remote_translations.map{ |remote_translation|
remote_translation.slice("remote_translatable_id","remote_translatable_type","locale")
}
end
def set_remote_translations
remote_translations = remote_translations_params["remote_translations"]
decoded_remote_translations = ActiveSupport::JSON.decode(remote_translations)
@remote_translations = decoded_remote_translations.map{ |remote_translation|
remote_translation.slice("remote_translatable_id",
"remote_translatable_type",
"locale")
}
end
def translations_enqueued?(remote_translation)
RemoteTranslation.remote_translation_enqueued?(remote_translation)
end
def translations_enqueued?(remote_translation)
RemoteTranslation.remote_translation_enqueued?(remote_translation)
end
end

View File

@@ -27,6 +27,7 @@ class RemoteTranslationsCaller
else
remote_translation.update(error_message: resource.errors.messages)
end
resource.save
end
def resource

View File

@@ -3,11 +3,12 @@ require "rails_helper"
describe RemoteTranslationsController do
describe "POST create" do
let(:debate) { create(:debate) }
before do
@debate = create(:debate)
@remote_translations_params = [{ remote_translatable_id: @debate.id.to_s,
remote_translatable_type: @debate.class.to_s,
locale: :es }].to_json
@remote_translations_params = [{ remote_translatable_id: debate.id.to_s,
remote_translatable_type: debate.class.to_s,
locale: :es }].to_json
allow(controller.request).to receive(:referer).and_return("any_path")
Delayed::Worker.delay_jobs = true
end
@@ -23,7 +24,7 @@ describe RemoteTranslationsController do
end
it "create remote translation when same remote translation with error_message is enqueued" do
create(:remote_translation, remote_translatable: @debate, locale: :es, error_message: "Has errors")
create(:remote_translation, remote_translatable: debate, locale: :es, error_message: "Has errors")
post :create, remote_translations: @remote_translations_params
@@ -31,7 +32,7 @@ describe RemoteTranslationsController do
end
it "not create remote translation when same remote translation is enqueued" do
create(:remote_translation, remote_translatable: @debate, locale: :es)
create(:remote_translation, remote_translatable: debate, locale: :es)
post :create, remote_translations: @remote_translations_params

View File

@@ -1,4 +1,4 @@
require 'rails_helper'
require "rails_helper"
describe RemoteTranslationsCaller do
@@ -6,18 +6,18 @@ describe RemoteTranslationsCaller do
RemoteTranslation.skip_callback(:create, :after, :enqueue_remote_translation)
end
describe '#call' do
describe "#call" do
context 'Debates' do
context "Debates" do
let(:debate) { create(:debate) }
let(:remote_translation) { create(:remote_translation,
remote_translatable: debate, locale: :es) }
let(:remote_translation_caller) { described_class.new(remote_translation) }
it 'returns the resource with new translation persisted' do
microsoft_translate_client_response = ["Título traducido", "Descripción traducida"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(microsoft_translate_client_response)
it "returns the resource with new translation persisted" do
response = ["Título traducido", "Descripción traducida"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(response)
remote_translation_caller.call
@@ -25,8 +25,8 @@ describe RemoteTranslationsCaller do
end
it "when new translation locale is distinct to default_locale skip length validations" do
microsoft_translate_client_response = ["TT", "Descripción traducida"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(microsoft_translate_client_response)
response = ["TT", "Descripción traducida"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(response)
remote_translation_caller.call
@@ -36,8 +36,8 @@ describe RemoteTranslationsCaller do
end
it "when new translation locale is distinct to default_locale not skip presence validations" do
microsoft_translate_client_response = ["", "Descripción traducida"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(microsoft_translate_client_response)
response = ["", "Descripción traducida"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(response)
remote_translation_caller.call
@@ -47,8 +47,8 @@ describe RemoteTranslationsCaller do
end
it "destroy remote translation instance" do
microsoft_translate_client_response = ["Título traducido", "Descripción traducida"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(microsoft_translate_client_response)
response = ["Título traducido", "Descripción traducida"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(response)
remote_translation_caller.call
@@ -56,16 +56,17 @@ describe RemoteTranslationsCaller do
end
end
context 'Proposals' do
context "Proposals" do
let!(:proposal) { create(:proposal) }
let(:remote_translation) { create(:remote_translation,
remote_translatable: proposal, locale: :es) }
let(:remote_translation_caller) { described_class.new(remote_translation) }
it 'returns the resource with new translation persisted' do
microsoft_translate_client_response = ["Título traducido", "Descripción traducida", "Pregunta traducida", "Resumen traducido", nil]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(microsoft_translate_client_response)
it "returns the resource with new translation persisted" do
response = ["Título traducido", "Descripción traducida", "Pregunta traducida",
"Resumen traducido", nil]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(response)
remote_translation_caller.call
@@ -73,8 +74,8 @@ describe RemoteTranslationsCaller do
end
it "when new translation locale is distinct to default_locale skip lenght validations" do
microsoft_translate_client_response = ["TT", "Descripción traducida", "Pregunta traducida", "Resumen traducido", nil]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(microsoft_translate_client_response)
response = ["TT", "Descripción traducida", "Pregunta traducida", "Resumen traducido", nil]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(response)
remote_translation_caller.call
@@ -84,8 +85,8 @@ describe RemoteTranslationsCaller do
end
it "when new translation locale is distinct to default_locale do not skip presence validations" do
microsoft_translate_client_response = ["", "Descripción traducida", "Pregunta traducida", "Resumen traducido", nil]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(microsoft_translate_client_response)
response = ["", "Descripción traducida", "Pregunta traducida", "Resumen traducido", nil]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(response)
remote_translation_caller.call
@@ -95,8 +96,9 @@ describe RemoteTranslationsCaller do
end
it "destroy remote translation instance" do
microsoft_translate_client_response = ["Título traducido", "Descripción traducida", "Pregunta traducida", "Resumen traducido", nil]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(microsoft_translate_client_response)
response = ["Título traducido", "Descripción traducida", "Pregunta traducida",
"Resumen traducido", nil]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(response)
remote_translation_caller.call
@@ -104,7 +106,7 @@ describe RemoteTranslationsCaller do
end
end
context 'Budget Investments' do
context "Budget Investments" do
let(:budget_investment) { create(:budget_investment) }
let(:remote_translation) { create(:remote_translation,
@@ -112,9 +114,9 @@ describe RemoteTranslationsCaller do
locale: :es) }
let(:remote_translation_caller) { described_class.new(remote_translation) }
it 'returns the resource with new translation persisted' do
microsoft_translate_client_response = ["Título traducido", "Descripción traducida"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(microsoft_translate_client_response)
it "returns the resource with new translation persisted" do
response = ["Título traducido", "Descripción traducida"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(response)
remote_translation_caller.call
@@ -122,8 +124,8 @@ describe RemoteTranslationsCaller do
end
it "when new translation locale is distinct to default_locale skip lenght validations" do
microsoft_translate_client_response = ["TT", "Descripción traducida"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(microsoft_translate_client_response)
response = ["TT", "Descripción traducida"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(response)
remote_translation_caller.call
@@ -133,8 +135,8 @@ describe RemoteTranslationsCaller do
end
it "when new translation locale is distinct to default_locale not skip presence validations" do
microsoft_translate_client_response = ["", "Descripción traducida"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(microsoft_translate_client_response)
response = ["", "Descripción traducida"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(response)
remote_translation_caller.call
@@ -144,8 +146,8 @@ describe RemoteTranslationsCaller do
end
it "destroy remote translation instance" do
microsoft_translate_client_response = ["Título traducido", "Descripción traducida"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(microsoft_translate_client_response)
response = ["Título traducido", "Descripción traducida"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(response)
remote_translation_caller.call
@@ -153,16 +155,16 @@ describe RemoteTranslationsCaller do
end
end
context 'Comments' do
context "Comments" do
let(:comment) { create(:comment) }
let(:remote_translation) { create(:remote_translation,
remote_translatable: comment, locale: :es) }
let(:remote_translation_caller) { described_class.new(remote_translation) }
it 'returns the resource with new translation persisted' do
microsoft_translate_client_response = ["Body traducido"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(microsoft_translate_client_response)
it "returns the resource with new translation persisted" do
response = ["Body traducido"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(response)
remote_translation_caller.call
@@ -170,8 +172,8 @@ describe RemoteTranslationsCaller do
end
it "when new translation locale is distinct to default_locale skip lenght validations" do
microsoft_translate_client_response = ["BT"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(microsoft_translate_client_response)
response = ["BT"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(response)
remote_translation_caller.call
@@ -181,8 +183,8 @@ describe RemoteTranslationsCaller do
end
it "when new translation locale is distinct to default_locale not skip presence validations" do
microsoft_translate_client_response = [""]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(microsoft_translate_client_response)
response = [""]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(response)
remote_translation_caller.call
@@ -192,8 +194,8 @@ describe RemoteTranslationsCaller do
end
it "destroy remote translation instance" do
microsoft_translate_client_response = ["Body traducido"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(microsoft_translate_client_response)
response = ["Body traducido"]
expect_any_instance_of(MicrosoftTranslateClient).to receive(:call).and_return(response)
remote_translation_caller.call

View File

@@ -28,9 +28,9 @@ describe RemoteTranslation do
expect(remote_translation).not_to be_valid
end
describe '#enqueue_remote_translation' do
describe "#enqueue_remote_translation" do
it 'after create enqueue Delayed Job' do
it "after create enqueue Delayed Job" do
Delayed::Worker.delay_jobs = true
expect { remote_translation.save }.to change { Delayed::Job.count }.by(1)