Add deposit date time on dossier table

This commit is contained in:
Xavier J 2016-08-08 14:12:16 +02:00
parent d6b9ebde9a
commit 9487d47ef8
5 changed files with 24 additions and 7 deletions

View file

@ -19,11 +19,9 @@ class Users::RecapitulatifController < UsersController
def submit def submit
create_dossier_facade create_dossier_facade
@facade.dossier.next_step! 'user', 'submit' @facade.dossier.submit!
flash.notice = 'Dossier déposé avec succès.' flash.notice = 'Dossier déposé avec succès.'
NotificationMailer.dossier_submitted(@facade.dossier).deliver_now!
render 'show' render 'show'
end end

View file

@ -216,4 +216,11 @@ class Dossier < ActiveRecord::Base
def total_commentaire def total_commentaire
self.commentaires.size self.commentaires.size
end end
def submit!
self.deposit_datetime= DateTime.now
next_step! 'user', 'submit'
NotificationMailer.dossier_submitted(self).deliver_now!
end
end end

View file

@ -0,0 +1,5 @@
class AddDepositAttrInDossierTable < ActiveRecord::Migration
def change
add_column :dossiers, :deposit_datetime, :datetime
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160804130638) do ActiveRecord::Schema.define(version: 20160808115924) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -124,6 +124,7 @@ ActiveRecord::Schema.define(version: 20160804130638) do
t.text "json_latlngs" t.text "json_latlngs"
t.boolean "archived", default: false t.boolean "archived", default: false
t.boolean "mandataire_social", default: false t.boolean "mandataire_social", default: false
t.datetime "deposit_datetime"
end end
add_index "dossiers", ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree add_index "dossiers", ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree

View file

@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'
describe Users::RecapitulatifController, type: :controller do describe Users::RecapitulatifController, type: :controller do
let(:dossier) { create(:dossier, state:'initiated') } let(:dossier) { create(:dossier, state: 'initiated') }
let(:bad_dossier_id) { Dossier.count + 100000 } let(:bad_dossier_id) { Dossier.count + 100000 }
before do before do
@ -55,16 +55,22 @@ describe Users::RecapitulatifController, type: :controller do
describe 'POST #submit' do describe 'POST #submit' do
context 'when an user depose his dossier' do context 'when an user depose his dossier' do
let(:deposit_datetime) { Time.local(2016, 8, 1, 10, 5, 0) }
before do before do
dossier.validated! dossier.validated!
post :submit, dossier_id: dossier.id Timecop.freeze(deposit_datetime) { post :submit, dossier_id: dossier.id }
dossier.reload
end end
it 'dossier change his state for submitted' do it 'dossier change his state for submitted' do
dossier.reload
expect(dossier.state).to eq('submitted') expect(dossier.state).to eq('submitted')
end end
it 'dossier deposit datetime is filled' do
expect(dossier.deposit_datetime).to eq deposit_datetime
end
it 'a message informe user what his dossier is initiated' do it 'a message informe user what his dossier is initiated' do
expect(flash[:notice]).to include('Dossier déposé avec succès.') expect(flash[:notice]).to include('Dossier déposé avec succès.')
end end