diff --git a/app/controllers/api/v1/dossiers_controller.rb b/app/controllers/api/v1/dossiers_controller.rb index 447a653ce..3dd39d816 100644 --- a/app/controllers/api/v1/dossiers_controller.rb +++ b/app/controllers/api/v1/dossiers_controller.rb @@ -2,8 +2,8 @@ class API::V1::DossiersController < APIController def index procedure = current_administrateur.procedures.find(params[:procedure_id]) - dossiers = procedure.dossiers.paginate(page: params[:page]).decorate - render json: dossiers, meta: pagination(dossiers), meta_key: 'pagination', status: 200 + dossiers = procedure.dossiers.paginate(page: params[:page]) + render json: dossiers, each_serializer: DossiersSerializer, meta: pagination(dossiers), meta_key: 'pagination', status: 200 rescue ActiveRecord::RecordNotFound => e render json: {}, status: 404 end diff --git a/app/serializers/dossiers_serializer.rb b/app/serializers/dossiers_serializer.rb new file mode 100644 index 000000000..2a4f084a1 --- /dev/null +++ b/app/serializers/dossiers_serializer.rb @@ -0,0 +1,5 @@ +class DossiersSerializer < ActiveModel::Serializer + attributes :id, + :nom_projet, + :updated_at +end \ No newline at end of file diff --git a/spec/controllers/api/v1/dossiers_controller_spec.rb b/spec/controllers/api/v1/dossiers_controller_spec.rb index 74f0a0315..467eb35b4 100644 --- a/spec/controllers/api/v1/dossiers_controller_spec.rb +++ b/spec/controllers/api/v1/dossiers_controller_spec.rb @@ -24,7 +24,7 @@ describe API::V1::DossiersController do context 'when procedure is found and belongs to admin' do let(:procedure_id) { procedure.id } let(:date_creation) { Time.local(2008, 9, 1, 10, 5, 0) } - let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, :with_user, procedure: procedure) } } + let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } } let(:body) { JSON.parse(response.body, symbolize_names: true) } it { expect(response.code).to eq('200') } it { expect(body).to have_key :pagination } @@ -54,8 +54,8 @@ describe API::V1::DossiersController do context 'when there are multiple pages' do let(:response) { get :index, token: admin.api_token, procedure_id: procedure_id, page: 2 } - let!(:dossier1) { create(:dossier, :with_entreprise, :with_user, procedure: procedure) } - let!(:dossier2) { create(:dossier, :with_entreprise, :with_user, procedure: procedure) } + let!(:dossier1) { create(:dossier, :with_entreprise, procedure: procedure) } + let!(:dossier2) { create(:dossier, :with_entreprise, procedure: procedure) } before do allow(Dossier).to receive(:per_page).and_return(1) end