select_multiple: clean user input
This commit is contained in:
parent
1fa1e9e8e8
commit
2f561a9cd0
2 changed files with 41 additions and 1 deletions
|
@ -12,8 +12,18 @@ class TypesDeChampService
|
||||||
if param_second[:libelle].empty?
|
if param_second[:libelle].empty?
|
||||||
parameters[attributes].delete(param_first.to_s)
|
parameters[attributes].delete(param_first.to_s)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
parameters
|
parameters
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def self.clean_value value
|
||||||
|
value.split("\r\n").map{ |v| v.strip }.join("\r\n")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
30
spec/services/type_de_champ_service_spec.rb
Normal file
30
spec/services/type_de_champ_service_spec.rb
Normal 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
|
Loading…
Add table
Reference in a new issue