From f945b9ec632297eda4a07d9a410cbc654edcd447 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Mon, 1 Apr 2019 16:24:56 +0200 Subject: [PATCH] Champ Siret: Fix siret-champ save When a user enter a siret, it calls siret_controller in ajax. The champ value is stil nil, so champ.present? is false because champ.blank is redefined to focus on value. Thus the champ is not updated. --- app/controllers/champs/siret_controller.rb | 6 +++--- spec/controllers/champs/siret_controller_spec.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/champs/siret_controller.rb b/app/controllers/champs/siret_controller.rb index 763146915..4923f6585 100644 --- a/app/controllers/champs/siret_controller.rb +++ b/app/controllers/champs/siret_controller.rb @@ -13,9 +13,9 @@ class Champs::SiretController < ApplicationController etablissement = find_etablisement_with_siret if etablissement.present? @etablissement = etablissement - if @champ.present? - etablissement.champ = @champ - etablissement.save! + + if !@champ.nil? + @champ.update!(value: etablissement.siret, etablissement: etablissement) end else @champ&.update!(value: '') diff --git a/spec/controllers/champs/siret_controller_spec.rb b/spec/controllers/champs/siret_controller_spec.rb index dfacb8f36..154b3e4ca 100644 --- a/spec/controllers/champs/siret_controller_spec.rb +++ b/spec/controllers/champs/siret_controller_spec.rb @@ -6,7 +6,7 @@ describe Champs::SiretController, type: :controller do describe '#show' do let(:dossier) { create(:dossier, user: user, procedure: procedure) } - let(:champ) { create(:champ_siret, dossier: dossier) } + let(:champ) { create(:champ_siret, dossier: dossier, value: nil, etablissement: nil) } let(:params) do { champ_id: champ.id,