From 63cf35a7483e53c50cc7b9542861b9fedf46244f Mon Sep 17 00:00:00 2001 From: Guillaume Lazzara Date: Tue, 24 May 2016 15:43:05 +0200 Subject: [PATCH] Add tests for siret with whitespaces --- app/models/siret.rb | 2 +- .../controllers/users/dossiers_controller_spec.rb | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/models/siret.rb b/app/models/siret.rb index 0bac4702b..8196a223d 100644 --- a/app/models/siret.rb +++ b/app/models/siret.rb @@ -10,6 +10,6 @@ class Siret before_validation :remove_whitespace def remove_whitespace - siret.delete!(' ') + siret.delete!(' ') unless siret.nil? end end diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 35eb2d87f..7630eb94c 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -17,6 +17,7 @@ describe Users::DossiersController, type: :controller do let(:siren) { dossier.siren } let(:siret) { dossier.siret } + let(:siret_with_whitespaces) { '440 1176 2001 530' } let(:bad_siret) { 1 } describe 'GET #show' do @@ -103,12 +104,12 @@ describe Users::DossiersController, type: :controller do describe 'dossier attributs' do let(:user) { create(:user) } - context 'with valid siret ' do + shared_examples 'with valid siret' do before do sign_in user end - subject { post :create, dossier: {siret: siret, procedure_id: Procedure.last} } + subject { post :create, dossier: {siret: example_siret, procedure_id: Procedure.last} } it 'create a dossier' do expect { subject }.to change { Dossier.count }.by(1) @@ -215,6 +216,16 @@ describe Users::DossiersController, type: :controller do end end + describe "with siret without whitespaces" do + let(:example_siret) { siret } + it_should_behave_like "with valid siret" + end + + describe "with siret with whitespaces" do + let(:example_siret) { siret_with_whitespaces } + it_should_behave_like "with valid siret" + end + context 'with non existant siret' do before do sign_in create(:user)