2019-06-24-01 (#3989)

2019-06-24-01
This commit is contained in:
Pierre de La Morinerie 2019-06-24 17:02:44 +02:00 committed by GitHub
commit f20739bbe4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 50 additions and 6 deletions

View file

@ -2,6 +2,7 @@ class API::V1::DossiersController < APIController
before_action :fetch_procedure_and_check_token before_action :fetch_procedure_and_check_token
DEFAULT_PAGE_SIZE = 100 DEFAULT_PAGE_SIZE = 100
ORDER_DIRECTIONS = { 'asc' => :asc, 'desc' => :desc }
def index def index
dossiers = @dossiers.page(params[:page]).per(per_page) dossiers = @dossiers.page(params[:page]).per(per_page)
@ -45,7 +46,8 @@ class API::V1::DossiersController < APIController
render json: {}, status: :unauthorized render json: {}, status: :unauthorized
end end
@dossiers = @procedure.dossiers.state_not_brouillon.order_for_api order = ORDER_DIRECTIONS.fetch(params[:order], :asc)
@dossiers = @procedure.dossiers.state_not_brouillon.order_for_api(order)
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
render json: {}, status: :not_found render json: {}, status: :not_found

View file

@ -1,4 +1,5 @@
class ApplicationMailer < ActionMailer::Base class ApplicationMailer < ActionMailer::Base
helper :application # gives access to all helpers defined within `application_helper`.
default from: "demarches-simplifiees.fr <#{CONTACT_EMAIL}>" default from: "demarches-simplifiees.fr <#{CONTACT_EMAIL}>"
layout 'mailer' layout 'mailer'
end end

View file

@ -85,8 +85,10 @@ class PieceJustificativeToChampPieceJointeMigrationService
) )
else else
champ.update_columns( champ.update_columns(
updated_at: dossier.updated_at, created_at: dossier.created_at,
created_at: dossier.created_at # Set an updated_at date that won't cause notifications to appear
# on gestionnaires' dashboard.
updated_at: dossier.created_at
) )
end end

View file

@ -0,0 +1,21 @@
namespace :after_party do
desc 'Deployment task: purge_unattached_piece_justificative'
task purge_unattached_piece_justificative: :environment do
puts "Running deploy task 'purge_unattached_piece_justificative'"
piece_justificatives = PieceJustificative.where(type_de_piece_justificative_id: nil)
progress = ProgressReport.new(piece_justificatives.count)
piece_justificatives.find_each do |pj|
# detach from dossier to ensure we do not trigger touch
pj.update_column(:dossier_id, nil)
pj.remove_content!
pj.destroy
progress.inc
end
progress.finish
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord.create version: '20190521131030'
end
end

View file

@ -24,7 +24,8 @@ describe API::V1::DossiersController do
end end
describe 'GET index' do describe 'GET index' do
let(:retour) { get :index, params: { token: token, procedure_id: procedure_id } } let(:order) { nil }
let(:retour) { get :index, params: { token: token, procedure_id: procedure_id, order: order }.compact }
subject { retour } subject { retour }
@ -80,6 +81,23 @@ describe API::V1::DossiersController do
it { expect(subject[:state]).to eq("initiated") } it { expect(subject[:state]).to eq("initiated") }
it { expect(subject.keys.size).to eq(4) } it { expect(subject.keys.size).to eq(4) }
end end
describe 'order' do
let!(:dossier1) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_construction)) }
let!(:dossier2) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_construction)) }
context 'asc' do
let(:order) { 'asc' }
it { expect(subject.map { |dossier| dossier[:id] }).to eq([dossier.id, dossier1.id, dossier2.id]) }
end
context 'desc' do
let(:order) { 'desc' }
it { expect(subject.map { |dossier| dossier[:id] }).to eq([dossier2.id, dossier1.id, dossier.id]) }
end
end
end end
context 'when there are multiple pages' do context 'when there are multiple pages' do

View file

@ -113,9 +113,9 @@ describe PieceJustificativeToChampPieceJointeMigrationService do
dossier.reload dossier.reload
end end
it 'the champ has the same timestamps as the dossier' do it 'the champ doesnt trigger a notification' do
expect(dossier.champs.last.created_at).to eq(initial_dossier_timestamps[:created_at]) expect(dossier.champs.last.created_at).to eq(initial_dossier_timestamps[:created_at])
expect(dossier.champs.last.updated_at).to eq(initial_dossier_timestamps[:updated_at]) expect(dossier.champs.last.updated_at).to eq(initial_dossier_timestamps[:created_at])
end end
it 'does not change the dossier timestamps' do it 'does not change the dossier timestamps' do