Sanitize resource fields values
Sanitize resource fields values from ddbb before send to remote translate client.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user