Merge pull request #10555 from mfo/US/normalize-number-cahmp
tech: Normalisation des champs de type number/decimal pr enlever les espace blanc à la saisi
This commit is contained in:
commit
75a6c8b4b6
5 changed files with 26 additions and 44 deletions
|
@ -24,6 +24,12 @@ describe Champs::DecimalNumberChamp do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when value contain space' do
|
||||
let(:champ) { create(:champ_decimal_number, :private, value:) }
|
||||
let(:value) { ' 2.6666 ' }
|
||||
it { expect(champ.value).to eq('2.6666') }
|
||||
end
|
||||
|
||||
context 'when the value has too many decimal' do
|
||||
let(:value) { '2.6666' }
|
||||
|
||||
|
@ -65,7 +71,7 @@ describe Champs::DecimalNumberChamp do
|
|||
end
|
||||
context 'with number having spaces' do
|
||||
let(:value) { " 120 " }
|
||||
it { is_expected.to be_nil }
|
||||
it { is_expected.to eq(120) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,6 +27,16 @@ describe Champs::IntegerNumberChamp do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when the value is a number with sapces' do
|
||||
let(:value) { ' 120 ' }
|
||||
|
||||
it 'is valid and is formated' do
|
||||
is_expected.to be_truthy
|
||||
champ.save!
|
||||
expect(champ.value).to eq('120')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the value is blank' do
|
||||
let(:value) { '' }
|
||||
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
module Maintenance
|
||||
RSpec.describe FixDecimalNumberWithSpacesTask do
|
||||
describe "#process" do
|
||||
subject(:process) { described_class.process(element) }
|
||||
let(:champ) { create(:champ_decimal_number, value:) }
|
||||
let(:element) { champ }
|
||||
|
||||
context 'with nil' do
|
||||
let(:value) { 0 }
|
||||
it { expect { process }.not_to change { champ.reload.valid_value } }
|
||||
end
|
||||
context 'with simple number' do
|
||||
let(:value) { "120" }
|
||||
it { expect { process }.not_to change { champ.reload.valid_value } }
|
||||
end
|
||||
context 'with number having leading spaces' do
|
||||
let(:value) { " 120" }
|
||||
it { expect { process }.to change { champ.reload.valid_value }.from(nil).to("120") }
|
||||
end
|
||||
context 'with number having trailing spaces' do
|
||||
let(:value) { "120 " }
|
||||
it { expect { process }.to change { champ.reload.valid_value }.from(nil).to("120") }
|
||||
end
|
||||
context 'with number having leading and trailing spaces' do
|
||||
let(:value) { " 120 " }
|
||||
it { expect { process }.to change { champ.reload.valid_value }.from(nil).to("120") }
|
||||
end
|
||||
context 'with number having in between spaces' do
|
||||
let(:value) { "1 2 0" }
|
||||
it { expect { process }.to change { champ.reload.valid_value }.from(nil).to("120") }
|
||||
end
|
||||
context 'with number having in between tab' do
|
||||
let(:value) { "\t120\t" }
|
||||
it { expect { process }.to change { champ.reload.valid_value }.from(nil).to("120") }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue