From 8dedf6fdca7fdc5ebe6a1dce0e65e442d8e26d74 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Tue, 24 Oct 2017 18:12:25 +0200 Subject: [PATCH] [fix #575] dossier updated_at is ... updated when children are updated --- app/models/avis.rb | 2 +- app/models/cadastre.rb | 2 +- app/models/cerfa.rb | 2 +- app/models/champ.rb | 2 +- app/models/commentaire.rb | 2 +- app/models/piece_justificative.rb | 2 +- app/models/quartier_prioritaire.rb | 2 +- spec/models/dossier_spec.rb | 58 ++++++++++++++++++++++++++++++ 8 files changed, 65 insertions(+), 7 deletions(-) diff --git a/app/models/avis.rb b/app/models/avis.rb index 9d2253a2f..c3bef4b3f 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -1,5 +1,5 @@ class Avis < ApplicationRecord - belongs_to :dossier + belongs_to :dossier, touch: true belongs_to :gestionnaire belongs_to :claimant, class_name: 'Gestionnaire' diff --git a/app/models/cadastre.rb b/app/models/cadastre.rb index 57e40f2d5..c2e318ba9 100644 --- a/app/models/cadastre.rb +++ b/app/models/cadastre.rb @@ -1,5 +1,5 @@ class Cadastre < ActiveRecord::Base - belongs_to :dossier + belongs_to :dossier, touch: true def geometry JSON.parse(read_attribute(:geometry)) diff --git a/app/models/cerfa.rb b/app/models/cerfa.rb index bfa0fda50..556d69af9 100644 --- a/app/models/cerfa.rb +++ b/app/models/cerfa.rb @@ -1,5 +1,5 @@ class Cerfa < ActiveRecord::Base - belongs_to :dossier + belongs_to :dossier, touch: true belongs_to :user mount_uploader :content, CerfaUploader diff --git a/app/models/champ.rb b/app/models/champ.rb index ea4043483..2c227d3fe 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -1,5 +1,5 @@ class Champ < ActiveRecord::Base - belongs_to :dossier + belongs_to :dossier, touch: true belongs_to :type_de_champ has_many :commentaires diff --git a/app/models/commentaire.rb b/app/models/commentaire.rb index a8c63b76e..05c3a5f08 100644 --- a/app/models/commentaire.rb +++ b/app/models/commentaire.rb @@ -1,5 +1,5 @@ class Commentaire < ActiveRecord::Base - belongs_to :dossier + belongs_to :dossier, touch: true belongs_to :champ belongs_to :piece_justificative diff --git a/app/models/piece_justificative.rb b/app/models/piece_justificative.rb index 6b08703b4..70f780aed 100644 --- a/app/models/piece_justificative.rb +++ b/app/models/piece_justificative.rb @@ -1,5 +1,5 @@ class PieceJustificative < ActiveRecord::Base - belongs_to :dossier + belongs_to :dossier, touch: true belongs_to :type_de_piece_justificative has_one :commentaire diff --git a/app/models/quartier_prioritaire.rb b/app/models/quartier_prioritaire.rb index 49b2f7fa4..c8ac1f712 100644 --- a/app/models/quartier_prioritaire.rb +++ b/app/models/quartier_prioritaire.rb @@ -1,5 +1,5 @@ class QuartierPrioritaire < ActiveRecord::Base - belongs_to :dossier + belongs_to :dossier, touch: true def geometry JSON.parse(read_attribute(:geometry)) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index fd0562648..520005f48 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -886,4 +886,62 @@ describe Dossier do it { expect(dossier.get_value('type_de_champ', @champ_public.type_de_champ.id.to_s)).to eq(dossier.champs.first.value) } it { expect(dossier.get_value('type_de_champ_private', @champ_private.type_de_champ.id.to_s)).to eq(dossier.champs_private.first.value) } end + + describe 'updated_at', focus: true do + let!(:dossier) { create(:dossier) } + let(:modif_date) { DateTime.parse('01/01/2100') } + + before { Timecop.freeze(modif_date) } + + subject do + dossier.reload + dossier.updated_at + end + + it { is_expected.not_to eq(modif_date) } + + context 'when a cerfa is modified' do + before { dossier.cerfa << create(:cerfa) } + + it { is_expected.to eq(modif_date) } + end + + context 'when a piece justificative is modified' do + before { dossier.pieces_justificatives << create(:piece_justificative, :contrat) } + + it { is_expected.to eq(modif_date) } + end + + context 'when a champ is modified' do + before { dossier.champs.first.update_attribute('value', 'yop') } + + it { is_expected.to eq(modif_date) } + end + + context 'when a quartier_prioritaire is modified' do + before { dossier.quartier_prioritaires << create(:quartier_prioritaire) } + + it { is_expected.to eq(modif_date) } + end + + context 'when a cadastre is modified' do + before { dossier.cadastres << create(:cadastre) } + + it { is_expected.to eq(modif_date) } + end + + context 'when a commentaire is modified' do + before { dossier.commentaires << create(:commentaire) } + + it { is_expected.to eq(modif_date) } + end + + context 'when an avis is modified' do + before { dossier.avis << create(:avis) } + + it { is_expected.to eq(modif_date) } + end + + after { Timecop.return } + end end