2015-08-10 11:05:06 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2015-09-23 19:20:03 +02:00
|
|
|
describe Users::RecapitulatifController, type: :controller do
|
2016-08-08 14:12:16 +02:00
|
|
|
let(:dossier) { create(:dossier, state: 'initiated') }
|
2015-09-23 19:20:03 +02:00
|
|
|
let(:bad_dossier_id) { Dossier.count + 100000 }
|
2015-08-10 11:05:06 +02:00
|
|
|
|
2015-09-24 16:51:14 +02:00
|
|
|
before do
|
|
|
|
sign_in dossier.user
|
|
|
|
end
|
|
|
|
|
2015-08-20 16:52:36 +02:00
|
|
|
describe 'GET #show' do
|
|
|
|
it 'returns http success' do
|
2016-11-15 05:54:27 +01:00
|
|
|
get :show, params: {dossier_id: dossier.id}
|
2015-08-10 11:05:06 +02:00
|
|
|
expect(response).to have_http_status(:success)
|
|
|
|
end
|
|
|
|
|
2015-09-23 16:56:30 +02:00
|
|
|
it 'redirection vers siret si mauvais dossier ID' do
|
2016-11-15 05:54:27 +01:00
|
|
|
get :show, params: {dossier_id: bad_dossier_id}
|
2015-10-09 17:33:33 +02:00
|
|
|
expect(response).to redirect_to('/')
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
2015-10-09 17:33:33 +02:00
|
|
|
|
|
|
|
it_behaves_like "not owner of dossier", :show
|
|
|
|
|
2016-01-25 15:54:21 +01:00
|
|
|
describe 'before_action authorized_routes?' do
|
|
|
|
context 'when dossier have draft state' do
|
|
|
|
before do
|
|
|
|
dossier.state = 'draft'
|
|
|
|
dossier.save
|
|
|
|
|
2016-11-15 05:54:27 +01:00
|
|
|
get :show, params: {dossier_id: dossier.id}
|
2016-01-25 15:54:21 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to redirect_to root_path }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|
2015-09-24 16:51:14 +02:00
|
|
|
|
2015-11-02 15:31:15 +01:00
|
|
|
describe 'POST #initiate' do
|
|
|
|
context 'when an user initiate his dossier' do
|
2015-09-24 16:51:14 +02:00
|
|
|
before do
|
2016-11-15 05:54:27 +01:00
|
|
|
post :initiate, params: {dossier_id: dossier.id}
|
2015-09-24 16:51:14 +02:00
|
|
|
end
|
|
|
|
|
2015-11-02 15:00:28 +01:00
|
|
|
it 'dossier change his state for closed' do
|
2015-09-24 16:51:14 +02:00
|
|
|
dossier.reload
|
2015-11-02 15:31:15 +01:00
|
|
|
expect(dossier.state).to eq('initiated')
|
2015-09-24 16:51:14 +02:00
|
|
|
end
|
|
|
|
|
2015-11-02 15:31:15 +01:00
|
|
|
it 'a message informe user what his dossier is initiated' do
|
2015-09-24 16:51:14 +02:00
|
|
|
expect(flash[:notice]).to include('Dossier soumis avec succès.')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-02 15:46:43 +01:00
|
|
|
describe 'POST #submit' do
|
2015-09-24 16:51:14 +02:00
|
|
|
context 'when an user depose his dossier' do
|
2016-08-08 14:12:16 +02:00
|
|
|
let(:deposit_datetime) { Time.local(2016, 8, 1, 10, 5, 0) }
|
|
|
|
|
2015-09-24 16:51:14 +02:00
|
|
|
before do
|
2015-11-02 11:45:52 +01:00
|
|
|
dossier.validated!
|
2016-11-15 05:54:27 +01:00
|
|
|
Timecop.freeze(deposit_datetime) { post :submit, params: {dossier_id: dossier.id} }
|
2016-08-08 14:12:16 +02:00
|
|
|
dossier.reload
|
2015-09-24 16:51:14 +02:00
|
|
|
end
|
|
|
|
|
2015-11-02 15:46:43 +01:00
|
|
|
it 'dossier change his state for submitted' do
|
|
|
|
expect(dossier.state).to eq('submitted')
|
2015-09-24 16:51:14 +02:00
|
|
|
end
|
|
|
|
|
2016-08-08 14:12:16 +02:00
|
|
|
it 'dossier deposit datetime is filled' do
|
|
|
|
expect(dossier.deposit_datetime).to eq deposit_datetime
|
|
|
|
end
|
|
|
|
|
2015-11-02 15:31:15 +01:00
|
|
|
it 'a message informe user what his dossier is initiated' do
|
2015-09-24 16:51:14 +02:00
|
|
|
expect(flash[:notice]).to include('Dossier déposé avec succès.')
|
|
|
|
end
|
2015-12-17 10:09:44 +01:00
|
|
|
|
|
|
|
it 'Notification email is send' do
|
|
|
|
expect(NotificationMailer).to receive(:dossier_submitted).and_return(NotificationMailer)
|
|
|
|
expect(NotificationMailer).to receive(:deliver_now!)
|
|
|
|
|
|
|
|
dossier.validated!
|
2016-11-15 05:54:27 +01:00
|
|
|
post :submit, params: {dossier_id: dossier.id}
|
2015-12-17 10:09:44 +01:00
|
|
|
end
|
2015-09-24 16:51:14 +02:00
|
|
|
end
|
|
|
|
end
|
2015-08-10 11:05:06 +02:00
|
|
|
end
|