Sanitize resource fields values

Sanitize resource fields values from ddbb before send
to remote translate client.
This commit is contained in:
taitus
2019-12-03 19:21:11 +01:00
parent 11adacfdb9
commit d1c9df5f91
2 changed files with 23 additions and 3 deletions

View File

@@ -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

View File

@@ -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 }
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