select_multiple: clean user input

This commit is contained in:
Simon Lehericey 2017-03-15 17:50:10 +01:00
parent 1fa1e9e8e8
commit 2f561a9cd0
2 changed files with 41 additions and 1 deletions

View file

@ -12,8 +12,18 @@ class TypesDeChampService
if param_second[:libelle].empty?
parameters[attributes].delete(param_first.to_s)
end
if param_second['drop_down_list_attributes'] && param_second['drop_down_list_attributes']['value']
param_second['drop_down_list_attributes']['value'] = self.clean_value (param_second['drop_down_list_attributes']['value'])
end
end
parameters
end
end
private
def self.clean_value value
value.split("\r\n").map{ |v| v.strip }.join("\r\n")
end
end

View file

@ -0,0 +1,30 @@
require 'spec_helper'
describe TypesDeChampService do
let(:params) do
ActionController::Parameters.new({
procedure: {
types_de_champ_attributes: {
"0" => {
libelle: 'top',
drop_down_list_attributes: {
value: "un\r\n deux\r\n -- commentaire --\r\n trois",
id: '5218'
}
}
}
}
})
end
let(:result) { TypesDeChampService.create_update_procedure_params(params) }
describe 'self.create_update_procedure_params' do
describe 'the drop down list attributes' do
subject { result['types_de_champ_attributes']['0']['drop_down_list_attributes'] }
it 'has its value stripped' do
expect(subject['value']).to eq("un\r\ndeux\r\n-- commentaire --\r\ntrois")
end
end
end
end