Avis: add claimant gestionnaire to track who asks for an avis
This commit is contained in:
parent
23e57f5cc4
commit
64f7cab3cf
9 changed files with 33 additions and 11 deletions
|
@ -5,7 +5,7 @@ class Backoffice::AvisController < ApplicationController
|
|||
before_action :check_avis_exists_and_email_belongs_to_avis, only: [:sign_up, :create_gestionnaire]
|
||||
|
||||
def create
|
||||
avis = Avis.new(create_params)
|
||||
avis = Avis.new(create_params.merge(claimant: current_gestionnaire))
|
||||
avis.dossier = dossier
|
||||
|
||||
email = create_params[:email]
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class Avis < ApplicationRecord
|
||||
belongs_to :dossier
|
||||
belongs_to :gestionnaire
|
||||
belongs_to :claimant, class_name: 'Gestionnaire'
|
||||
|
||||
after_create :notify_gestionnaire
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
%p
|
||||
Bonjour,
|
||||
%br
|
||||
= "Vous avez été invité à donner votre avis sur le dossier nº #{@avis.dossier.id} de la procédure : #{@avis.dossier.procedure.libelle}."
|
||||
= "Vous avez été invité par #{@avis.claimant.email} à donner votre avis sur le dossier nº #{@avis.dossier.id} de la procédure : #{@avis.dossier.procedure.libelle}."
|
||||
%br
|
||||
Message de votre interlocuteur :
|
||||
|
||||
|
|
5
db/migrate/20170523092900_add_claimant_to_avis.rb
Normal file
5
db/migrate/20170523092900_add_claimant_to_avis.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class AddClaimantToAvis < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
add_reference :avis, :claimant, foreign_key: { to_table: :gestionnaires }, null: false
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20170425100757) do
|
||||
ActiveRecord::Schema.define(version: 20170523092900) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -79,6 +79,8 @@ ActiveRecord::Schema.define(version: 20170425100757) do
|
|||
t.integer "dossier_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "claimant_id", null: false
|
||||
t.index ["claimant_id"], name: "index_avis_on_claimant_id", using: :btree
|
||||
t.index ["dossier_id"], name: "index_avis_on_dossier_id", using: :btree
|
||||
t.index ["gestionnaire_id"], name: "index_avis_on_gestionnaire_id", using: :btree
|
||||
end
|
||||
|
@ -446,6 +448,7 @@ ActiveRecord::Schema.define(version: 20170425100757) do
|
|||
t.index ["procedure_id"], name: "index_without_continuation_mails_on_procedure_id", using: :btree
|
||||
end
|
||||
|
||||
add_foreign_key "avis", "gestionnaires", column: "claimant_id"
|
||||
add_foreign_key "cerfas", "dossiers"
|
||||
add_foreign_key "closed_mails", "procedures"
|
||||
add_foreign_key "commentaires", "dossiers"
|
||||
|
|
|
@ -75,7 +75,7 @@ describe Backoffice::AvisController, type: :controller do
|
|||
describe '.sign_up' do
|
||||
let(:invited_email) { 'invited@avis.com' }
|
||||
let(:dossier) { create(:dossier) }
|
||||
let!(:avis) { Avis.create(email: invited_email, dossier: dossier) }
|
||||
let!(:avis) { create(:avis, email: invited_email, dossier: dossier) }
|
||||
let(:invitations_email) { true }
|
||||
|
||||
context 'when the new gestionnaire has never signed up' do
|
||||
|
@ -101,7 +101,7 @@ describe Backoffice::AvisController, type: :controller do
|
|||
|
||||
context 'when the gestionnaire has already signed up and belongs to the invitation' do
|
||||
let(:gestionnaire) { create(:gestionnaire, email: invited_email) }
|
||||
let!(:avis) { Avis.create(dossier: dossier, gestionnaire: gestionnaire) }
|
||||
let!(:avis) { create(:avis, dossier: dossier, gestionnaire: gestionnaire) }
|
||||
|
||||
context 'when the gestionnaire is authenticated' do
|
||||
before do
|
||||
|
@ -123,7 +123,7 @@ describe Backoffice::AvisController, type: :controller do
|
|||
|
||||
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) { Avis.create(email: invited_email, dossier: dossier) }
|
||||
let!(:avis) { create(:avis, email: invited_email, dossier: dossier) }
|
||||
|
||||
before do
|
||||
sign_in gestionnaire
|
||||
|
@ -138,7 +138,7 @@ describe Backoffice::AvisController, type: :controller do
|
|||
describe '.create_gestionnaire' do
|
||||
let(:invited_email) { 'invited@avis.com' }
|
||||
let(:dossier) { create(:dossier) }
|
||||
let!(:avis) { Avis.create(email: invited_email, dossier: 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) }
|
||||
|
|
|
@ -13,5 +13,11 @@ FactoryGirl.define do
|
|||
avis.dossier = create :dossier
|
||||
end
|
||||
end
|
||||
|
||||
before(:create) do |avis, _evaluator|
|
||||
unless avis.claimant
|
||||
avis.claimant = create :gestionnaire
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,8 @@ RSpec.describe AvisMailer, type: :mailer do
|
|||
subject { described_class.you_are_invited_on_dossier(avis) }
|
||||
|
||||
it { expect(subject.subject).to eq("Donnez votre avis sur le dossier nº #{avis.dossier.id} (#{avis.dossier.procedure.libelle})") }
|
||||
it { expect(subject.body).to include("Vous avez été invité à donner votre avis sur le dossier nº #{avis.dossier.id} de la procédure : #{avis.dossier.procedure.libelle}.") }
|
||||
it { expect(subject.body).to include("Vous avez été invité par #{avis.claimant.email} à donner votre avis sur le dossier nº #{avis.dossier.id} de la procédure : #{avis.dossier.procedure.libelle}.") }
|
||||
it { expect(subject.body).to include(avis.introduction) }
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,15 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Avis, type: :model do
|
||||
let(:claimant) { create(:gestionnaire) }
|
||||
|
||||
describe '.email_to_display' do
|
||||
let(:invited_email) { 'invited@avis.com' }
|
||||
let!(:avis) { Avis.create(email: invited_email, dossier: create(:dossier)) }
|
||||
let!(:avis) do
|
||||
avis = create(:avis, email: invited_email, dossier: create(:dossier))
|
||||
avis.gestionnaire = nil
|
||||
avis
|
||||
end
|
||||
|
||||
subject { avis.email_to_display }
|
||||
|
||||
|
@ -12,7 +18,7 @@ RSpec.describe Avis, type: :model do
|
|||
end
|
||||
|
||||
context 'when gestionnaire is known' do
|
||||
let!(:avis) { Avis.create(email: nil, gestionnaire: create(:gestionnaire), dossier: create(:dossier)) }
|
||||
let!(:avis) { create(:avis, email: nil, gestionnaire: create(:gestionnaire), dossier: create(:dossier)) }
|
||||
|
||||
it{ is_expected.to eq(avis.gestionnaire.email) }
|
||||
end
|
||||
|
@ -55,7 +61,7 @@ RSpec.describe Avis, type: :model do
|
|||
describe '.avis_exists_and_email_belongs_to_avis' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:invited_email) { 'invited@avis.com' }
|
||||
let!(:avis) { Avis.create(email: invited_email, dossier: dossier) }
|
||||
let!(:avis) { create(:avis, email: invited_email, dossier: dossier) }
|
||||
|
||||
subject { Avis.avis_exists_and_email_belongs_to_avis?(avis_id, email) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue