diff --git a/lib/remote_translations/caller.rb b/lib/remote_translations/caller.rb index 3b069a4e9..ecc5e4743 100644 --- a/lib/remote_translations/caller.rb +++ b/lib/remote_translations/caller.rb @@ -40,7 +40,7 @@ class RemoteTranslations::Caller def fields_values resource.translated_attribute_names.map do |field| - resource.send(field) + WYSIWYGSanitizer.new.sanitize(resource.send(field)) end end diff --git a/spec/lib/remote_translations/caller_spec.rb b/spec/lib/remote_translations/caller_spec.rb index 3b7818219..c0f137b11 100644 --- a/spec/lib/remote_translations/caller_spec.rb +++ b/spec/lib/remote_translations/caller_spec.rb @@ -9,9 +9,9 @@ describe RemoteTranslations::Caller do RemoteTranslation.set_callback(:create, :after, :enqueue_remote_translation) end - describe "#call" do - let(:client) { RemoteTranslations::Microsoft::Client } + let(:client) { RemoteTranslations::Microsoft::Client } + describe "#call" do context "Debates" do let(:debate) { create(:debate) } let(:remote_translation) do @@ -206,4 +206,24 @@ describe RemoteTranslations::Caller do end end end + + describe "#field values" do + let!(:proposal) { create(:proposal, description: "Σ with sample text") } + let(:remote_translation) do + create(:remote_translation, remote_translatable: proposal, locale: :es) + end + let(:caller) { RemoteTranslations::Caller.new(remote_translation) } + + it "sanitize field value when the field contains entity references as Σ" do + field_values_sanitized = [proposal.title, "Σ with sample text", proposal.summary, + proposal.retired_reason] + locale = remote_translation.locale + fake_response = ["translated title", "translated description", "translated summary", nil] + + expect_any_instance_of(client).to receive(:call).with(field_values_sanitized, locale). + and_return(fake_response) + + caller.call + end + end end