Add total_commentaire in API Dossier and total_dossier on API Procedure
This commit is contained in:
parent
4e6d153893
commit
21a18a536f
7 changed files with 30 additions and 3 deletions
|
@ -202,4 +202,8 @@ class Dossier < ActiveRecord::Base
|
|||
def total_follow
|
||||
follows.size
|
||||
end
|
||||
|
||||
def total_commentaire
|
||||
self.commentaires.size
|
||||
end
|
||||
end
|
||||
|
|
|
@ -85,4 +85,7 @@ class Procedure < ActiveRecord::Base
|
|||
self.update_attributes!({ archived: true })
|
||||
end
|
||||
|
||||
def total_dossier
|
||||
self.dossiers.where.not(state: :draft).size
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,8 @@ class DossierSerializer < ActiveModel::Serializer
|
|||
:updated_at,
|
||||
:archived,
|
||||
:mandataire_social,
|
||||
:state
|
||||
:state,
|
||||
:total_commentaire
|
||||
|
||||
has_one :entreprise
|
||||
has_one :etablissement
|
||||
|
|
|
@ -7,7 +7,8 @@ class ProcedureSerializer < ActiveModel::Serializer
|
|||
:organisation,
|
||||
:direction,
|
||||
:archived,
|
||||
:geographic_information
|
||||
:geographic_information,
|
||||
:total_dossier
|
||||
|
||||
|
||||
has_one :geographic_information, serializer: ModuleApiCartoSerializer
|
||||
|
|
|
@ -115,7 +115,7 @@ describe API::V1::DossiersController do
|
|||
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } }
|
||||
let(:dossier_id) { dossier.id }
|
||||
let(:body) { JSON.parse(retour.body, symbolize_names: true) }
|
||||
let(:field_list) { [:id, :created_at, :updated_at, :archived, :mandataire_social, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :commentaires, :state] }
|
||||
let(:field_list) { [:id, :created_at, :updated_at, :archived, :mandataire_social, :total_commentaire, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :commentaires, :state] }
|
||||
subject { body[:dossier] }
|
||||
|
||||
it 'return REST code 200', :show_in_doc do
|
||||
|
@ -127,6 +127,7 @@ describe API::V1::DossiersController do
|
|||
it { expect(subject[:updated_at]).to eq('2008-09-01T08:05:00.000Z') }
|
||||
it { expect(subject[:archived]).to eq(dossier.archived) }
|
||||
it { expect(subject[:mandataire_social]).to eq(dossier.mandataire_social) }
|
||||
it { expect(subject[:total_commentaire]).to eq(dossier.total_commentaire) }
|
||||
|
||||
it { expect(subject.keys).to match_array(field_list) }
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ describe API::V1::ProceduresController do
|
|||
it { expect(subject[:direction]).to eq(procedure.direction) }
|
||||
it { expect(subject[:link]).to eq(procedure.lien_demarche) }
|
||||
it { expect(subject[:archived]).to eq(procedure.archived) }
|
||||
it { expect(subject[:total_dossier]).to eq(procedure.total_dossier) }
|
||||
it { is_expected.to have_key(:types_de_champ) }
|
||||
it { expect(subject[:types_de_champ]).to be_an(Array) }
|
||||
describe 'type_de_champ' do
|
||||
|
|
|
@ -200,4 +200,20 @@ describe Procedure do
|
|||
expect(ProcedurePath.find_by_procedure_id(procedure.id)).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'total_dossier' do
|
||||
|
||||
let(:procedure) { create :procedure }
|
||||
|
||||
before do
|
||||
create :dossier, procedure: procedure, state: :initiated
|
||||
create :dossier, procedure: procedure, state: :draft
|
||||
create :dossier, procedure: procedure, state: :replied
|
||||
end
|
||||
|
||||
subject { procedure.total_dossier }
|
||||
|
||||
it { is_expected.to eq 2 }
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue