Merge pull request #1159 from sgmap/fix_1149
Move avis actions to new gestionnaire controller
This commit is contained in:
commit
b086706f55
8 changed files with 269 additions and 264 deletions
|
@ -1,7 +1,5 @@
|
||||||
class Backoffice::AvisController < ApplicationController
|
class Backoffice::AvisController < ApplicationController
|
||||||
before_action :authenticate_gestionnaire!, except: [:sign_up, :create_gestionnaire]
|
before_action :authenticate_gestionnaire!
|
||||||
before_action :redirect_if_no_sign_up_needed, only: [:sign_up]
|
|
||||||
before_action :check_avis_exists_and_email_belongs_to_avis, only: [:sign_up, :create_gestionnaire]
|
|
||||||
|
|
||||||
def create
|
def create
|
||||||
avis = Avis.new(create_params.merge(claimant: current_gestionnaire, dossier: dossier, confidentiel: true))
|
avis = Avis.new(create_params.merge(claimant: current_gestionnaire, dossier: dossier, confidentiel: true))
|
||||||
|
@ -22,30 +20,6 @@ class Backoffice::AvisController < ApplicationController
|
||||||
redirect_to backoffice_dossier_path(avis.dossier_id)
|
redirect_to backoffice_dossier_path(avis.dossier_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def sign_up
|
|
||||||
@email = params[:email]
|
|
||||||
@dossier = Avis.includes(:dossier).find(params[:id]).dossier
|
|
||||||
|
|
||||||
render layout: 'new_application'
|
|
||||||
end
|
|
||||||
|
|
||||||
def create_gestionnaire
|
|
||||||
email = params[:email]
|
|
||||||
password = params['gestionnaire']['password']
|
|
||||||
|
|
||||||
gestionnaire = Gestionnaire.new(email: email, password: password)
|
|
||||||
|
|
||||||
if gestionnaire.save
|
|
||||||
sign_in(gestionnaire, scope: :gestionnaire)
|
|
||||||
Avis.link_avis_to_gestionnaire(gestionnaire)
|
|
||||||
avis = Avis.find(params[:id])
|
|
||||||
redirect_to url_for(avis_index_path)
|
|
||||||
else
|
|
||||||
flash[:alert] = gestionnaire.errors.full_messages
|
|
||||||
redirect_to url_for(avis_sign_up_path(params[:id], email))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def dossier
|
def dossier
|
||||||
|
@ -63,24 +37,4 @@ class Backoffice::AvisController < ApplicationController
|
||||||
def update_params
|
def update_params
|
||||||
params.require(:avis).permit(:answer)
|
params.require(:avis).permit(:answer)
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirect_if_no_sign_up_needed
|
|
||||||
avis = Avis.find(params[:id])
|
|
||||||
|
|
||||||
if current_gestionnaire.present?
|
|
||||||
# a gestionnaire is authenticated ... lets see if it can view the dossier
|
|
||||||
|
|
||||||
redirect_to backoffice_dossier_url(avis.dossier)
|
|
||||||
elsif avis.gestionnaire.present? && avis.gestionnaire.email == params[:email]
|
|
||||||
# the avis gestionnaire has already signed up and it sould sign in
|
|
||||||
|
|
||||||
redirect_to new_gestionnaire_session_url
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def check_avis_exists_and_email_belongs_to_avis
|
|
||||||
if !Avis.avis_exists_and_email_belongs_to_avis?(params[:id], params[:email])
|
|
||||||
redirect_to url_for(root_path)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
module NewGestionnaire
|
module NewGestionnaire
|
||||||
class AvisController < GestionnaireController
|
class AvisController < GestionnaireController
|
||||||
|
before_action :authenticate_gestionnaire!, except: [:sign_up, :create_gestionnaire]
|
||||||
|
before_action :redirect_if_no_sign_up_needed, only: [:sign_up]
|
||||||
|
before_action :check_avis_exists_and_email_belongs_to_avis, only: [:sign_up, :create_gestionnaire]
|
||||||
before_action :set_avis_and_dossier, only: [:show, :instruction, :messagerie, :create_commentaire]
|
before_action :set_avis_and_dossier, only: [:show, :instruction, :messagerie, :create_commentaire]
|
||||||
|
|
||||||
A_DONNER_STATUS = 'a-donner'
|
A_DONNER_STATUS = 'a-donner'
|
||||||
|
@ -56,6 +59,30 @@ module NewGestionnaire
|
||||||
redirect_to instruction_avis_path(avis)
|
redirect_to instruction_avis_path(avis)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sign_up
|
||||||
|
@email = params[:email]
|
||||||
|
@dossier = Avis.includes(:dossier).find(params[:id]).dossier
|
||||||
|
|
||||||
|
render layout: 'new_application'
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_gestionnaire
|
||||||
|
email = params[:email]
|
||||||
|
password = params['gestionnaire']['password']
|
||||||
|
|
||||||
|
gestionnaire = Gestionnaire.new(email: email, password: password)
|
||||||
|
|
||||||
|
if gestionnaire.save
|
||||||
|
sign_in(gestionnaire, scope: :gestionnaire)
|
||||||
|
Avis.link_avis_to_gestionnaire(gestionnaire)
|
||||||
|
avis = Avis.find(params[:id])
|
||||||
|
redirect_to url_for(avis_index_path)
|
||||||
|
else
|
||||||
|
flash[:alert] = gestionnaire.errors.full_messages
|
||||||
|
redirect_to url_for(sign_up_avis_path(params[:id], email))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_avis_and_dossier
|
def set_avis_and_dossier
|
||||||
|
@ -63,6 +90,26 @@ module NewGestionnaire
|
||||||
@dossier = avis.dossier
|
@dossier = avis.dossier
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def redirect_if_no_sign_up_needed
|
||||||
|
avis = Avis.find(params[:id])
|
||||||
|
|
||||||
|
if current_gestionnaire.present?
|
||||||
|
# a gestionnaire is authenticated ... lets see if it can view the dossier
|
||||||
|
|
||||||
|
redirect_to avis_url(avis)
|
||||||
|
elsif avis.gestionnaire.present? && avis.gestionnaire.email == params[:email]
|
||||||
|
# the avis gestionnaire has already signed up and it sould sign in
|
||||||
|
|
||||||
|
redirect_to new_gestionnaire_session_url
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_avis_exists_and_email_belongs_to_avis
|
||||||
|
if !Avis.avis_exists_and_email_belongs_to_avis?(params[:id], params[:email])
|
||||||
|
redirect_to url_for(root_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def avis
|
def avis
|
||||||
current_gestionnaire.avis.includes(dossier: [:avis, :commentaires]).find(params[:id])
|
current_gestionnaire.avis.includes(dossier: [:avis, :commentaires]).find(params[:id])
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,10 +12,10 @@
|
||||||
|
|
||||||
- if @avis.gestionnaire.present?
|
- if @avis.gestionnaire.present?
|
||||||
%p
|
%p
|
||||||
= link_to "Connectez-vous pour donner votre avis", backoffice_dossier_url(@avis.dossier)
|
= link_to "Connectez-vous pour donner votre avis", dossier_url(@avis.dossier.procedure, @avis.dossier)
|
||||||
- else
|
- else
|
||||||
%p
|
%p
|
||||||
= link_to "Inscrivez-vous pour donner votre avis", avis_sign_up_url(@avis.id, @avis.email)
|
= link_to "Inscrivez-vous pour donner votre avis", sign_up_avis_url(@avis.id, @avis.email)
|
||||||
|
|
||||||
Bonne journée,
|
Bonne journée,
|
||||||
%br
|
%br
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
%p.description= @dossier.procedure.libelle
|
%p.description= @dossier.procedure.libelle
|
||||||
%p.dossier Dossier nº #{@dossier.id}
|
%p.dossier Dossier nº #{@dossier.id}
|
||||||
.column
|
.column
|
||||||
= form_for(Gestionnaire.new, url: { controller: "backoffice/avis", action: :create_gestionnaire }, method: :post, html: { class: "form" }) do |f|
|
= form_for(Gestionnaire.new, url: { controller: "new_gestionnaire/avis", action: :create_gestionnaire }, method: :post, html: { class: "form" }) do |f|
|
||||||
%h1 Créez-vous un compte
|
%h1 Créez-vous un compte
|
||||||
|
|
||||||
= f.label :email, "Email"
|
= f.label :email, "Email"
|
|
@ -33,9 +33,6 @@ Rails.application.routes.draw do
|
||||||
put '/gestionnaires' => 'gestionnaires/registrations#update', :as => 'gestionnaires_registration'
|
put '/gestionnaires' => 'gestionnaires/registrations#update', :as => 'gestionnaires_registration'
|
||||||
end
|
end
|
||||||
|
|
||||||
get 'avis/:id/sign_up/email/:email' => 'backoffice/avis#sign_up', constraints: { email: /.*/ }, as: 'avis_sign_up'
|
|
||||||
post 'avis/:id/sign_up/email/:email' => 'backoffice/avis#create_gestionnaire', constraints: { email: /.*/ }
|
|
||||||
|
|
||||||
devise_scope :administrateur do
|
devise_scope :administrateur do
|
||||||
get '/administrateurs/sign_in/demo' => redirect("/users/sign_in")
|
get '/administrateurs/sign_in/demo' => redirect("/users/sign_in")
|
||||||
end
|
end
|
||||||
|
@ -283,6 +280,9 @@ Rails.application.routes.draw do
|
||||||
get 'messagerie'
|
get 'messagerie'
|
||||||
post 'commentaire' => 'avis#create_commentaire'
|
post 'commentaire' => 'avis#create_commentaire'
|
||||||
post 'avis' => 'avis#create_avis'
|
post 'avis' => 'avis#create_avis'
|
||||||
|
|
||||||
|
get 'sign_up/email/:email' => 'avis#sign_up', constraints: { email: /.*/ }, as: 'sign_up'
|
||||||
|
post 'sign_up/email/:email' => 'avis#create_gestionnaire', constraints: { email: /.*/ }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
get "recherche" => "recherche#index"
|
get "recherche" => "recherche#index"
|
||||||
|
|
|
@ -77,116 +77,4 @@ describe Backoffice::AvisController, type: :controller do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '.sign_up' do
|
|
||||||
let(:invited_email) { 'invited@avis.com' }
|
|
||||||
let(:dossier) { create(:dossier) }
|
|
||||||
let!(:avis) { create(:avis, email: invited_email, dossier: dossier) }
|
|
||||||
let(:invitations_email) { true }
|
|
||||||
|
|
||||||
context 'when the new gestionnaire has never signed up' do
|
|
||||||
before do
|
|
||||||
expect(Avis).to receive(:avis_exists_and_email_belongs_to_avis?)
|
|
||||||
.with(avis.id.to_s, invited_email)
|
|
||||||
.and_return(invitations_email)
|
|
||||||
get :sign_up, params: { id: avis.id, email: invited_email }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when the email belongs to the invitation' do
|
|
||||||
it { expect(subject.status).to eq(200) }
|
|
||||||
it { expect(assigns(:email)).to eq(invited_email) }
|
|
||||||
it { expect(assigns(:dossier)).to eq(dossier) }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when the email does not belong to the invitation' do
|
|
||||||
let(:invitations_email) { false }
|
|
||||||
|
|
||||||
it { is_expected.to redirect_to root_path }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when the gestionnaire has already signed up and belongs to the invitation' do
|
|
||||||
let(:gestionnaire) { create(:gestionnaire, email: invited_email) }
|
|
||||||
let!(:avis) { create(:avis, dossier: dossier, gestionnaire: gestionnaire) }
|
|
||||||
|
|
||||||
context 'when the gestionnaire is authenticated' do
|
|
||||||
before do
|
|
||||||
sign_in gestionnaire
|
|
||||||
get :sign_up, params: { id: avis.id, email: invited_email }
|
|
||||||
end
|
|
||||||
|
|
||||||
it { is_expected.to redirect_to backoffice_dossier_url(avis.dossier) }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when the gestionnaire is not authenticated' do
|
|
||||||
before do
|
|
||||||
get :sign_up, params: { id: avis.id, email: invited_email }
|
|
||||||
end
|
|
||||||
|
|
||||||
it { is_expected.to redirect_to new_gestionnaire_session_url }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when the gestionnaire has already signed up / is authenticated and does not belong to the invitation' do
|
|
||||||
let(:gestionnaire) { create(:gestionnaire, email: 'other@gmail.com') }
|
|
||||||
let!(:avis) { create(:avis, email: invited_email, dossier: dossier) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
sign_in gestionnaire
|
|
||||||
get :sign_up, params: { id: avis.id, email: invited_email }
|
|
||||||
end
|
|
||||||
|
|
||||||
# redirected to dossier but then the gestionnaire gonna be banished !
|
|
||||||
it { is_expected.to redirect_to backoffice_dossier_url(avis.dossier) }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '.create_gestionnaire' do
|
|
||||||
let(:invited_email) { 'invited@avis.com' }
|
|
||||||
let(:dossier) { create(:dossier) }
|
|
||||||
let!(:avis) { create(:avis, email: invited_email, dossier: dossier) }
|
|
||||||
let(:avis_id) { avis.id }
|
|
||||||
let(:password) { '12345678' }
|
|
||||||
let(:created_gestionnaire) { Gestionnaire.find_by(email: invited_email) }
|
|
||||||
let(:invitations_email) { true }
|
|
||||||
|
|
||||||
before do
|
|
||||||
allow(Avis).to receive(:link_avis_to_gestionnaire)
|
|
||||||
expect(Avis).to receive(:avis_exists_and_email_belongs_to_avis?)
|
|
||||||
.with(avis_id.to_s, invited_email)
|
|
||||||
.and_return(invitations_email)
|
|
||||||
|
|
||||||
post :create_gestionnaire, params: { id: avis_id,
|
|
||||||
email: invited_email,
|
|
||||||
gestionnaire: {
|
|
||||||
password: password
|
|
||||||
} }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when the email does not belong to the invitation' do
|
|
||||||
let(:invitations_email) { false }
|
|
||||||
|
|
||||||
it { is_expected.to redirect_to root_path }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when the email belongs to the invitation' do
|
|
||||||
context 'when the gestionnaire creation succeeds' do
|
|
||||||
it { expect(created_gestionnaire).to be_present }
|
|
||||||
it { expect(created_gestionnaire.valid_password?(password)).to be true }
|
|
||||||
|
|
||||||
it { expect(Avis).to have_received(:link_avis_to_gestionnaire) }
|
|
||||||
|
|
||||||
it { expect(subject.current_gestionnaire).to eq(created_gestionnaire) }
|
|
||||||
it { is_expected.to redirect_to avis_index_path }
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when the gestionnaire creation fails' do
|
|
||||||
let(:password) { '' }
|
|
||||||
|
|
||||||
it { expect(created_gestionnaire).to be_nil }
|
|
||||||
it { is_expected.to redirect_to avis_sign_up_path(avis_id, invited_email) }
|
|
||||||
it { expect(flash.alert).to eq(['Password : Le mot de passe est vide']) }
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,140 +1,256 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe NewGestionnaire::AvisController, type: :controller do
|
describe NewGestionnaire::AvisController, type: :controller do
|
||||||
render_views
|
context 'with a gestionnaire signed in' do
|
||||||
|
render_views
|
||||||
|
|
||||||
let(:claimant) { create(:gestionnaire) }
|
let(:claimant) { create(:gestionnaire) }
|
||||||
let(:gestionnaire) { create(:gestionnaire) }
|
let(:gestionnaire) { create(:gestionnaire) }
|
||||||
let(:procedure) { create(:procedure, :published, gestionnaires: [gestionnaire]) }
|
let(:procedure) { create(:procedure, :published, gestionnaires: [gestionnaire]) }
|
||||||
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
||||||
let!(:avis_without_answer) { Avis.create(dossier: dossier, claimant: claimant, gestionnaire: gestionnaire) }
|
let!(:avis_without_answer) { Avis.create(dossier: dossier, claimant: claimant, gestionnaire: gestionnaire) }
|
||||||
let!(:avis_with_answer) { Avis.create(dossier: dossier, claimant: claimant, gestionnaire: gestionnaire, answer: 'yop') }
|
let!(:avis_with_answer) { Avis.create(dossier: dossier, claimant: claimant, gestionnaire: gestionnaire, answer: 'yop') }
|
||||||
|
|
||||||
before { sign_in(gestionnaire) }
|
before { sign_in(gestionnaire) }
|
||||||
|
|
||||||
describe '#index' do
|
describe '#index' do
|
||||||
before { get :index }
|
before { get :index }
|
||||||
|
|
||||||
it { expect(response).to have_http_status(:success) }
|
it { expect(response).to have_http_status(:success) }
|
||||||
it { expect(assigns(:avis_a_donner)).to match([avis_without_answer]) }
|
it { expect(assigns(:avis_a_donner)).to match([avis_without_answer]) }
|
||||||
it { expect(assigns(:avis_donnes)).to match([avis_with_answer]) }
|
it { expect(assigns(:avis_donnes)).to match([avis_with_answer]) }
|
||||||
it { expect(assigns(:statut)).to eq('a-donner') }
|
it { expect(assigns(:statut)).to eq('a-donner') }
|
||||||
|
|
||||||
context 'with a statut equal to donnes' do
|
context 'with a statut equal to donnes' do
|
||||||
before { get :index, statut: 'donnes' }
|
before { get :index, statut: 'donnes' }
|
||||||
|
|
||||||
it { expect(assigns(:statut)).to eq('donnes') }
|
it { expect(assigns(:statut)).to eq('donnes') }
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
describe '#show' do
|
|
||||||
before { get :show, { id: avis_without_answer.id } }
|
|
||||||
|
|
||||||
it { expect(response).to have_http_status(:success) }
|
|
||||||
it { expect(assigns(:avis)).to eq(avis_without_answer) }
|
|
||||||
it { expect(assigns(:dossier)).to eq(dossier) }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#instruction' do
|
|
||||||
before { get :instruction, { id: avis_without_answer.id } }
|
|
||||||
|
|
||||||
it { expect(response).to have_http_status(:success) }
|
|
||||||
it { expect(assigns(:avis)).to eq(avis_without_answer) }
|
|
||||||
it { expect(assigns(:dossier)).to eq(dossier) }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#messagerie' do
|
|
||||||
before { get :messagerie, { id: avis_without_answer.id } }
|
|
||||||
|
|
||||||
it { expect(response).to have_http_status(:success) }
|
|
||||||
it { expect(assigns(:avis)).to eq(avis_without_answer) }
|
|
||||||
it { expect(assigns(:dossier)).to eq(dossier) }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#update' do
|
|
||||||
before do
|
|
||||||
patch :update, { id: avis_without_answer.id, avis: { answer: 'answer' } }
|
|
||||||
avis_without_answer.reload
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(response).to redirect_to(instruction_avis_path(avis_without_answer)) }
|
describe '#show' do
|
||||||
it { expect(avis_without_answer.answer).to eq('answer') }
|
before { get :show, { id: avis_without_answer.id } }
|
||||||
it { expect(flash.notice).to eq('Votre réponse est enregistrée.') }
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#create_commentaire' do
|
it { expect(response).to have_http_status(:success) }
|
||||||
let(:file) { nil }
|
it { expect(assigns(:avis)).to eq(avis_without_answer) }
|
||||||
let(:scan_result) { true }
|
it { expect(assigns(:dossier)).to eq(dossier) }
|
||||||
|
|
||||||
subject { post :create_commentaire, { id: avis_without_answer.id, commentaire: { body: 'commentaire body', file: file } } }
|
|
||||||
|
|
||||||
before do
|
|
||||||
allow(ClamavService).to receive(:safe_file?).and_return(scan_result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it do
|
describe '#instruction' do
|
||||||
subject
|
before { get :instruction, { id: avis_without_answer.id } }
|
||||||
|
|
||||||
expect(response).to redirect_to(messagerie_avis_path(avis_without_answer))
|
it { expect(response).to have_http_status(:success) }
|
||||||
expect(dossier.commentaires.map(&:body)).to match(['commentaire body'])
|
it { expect(assigns(:avis)).to eq(avis_without_answer) }
|
||||||
|
it { expect(assigns(:dossier)).to eq(dossier) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with a file" do
|
describe '#messagerie' do
|
||||||
let(:file) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
|
before { get :messagerie, { id: avis_without_answer.id } }
|
||||||
|
|
||||||
|
it { expect(response).to have_http_status(:success) }
|
||||||
|
it { expect(assigns(:avis)).to eq(avis_without_answer) }
|
||||||
|
it { expect(assigns(:dossier)).to eq(dossier) }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#update' do
|
||||||
|
before do
|
||||||
|
patch :update, { id: avis_without_answer.id, avis: { answer: 'answer' } }
|
||||||
|
avis_without_answer.reload
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(response).to redirect_to(instruction_avis_path(avis_without_answer)) }
|
||||||
|
it { expect(avis_without_answer.answer).to eq('answer') }
|
||||||
|
it { expect(flash.notice).to eq('Votre réponse est enregistrée.') }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#create_commentaire' do
|
||||||
|
let(:file) { nil }
|
||||||
|
let(:scan_result) { true }
|
||||||
|
|
||||||
|
subject { post :create_commentaire, { id: avis_without_answer.id, commentaire: { body: 'commentaire body', file: file } } }
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow(ClamavService).to receive(:safe_file?).and_return(scan_result)
|
||||||
|
end
|
||||||
|
|
||||||
it do
|
it do
|
||||||
subject
|
subject
|
||||||
expect(Commentaire.last.file.path).to include("piece_justificative_0.pdf")
|
|
||||||
|
expect(response).to redirect_to(messagerie_avis_path(avis_without_answer))
|
||||||
|
expect(dossier.commentaires.map(&:body)).to match(['commentaire body'])
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect { subject }.to change(Commentaire, :count).by(1) }
|
context "with a file" do
|
||||||
|
let(:file) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
|
||||||
|
|
||||||
context "and a virus" do
|
it do
|
||||||
let(:scan_result) { false }
|
subject
|
||||||
|
expect(Commentaire.last.file.path).to include("piece_justificative_0.pdf")
|
||||||
|
end
|
||||||
|
|
||||||
it { expect { subject }.not_to change(Commentaire, :count) }
|
it { expect { subject }.to change(Commentaire, :count).by(1) }
|
||||||
|
|
||||||
|
context "and a virus" do
|
||||||
|
let(:scan_result) { false }
|
||||||
|
|
||||||
|
it { expect { subject }.not_to change(Commentaire, :count) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#create_avis' do
|
||||||
|
let!(:previous_avis) { Avis.create(dossier: dossier, claimant: claimant, gestionnaire: gestionnaire, confidentiel: previous_avis_confidentiel) }
|
||||||
|
let(:email) { 'a@b.com' }
|
||||||
|
let(:intro) { 'introduction' }
|
||||||
|
let(:created_avis) { Avis.last }
|
||||||
|
|
||||||
|
before do
|
||||||
|
post :create_avis, { id: previous_avis.id, avis: { email: email, introduction: intro, confidentiel: asked_confidentiel } }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the previous avis is public' do
|
||||||
|
let(:previous_avis_confidentiel) { false }
|
||||||
|
|
||||||
|
context 'when the user asked for a public avis' do
|
||||||
|
let(:asked_confidentiel) { false }
|
||||||
|
|
||||||
|
it { expect(created_avis.confidentiel).to be(false) }
|
||||||
|
it { expect(created_avis.email).to eq(email) }
|
||||||
|
it { expect(created_avis.introduction).to eq(intro) }
|
||||||
|
it { expect(created_avis.dossier).to eq(previous_avis.dossier) }
|
||||||
|
it { expect(created_avis.claimant).to eq(gestionnaire) }
|
||||||
|
it { expect(response).to redirect_to(instruction_avis_path(previous_avis)) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the user asked for a confidentiel avis' do
|
||||||
|
let(:asked_confidentiel) { true }
|
||||||
|
|
||||||
|
it { expect(created_avis.confidentiel).to be(true) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the preivous avis is confidentiel' do
|
||||||
|
let(:previous_avis_confidentiel) { true }
|
||||||
|
|
||||||
|
context 'when the user asked for a public avis' do
|
||||||
|
let(:asked_confidentiel) { false }
|
||||||
|
|
||||||
|
it { expect(created_avis.confidentiel).to be(true) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#create_avis' do
|
context 'without a gestionnaire signed in' do
|
||||||
let!(:previous_avis) { Avis.create(dossier: dossier, claimant: claimant, gestionnaire: gestionnaire, confidentiel: previous_avis_confidentiel) }
|
describe '.sign_up' do
|
||||||
let(:email) { 'a@b.com' }
|
let(:invited_email) { 'invited@avis.com' }
|
||||||
let(:intro) { 'introduction' }
|
let(:dossier) { create(:dossier) }
|
||||||
let(:created_avis) { Avis.last }
|
let!(:avis) { create(:avis, email: invited_email, dossier: dossier) }
|
||||||
|
let(:invitations_email) { true }
|
||||||
|
|
||||||
before do
|
context 'when the new gestionnaire has never signed up' do
|
||||||
post :create_avis, { id: previous_avis.id, avis: { email: email, introduction: intro, confidentiel: asked_confidentiel } }
|
before do
|
||||||
end
|
expect(Avis).to receive(:avis_exists_and_email_belongs_to_avis?)
|
||||||
|
.with(avis.id.to_s, invited_email)
|
||||||
|
.and_return(invitations_email)
|
||||||
|
get :sign_up, params: { id: avis.id, email: invited_email }
|
||||||
|
end
|
||||||
|
|
||||||
context 'when the previous avis is public' do
|
context 'when the email belongs to the invitation' do
|
||||||
let(:previous_avis_confidentiel) { false }
|
it { expect(subject.status).to eq(200) }
|
||||||
|
it { expect(assigns(:email)).to eq(invited_email) }
|
||||||
|
it { expect(assigns(:dossier)).to eq(dossier) }
|
||||||
|
end
|
||||||
|
|
||||||
context 'when the user asked for a public avis' do
|
context 'when the email does not belong to the invitation' do
|
||||||
let(:asked_confidentiel) { false }
|
let(:invitations_email) { false }
|
||||||
|
|
||||||
it { expect(created_avis.confidentiel).to be(false) }
|
it { is_expected.to redirect_to root_path }
|
||||||
it { expect(created_avis.email).to eq(email) }
|
end
|
||||||
it { expect(created_avis.introduction).to eq(intro) }
|
|
||||||
it { expect(created_avis.dossier).to eq(previous_avis.dossier) }
|
|
||||||
it { expect(created_avis.claimant).to eq(gestionnaire) }
|
|
||||||
it { expect(response).to redirect_to(instruction_avis_path(previous_avis)) }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the user asked for a confidentiel avis' do
|
context 'when the gestionnaire has already signed up and belongs to the invitation' do
|
||||||
let(:asked_confidentiel) { true }
|
let(:gestionnaire) { create(:gestionnaire, email: invited_email) }
|
||||||
|
let!(:avis) { create(:avis, dossier: dossier, gestionnaire: gestionnaire) }
|
||||||
|
|
||||||
it { expect(created_avis.confidentiel).to be(true) }
|
context 'when the gestionnaire is authenticated' do
|
||||||
|
before do
|
||||||
|
sign_in gestionnaire
|
||||||
|
get :sign_up, params: { id: avis.id, email: invited_email }
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.to redirect_to avis_url(avis) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the gestionnaire is not authenticated' do
|
||||||
|
before do
|
||||||
|
get :sign_up, params: { id: avis.id, email: invited_email }
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.to redirect_to new_gestionnaire_session_url }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the gestionnaire has already signed up / is authenticated and does not belong to the invitation' do
|
||||||
|
let(:gestionnaire) { create(:gestionnaire, email: 'other@gmail.com') }
|
||||||
|
let!(:avis) { create(:avis, email: invited_email, dossier: dossier) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
sign_in gestionnaire
|
||||||
|
get :sign_up, params: { id: avis.id, email: invited_email }
|
||||||
|
end
|
||||||
|
|
||||||
|
# redirected to dossier but then the gestionnaire gonna be banished !
|
||||||
|
it { is_expected.to redirect_to avis_url(avis) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the preivous avis is confidentiel' do
|
describe '.create_gestionnaire' do
|
||||||
let(:previous_avis_confidentiel) { true }
|
let(:invited_email) { 'invited@avis.com' }
|
||||||
|
let(:dossier) { create(:dossier) }
|
||||||
|
let!(:avis) { create(:avis, email: invited_email, dossier: dossier) }
|
||||||
|
let(:avis_id) { avis.id }
|
||||||
|
let(:password) { '12345678' }
|
||||||
|
let(:created_gestionnaire) { Gestionnaire.find_by(email: invited_email) }
|
||||||
|
let(:invitations_email) { true }
|
||||||
|
|
||||||
context 'when the user asked for a public avis' do
|
before do
|
||||||
let(:asked_confidentiel) { false }
|
allow(Avis).to receive(:link_avis_to_gestionnaire)
|
||||||
|
expect(Avis).to receive(:avis_exists_and_email_belongs_to_avis?)
|
||||||
|
.with(avis_id.to_s, invited_email)
|
||||||
|
.and_return(invitations_email)
|
||||||
|
|
||||||
it { expect(created_avis.confidentiel).to be(true) }
|
post :create_gestionnaire, params: { id: avis_id,
|
||||||
|
email: invited_email,
|
||||||
|
gestionnaire: {
|
||||||
|
password: password
|
||||||
|
} }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the email does not belong to the invitation' do
|
||||||
|
let(:invitations_email) { false }
|
||||||
|
|
||||||
|
it { is_expected.to redirect_to root_path }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the email belongs to the invitation' do
|
||||||
|
context 'when the gestionnaire creation succeeds' do
|
||||||
|
it { expect(created_gestionnaire).to be_present }
|
||||||
|
it { expect(created_gestionnaire.valid_password?(password)).to be true }
|
||||||
|
|
||||||
|
it { expect(Avis).to have_received(:link_avis_to_gestionnaire) }
|
||||||
|
|
||||||
|
it { expect(subject.current_gestionnaire).to eq(created_gestionnaire) }
|
||||||
|
it { is_expected.to redirect_to avis_index_path }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the gestionnaire creation fails' do
|
||||||
|
let(:password) { '' }
|
||||||
|
|
||||||
|
it { expect(created_gestionnaire).to be_nil }
|
||||||
|
it { is_expected.to redirect_to sign_up_avis_path(avis_id, invited_email) }
|
||||||
|
it { expect(flash.alert).to eq(['Password : Le mot de passe est vide']) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -71,7 +71,7 @@ feature 'The gestionnaire part' do
|
||||||
log_out
|
log_out
|
||||||
|
|
||||||
avis = dossier.avis.first
|
avis = dossier.avis.first
|
||||||
test_mail(expert_email, avis_sign_up_path(avis, expert_email))
|
test_mail(expert_email, sign_up_avis_path(avis, expert_email))
|
||||||
|
|
||||||
avis_sign_up(avis, expert_email, 'a good password')
|
avis_sign_up(avis, expert_email, 'a good password')
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ feature 'The gestionnaire part' do
|
||||||
end
|
end
|
||||||
|
|
||||||
def avis_sign_up(avis, email, password)
|
def avis_sign_up(avis, email, password)
|
||||||
visit avis_sign_up_path(avis, email)
|
visit sign_up_avis_path(avis, email)
|
||||||
fill_in 'gestionnaire_password', with: 'a good password'
|
fill_in 'gestionnaire_password', with: 'a good password'
|
||||||
click_on 'Créer un compte'
|
click_on 'Créer un compte'
|
||||||
expect(page).to have_current_path(avis_index_path)
|
expect(page).to have_current_path(avis_index_path)
|
||||||
|
|
Loading…
Reference in a new issue