add exportables_pieces_jointes_for_all_versions and outdated to pj_list_concern
This commit is contained in:
parent
106698a242
commit
24109a0128
2 changed files with 79 additions and 39 deletions
|
@ -11,14 +11,26 @@ module PiecesJointesListConcern
|
||||||
pieces_jointes(exclude_titre_identite: true)
|
pieces_jointes(exclude_titre_identite: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def exportables_pieces_jointes_for_all_versions
|
||||||
|
pieces_jointes(
|
||||||
|
exclude_titre_identite: true,
|
||||||
|
revision: revisions
|
||||||
|
).sort_by { - _1.id }.uniq(&:stable_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def outdated_exportables_pieces_jointes
|
||||||
|
exportables_pieces_jointes_for_all_versions - exportables_pieces_jointes
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def pieces_jointes(
|
def pieces_jointes(
|
||||||
exclude_titre_identite: false,
|
exclude_titre_identite: false,
|
||||||
public_only: false,
|
public_only: false,
|
||||||
wrap_with_parent: false
|
wrap_with_parent: false,
|
||||||
|
revision: active_revision
|
||||||
)
|
)
|
||||||
coordinates = active_revision.revision_types_de_champ
|
coordinates = ProcedureRevisionTypeDeChamp.where(revision:)
|
||||||
.includes(:type_de_champ, revision_types_de_champ: :type_de_champ)
|
.includes(:type_de_champ, revision_types_de_champ: :type_de_champ)
|
||||||
|
|
||||||
coordinates = coordinates.public_only if public_only
|
coordinates = coordinates.public_only if public_only
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
describe PiecesJointesListConcern do
|
describe PiecesJointesListConcern do
|
||||||
describe '#pieces_jointes_list' do
|
describe '#pieces_jointes_list' do
|
||||||
include Logic
|
include Logic
|
||||||
|
|
||||||
|
describe 'public_wrapped_partionned_pjs and exportables_pieces_jointes' do
|
||||||
let(:procedure) { create(:procedure, types_de_champ_public:, types_de_champ_private:) }
|
let(:procedure) { create(:procedure, types_de_champ_public:, types_de_champ_private:) }
|
||||||
let(:types_de_champ_public) do
|
let(:types_de_champ_public) do
|
||||||
[
|
[
|
||||||
|
@ -46,5 +48,31 @@ describe PiecesJointesListConcern do
|
||||||
it "returns the list of pieces jointes with private, without parent repetition, without titre identite" do
|
it "returns the list of pieces jointes with private, without parent repetition, without titre identite" do
|
||||||
expect(procedure.exportables_pieces_jointes.map(&:libelle)).to match_array([pj1, pj2, pjcond, pj5, pjcond2, pj6].map(&:libelle))
|
expect(procedure.exportables_pieces_jointes.map(&:libelle)).to match_array([pj1, pj2, pjcond, pj5, pjcond2, pj6].map(&:libelle))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns the same list but for all versions" do
|
||||||
|
expect(procedure.exportables_pieces_jointes.map(&:libelle)).to match_array([pj1, pj2, pjcond, pj5, pjcond2, pj6].map(&:libelle))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#outdated_exportables_pieces_jointes' do
|
||||||
|
let(:types_de_champ_public) do
|
||||||
|
[
|
||||||
|
{ type: :piece_justificative, libelle: "outdated", stable_id: 1 },
|
||||||
|
{ type: :piece_justificative, libelle: "kept", stable_id: 2 }
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:procedure) { create(:procedure, :published, types_de_champ_public:) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
procedure.draft_revision.remove_type_de_champ(1)
|
||||||
|
procedure.draft_revision.add_type_de_champ(type_champ: :piece_justificative, libelle: 'new', mandatory: false)
|
||||||
|
procedure.publish_revision!
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(procedure.exportables_pieces_jointes_for_all_versions.map(&:libelle)).to eq(["new", "kept", "outdated"]) }
|
||||||
|
it { expect(procedure.exportables_pieces_jointes.map(&:libelle)).to match_array(["kept", "new"]) }
|
||||||
|
it { expect(procedure.outdated_exportables_pieces_jointes.map(&:libelle)).to match_array(["outdated"]) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue