Merge branch 'dev'
This commit is contained in:
commit
f0273d6512
21 changed files with 284 additions and 185 deletions
|
@ -6,7 +6,7 @@ class Admin::ProceduresController < AdminController
|
|||
|
||||
def index
|
||||
@procedures = smart_listing_create :procedures,
|
||||
current_administrateur.procedures.where(published: true, archived: false).order(created_at: :desc),
|
||||
current_administrateur.procedures.published.not_archived.order(created_at: :desc),
|
||||
partial: "admin/procedures/list",
|
||||
array: true
|
||||
|
||||
|
@ -15,7 +15,7 @@ class Admin::ProceduresController < AdminController
|
|||
|
||||
def archived
|
||||
@procedures = smart_listing_create :procedures,
|
||||
current_administrateur.procedures.where(archived: true).order(created_at: :desc),
|
||||
current_administrateur.procedures.archived.order(created_at: :desc),
|
||||
partial: "admin/procedures/list",
|
||||
array: true
|
||||
|
||||
|
@ -26,7 +26,7 @@ class Admin::ProceduresController < AdminController
|
|||
|
||||
def draft
|
||||
@procedures = smart_listing_create :procedures,
|
||||
current_administrateur.procedures.where(published: false, archived: false).order(created_at: :desc),
|
||||
current_administrateur.procedures.not_published.not_archived.order(created_at: :desc),
|
||||
partial: "admin/procedures/list",
|
||||
array: true
|
||||
|
||||
|
|
|
@ -9,10 +9,10 @@ class API::StatistiquesController < ApplicationController
|
|||
private
|
||||
|
||||
def total_dossiers
|
||||
Dossier.where.not(state: :draft).size
|
||||
Dossier.state_not_brouillon.size
|
||||
end
|
||||
|
||||
def dossiers_mois
|
||||
Dossier.where.not(state: :draft).where(created_at: (1.month.ago)..Time.now).size
|
||||
Dossier.state_not_brouillon.where(created_at: (1.month.ago)..Time.now).size
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ class API::V1::DossiersController < APIController
|
|||
|
||||
def index
|
||||
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
||||
dossiers = procedure.dossiers.where.not(state: :draft).paginate(page: params[:page])
|
||||
dossiers = procedure.dossiers.state_not_brouillon.paginate(page: params[:page])
|
||||
|
||||
render json: { dossiers: dossiers.map{ |dossier| DossiersSerializer.new(dossier) }, pagination: pagination(dossiers) }, status: 200
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
|
|
|
@ -13,14 +13,16 @@ class CommentairesController < ApplicationController
|
|||
|
||||
def create
|
||||
@commentaire = Commentaire.new
|
||||
@commentaire.dossier = Dossier.find(params['dossier_id'])
|
||||
@commentaire.champ = @commentaire.dossier.champs.find(params[:champ_id]) if params[:champ_id]
|
||||
|
||||
dossier_id = params['dossier_id']
|
||||
if is_gestionnaire?
|
||||
@commentaire.email = current_gestionnaire.email
|
||||
@commentaire.dossier = current_gestionnaire.dossiers.find_by(id: dossier_id) || current_gestionnaire.avis.find_by!(dossier_id: dossier_id).dossier
|
||||
@commentaire.dossier.next_step! 'gestionnaire', 'comment'
|
||||
else
|
||||
@commentaire.email = current_user.email
|
||||
@commentaire.dossier = current_user.dossiers.find_by(id: dossier_id) || current_user.invites.find_by!(dossier_id: dossier_id).dossier
|
||||
@commentaire.dossier.next_step! 'user', 'comment' if current_user.email == @commentaire.dossier.user.email
|
||||
end
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ class DemoController < ApplicationController
|
|||
return redirect_to root_path if Rails.env.production?
|
||||
|
||||
smart_listing_create :procedures,
|
||||
Procedure.where(archived: false, published: true).order("id DESC"),
|
||||
Procedure.published.not_archived.order("id DESC"),
|
||||
partial: "demo/list",
|
||||
array: true
|
||||
end
|
||||
|
|
|
@ -5,11 +5,12 @@ class InvitesController < ApplicationController
|
|||
email_sender = @current_devise_profil.email
|
||||
|
||||
class_var = @current_devise_profil.class == User ? InviteUser : InviteGestionnaire
|
||||
dossier = @current_devise_profil.dossiers.find(params[:dossier_id])
|
||||
|
||||
email = params[:email].downcase
|
||||
|
||||
user = User.find_by_email(email)
|
||||
invite = class_var.create(dossier_id: params[:dossier_id], user: user, email: email, email_sender: email_sender)
|
||||
invite = class_var.create(dossier: dossier, user: user, email: email, email_sender: email_sender)
|
||||
|
||||
if invite.valid?
|
||||
InviteMailer.invite_user(invite).deliver_now! unless invite.user.nil?
|
||||
|
|
|
@ -4,7 +4,7 @@ class StatsController < ApplicationController
|
|||
MEAN_NUMBER_OF_CHAMPS_IN_A_FORM = 24.0
|
||||
|
||||
def index
|
||||
procedures = Procedure.where(:published => true)
|
||||
procedures = Procedure.published
|
||||
dossiers = Dossier.where.not(:state => :draft)
|
||||
|
||||
@procedures_count = procedures.count
|
||||
|
|
|
@ -60,7 +60,7 @@ class Users::DossiersController < UsersController
|
|||
end
|
||||
|
||||
def new
|
||||
procedure = Procedure.where(archived: false, published: true).find(params[:procedure_id])
|
||||
procedure = Procedure.not_archived.published.find(params[:procedure_id])
|
||||
|
||||
dossier = Dossier.create(procedure: procedure, user: current_user, state: 'draft')
|
||||
siret = params[:siret] || current_user.siret
|
||||
|
|
|
@ -8,11 +8,11 @@ class AdminProceduresShowFacades
|
|||
end
|
||||
|
||||
def dossiers
|
||||
@procedure.dossiers.where.not(state: :draft)
|
||||
@procedure.dossiers.state_not_brouillon
|
||||
end
|
||||
|
||||
def dossiers_for_pie_highchart
|
||||
dossiers.where.not(state: :draft, archived: true).group(:state).count
|
||||
dossiers.state_not_brouillon.not_archived.group(:state).count
|
||||
.reduce({}) do |acc, (key, val)|
|
||||
translated_key = DossierDecorator.case_state_fr(key)
|
||||
acc[translated_key].nil? ? acc[translated_key] = val : acc[translated_key] += val
|
||||
|
@ -21,11 +21,11 @@ class AdminProceduresShowFacades
|
|||
end
|
||||
|
||||
def dossiers_archived_by_state_total
|
||||
dossiers.select('state, count(*) as total').where(archived: true).where.not(state: :termine).group(:state).order(:state).decorate
|
||||
dossiers.select('state, count(*) as total').archived.where.not(state: :termine).group(:state).order(:state).decorate
|
||||
end
|
||||
|
||||
def dossiers_archived_total
|
||||
dossiers.where(archived: true).where.not(state: :termine).size
|
||||
dossiers.archived.where.not(state: :termine).size
|
||||
end
|
||||
|
||||
def dossiers_total
|
||||
|
|
|
@ -14,7 +14,7 @@ class DossiersListFacades
|
|||
end
|
||||
|
||||
def total_dossier
|
||||
current_devise_profil.dossiers.where(archived: false).count
|
||||
current_devise_profil.dossiers.not_archived.count
|
||||
end
|
||||
|
||||
def total_dossier_follow
|
||||
|
@ -22,11 +22,11 @@ class DossiersListFacades
|
|||
end
|
||||
|
||||
def total_new_dossier
|
||||
current_devise_profil.dossiers.where(state: :initiated, archived: false).count
|
||||
current_devise_profil.dossiers.state_nouveaux.not_archived.count
|
||||
end
|
||||
|
||||
def new_dossier_number procedure_id
|
||||
current_devise_profil.dossiers.where(state: :initiated, archived: false, procedure_id: procedure_id).count
|
||||
current_devise_profil.dossiers.state_nouveaux.not_archived.where(procedure_id: procedure_id).count
|
||||
end
|
||||
|
||||
def gestionnaire_procedures_name_and_id_list
|
||||
|
|
|
@ -8,7 +8,7 @@ class Gestionnaire < ActiveRecord::Base
|
|||
|
||||
has_many :assign_to, dependent: :destroy
|
||||
has_many :procedures, through: :assign_to
|
||||
has_many :dossiers, -> { where.not(state: :draft) }, through: :procedures
|
||||
has_many :dossiers, -> { state_not_brouillon }, through: :procedures
|
||||
has_many :followed_dossiers, through: :follows, source: :dossier
|
||||
has_many :follows
|
||||
has_many :preference_list_dossiers
|
||||
|
@ -108,8 +108,7 @@ class Gestionnaire < ActiveRecord::Base
|
|||
start_date = DateTime.now.beginning_of_week
|
||||
|
||||
active_procedure_overviews = procedures
|
||||
.where(published: true)
|
||||
.all
|
||||
.published
|
||||
.map { |procedure| procedure.procedure_overview(start_date) }
|
||||
.select(&:had_some_activities?)
|
||||
|
||||
|
|
|
@ -32,6 +32,9 @@ class Procedure < ActiveRecord::Base
|
|||
mount_uploader :logo, ProcedureLogoUploader
|
||||
|
||||
default_scope { where(hidden_at: nil) }
|
||||
scope :published, -> { where(published: true) }
|
||||
scope :not_published, -> { where(published: false) }
|
||||
scope :archived, -> { where(archived: true) }
|
||||
scope :not_archived, -> { where(archived: false) }
|
||||
scope :by_libelle, -> { order(libelle: :asc) }
|
||||
|
||||
|
@ -61,7 +64,7 @@ class Procedure < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.active id
|
||||
not_archived.where(published: true).find(id)
|
||||
not_archived.published.find(id)
|
||||
end
|
||||
|
||||
def switch_types_de_champ index_of_first_element
|
||||
|
@ -127,7 +130,7 @@ class Procedure < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def total_dossier
|
||||
self.dossiers.where.not(state: :draft).size
|
||||
self.dossiers.state_not_brouillon.size
|
||||
end
|
||||
|
||||
def generate_export
|
||||
|
|
|
@ -46,8 +46,8 @@ class Search < ActiveRecord::Base
|
|||
|
||||
dossier_ids = @gestionnaire.dossiers
|
||||
.select(:id)
|
||||
.where(archived: false)
|
||||
.where.not(state: "draft")
|
||||
.not_archived
|
||||
.state_not_brouillon
|
||||
|
||||
q = Search
|
||||
.select("DISTINCT(searches.dossier_id)")
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
= admin.last_sign_in_at.localtime.strftime('%d/%m/%Y')
|
||||
)
|
||||
%td
|
||||
= admin.procedures.where(published: true).count
|
||||
= admin.procedures.published.count
|
||||
%td
|
||||
- total_dossier = 0
|
||||
- admin.procedures.each do |procedure| total_dossier += procedure.dossiers.where.not(state: :draft).count end
|
||||
- admin.procedures.each do |procedure| total_dossier += procedure.dossiers.state_not_brouillon.count end
|
||||
= total_dossier
|
||||
= smart_listing.paginate
|
||||
= smart_listing.pagination_per_page_links
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
%data.mj-w-data{ "data-apikey" => "1v5T", "data-base" => "https://app.mailjet.com", "data-height" => "328", "data-lang" => "fr_FR", "data-statics" => "statics", "data-token" => "11c89e7ddb46fbcdcb7f8fe5fdfca818", "data-w-id" => "39b", "data-width" => "640" }
|
||||
%script{ src: 'https://app.mailjet.com/statics/js/widget.modal.js' }
|
||||
%script{ src: 'https://app.mailjet.com/statics/js/widget.modal.js', 'data-turbolinks-eval': 'false' }
|
||||
|
|
|
@ -13,19 +13,19 @@
|
|||
.procedure-list-element{ class: @draft_class }
|
||||
Brouillons
|
||||
.badge.progress-bar-default
|
||||
= current_administrateur.procedures.where(published: false, archived: false).count
|
||||
= current_administrateur.procedures.not_published.not_archived.count
|
||||
|
||||
%a#active-procedures{ :href => "#{url_for :admin_procedures}" }
|
||||
.procedure-list-element{ class: @active_class }
|
||||
Actives
|
||||
.badge.progress-bar-success
|
||||
= current_administrateur.procedures.where(published: true, archived: false).count
|
||||
= current_administrateur.procedures.published.not_archived.count
|
||||
|
||||
%a#archived-procedures{ :href => "#{url_for :admin_procedures_archived}" }
|
||||
.procedure-list-element{ class: @archived_class }
|
||||
Archivées
|
||||
.badge.progress-bar-purple
|
||||
= current_administrateur.procedures.where(archived: true).count
|
||||
= current_administrateur.procedures.archived.count
|
||||
|
||||
.split-hr-left
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
= render partial: "layouts/mailjet_newsletter"
|
||||
= render partial: "layouts/crisp"
|
||||
|
||||
= javascript_include_tag "new_design/application", "data-turbolinks-track": true
|
||||
= javascript_include_tag "new_design/application", "data-turbolinks-eval": false
|
||||
= yield :charts_js
|
||||
- if Rails.env == "test"
|
||||
%script{ type: "text/javascript" }
|
||||
|
|
|
@ -80,7 +80,7 @@
|
|||
%ul.numbers
|
||||
%li.number
|
||||
.number-value
|
||||
= number_with_delimiter(Procedure.where(:published => true).count, :locale => :fr)
|
||||
= number_with_delimiter(Procedure.published.count, :locale => :fr)
|
||||
.number-label<
|
||||
procédures
|
||||
%br<>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Backoffice::CommentairesController, type: :controller do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:dossier) { create(:dossier, :replied) }
|
||||
let(:dossier_id) { dossier.id }
|
||||
let(:email_commentaire) { 'test@test.com' }
|
||||
let(:texte_commentaire) { 'Commentaire de test' }
|
||||
|
@ -16,116 +16,136 @@ describe Backoffice::CommentairesController, type: :controller do
|
|||
sign_in gestionnaire
|
||||
end
|
||||
|
||||
context "création correct d'un commentaire" do
|
||||
subject { post :create, params: {dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire} }
|
||||
context "when gestionnaire has no access to dossier" do
|
||||
subject { post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire } }
|
||||
|
||||
it 'depuis la page admin' do
|
||||
expect(subject).to redirect_to("/backoffice/dossiers/#{dossier_id}")
|
||||
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
|
||||
it { expect { subject rescue nil }.to change(Commentaire, :count).by(0) }
|
||||
end
|
||||
|
||||
context "when gestionnaire is invited for avis on dossier" do
|
||||
subject { post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire } }
|
||||
before { Avis.create(dossier: dossier, gestionnaire: gestionnaire, claimant: create(:gestionnaire)) }
|
||||
|
||||
it { expect{ subject }.to change(Commentaire, :count).by(1) }
|
||||
end
|
||||
|
||||
context "when gestionnaire has access to dossier" do
|
||||
before do
|
||||
gestionnaire.procedures << dossier.procedure
|
||||
end
|
||||
|
||||
it 'gestionnaire is automatically affect to follow the dossier' do
|
||||
expect { subject }.to change(Follow, :count).by(1)
|
||||
end
|
||||
context "création correct d'un commentaire" do
|
||||
subject { post :create, params: {dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire} }
|
||||
|
||||
context 'when gestionnaire already follow dossier' do
|
||||
before do
|
||||
create :follow, gestionnaire_id: gestionnaire.id, dossier_id: dossier_id
|
||||
it 'depuis la page admin' do
|
||||
expect(subject).to redirect_to("/backoffice/dossiers/#{dossier_id}")
|
||||
end
|
||||
|
||||
it 'gestionnaire is automatically affect to follow the dossier' do
|
||||
expect { subject }.to change(Follow, :count).by(0)
|
||||
end
|
||||
end
|
||||
|
||||
it 'Internal notification is not create' do
|
||||
expect { subject }.to change(Notification, :count).by (0)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when document is upload whith a commentaire', vcr: {cassette_name: 'controllers_backoffice_commentaires_controller_doc_upload_with_comment'} do
|
||||
let(:document_upload) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
|
||||
|
||||
subject do
|
||||
post :create, params: {dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire, piece_justificative: {content: document_upload}}
|
||||
end
|
||||
|
||||
it 'create a new piece justificative' do
|
||||
expect { subject }.to change(PieceJustificative, :count).by(1)
|
||||
end
|
||||
|
||||
it 'clamav check the pj' do
|
||||
expect(ClamavService).to receive(:safe_file?)
|
||||
subject
|
||||
end
|
||||
|
||||
it 'Internal notification is not create' do
|
||||
expect { subject }.to change(Notification, :count).by (0)
|
||||
end
|
||||
|
||||
describe 'piece justificative created' do
|
||||
let(:pj) { PieceJustificative.last }
|
||||
|
||||
before do
|
||||
subject
|
||||
expect { subject }.to change(Follow, :count).by(1)
|
||||
end
|
||||
|
||||
it 'not have a type de pj' do
|
||||
expect(pj.type_de_piece_justificative).to be_nil
|
||||
end
|
||||
|
||||
it 'content not be nil' do
|
||||
expect(pj.content).not_to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'commentaire created' do
|
||||
let(:commentaire) { Commentaire.last }
|
||||
|
||||
before do
|
||||
subject
|
||||
end
|
||||
|
||||
it 'have a piece justificative reference' do
|
||||
expect(commentaire.piece_justificative).not_to be_nil
|
||||
expect(commentaire.piece_justificative).to eq PieceJustificative.last
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'change dossier state after post a comment' do
|
||||
context 'gestionnaire is connected' do
|
||||
context 'when dossier is at state updated' do
|
||||
context 'when gestionnaire already follow dossier' do
|
||||
before do
|
||||
sign_in create(:gestionnaire)
|
||||
dossier.updated!
|
||||
|
||||
post :create, params: {dossier_id: dossier_id, texte_commentaire: texte_commentaire}
|
||||
dossier.reload
|
||||
create :follow, gestionnaire_id: gestionnaire.id, dossier_id: dossier_id
|
||||
end
|
||||
|
||||
subject { dossier.state }
|
||||
it 'gestionnaire is automatically affect to follow the dossier' do
|
||||
expect { subject }.to change(Follow, :count).by(0)
|
||||
end
|
||||
end
|
||||
|
||||
it { is_expected.to eq('replied') }
|
||||
it 'Internal notification is not create' do
|
||||
expect { subject }.to change(Notification, :count).by (0)
|
||||
end
|
||||
end
|
||||
|
||||
it 'Notification email is send' do
|
||||
expect(NotificationMailer).to receive(:new_answer).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_now!)
|
||||
context 'when document is upload whith a commentaire', vcr: {cassette_name: 'controllers_backoffice_commentaires_controller_doc_upload_with_comment'} do
|
||||
let(:document_upload) { Rack::Test::UploadedFile.new("./spec/support/files/piece_justificative_0.pdf", 'application/pdf') }
|
||||
|
||||
post :create, params: {dossier_id: dossier_id, texte_commentaire: texte_commentaire}
|
||||
subject do
|
||||
post :create, params: {dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire, piece_justificative: {content: document_upload}}
|
||||
end
|
||||
|
||||
it 'create a new piece justificative' do
|
||||
expect { subject }.to change(PieceJustificative, :count).by(1)
|
||||
end
|
||||
|
||||
it 'clamav check the pj' do
|
||||
expect(ClamavService).to receive(:safe_file?)
|
||||
subject
|
||||
end
|
||||
|
||||
it 'Internal notification is created' do
|
||||
expect { subject }.to change(Notification, :count).by (1)
|
||||
end
|
||||
|
||||
describe 'piece justificative created' do
|
||||
let(:pj) { PieceJustificative.last }
|
||||
|
||||
before do
|
||||
subject
|
||||
end
|
||||
|
||||
it 'not have a type de pj' do
|
||||
expect(pj.type_de_piece_justificative).to be_nil
|
||||
end
|
||||
|
||||
it 'content not be nil' do
|
||||
expect(pj.content).not_to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe 'commentaire created' do
|
||||
let(:commentaire) { Commentaire.last }
|
||||
|
||||
before do
|
||||
subject
|
||||
end
|
||||
|
||||
it 'have a piece justificative reference' do
|
||||
expect(commentaire.piece_justificative).not_to be_nil
|
||||
expect(commentaire.piece_justificative).to eq PieceJustificative.last
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'comment cannot be saved' do
|
||||
before do
|
||||
allow_any_instance_of(Commentaire).to receive(:save).and_return(false)
|
||||
describe 'change dossier state after post a comment' do
|
||||
context 'gestionnaire is connected' do
|
||||
context 'when dossier is at state updated' do
|
||||
before do
|
||||
sign_in gestionnaire
|
||||
dossier.updated!
|
||||
|
||||
post :create, params: {dossier_id: dossier_id, texte_commentaire: texte_commentaire}
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
subject { dossier.state }
|
||||
|
||||
it { is_expected.to eq('replied') }
|
||||
|
||||
it 'Notification email is send' do
|
||||
expect(NotificationMailer).to receive(:new_answer).and_return(NotificationMailer)
|
||||
expect(NotificationMailer).to receive(:deliver_now!)
|
||||
|
||||
post :create, params: {dossier_id: dossier_id, texte_commentaire: texte_commentaire}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
it 'Notification email is not sent' do
|
||||
expect(NotificationMailer).not_to receive(:new_answer)
|
||||
expect(NotificationMailer).not_to receive(:deliver_now!)
|
||||
|
||||
post :create, params: {dossier_id: dossier_id, texte_commentaire: texte_commentaire}
|
||||
describe 'comment cannot be saved' do
|
||||
before do
|
||||
allow_any_instance_of(Commentaire).to receive(:save).and_return(false)
|
||||
end
|
||||
it 'Notification email is not sent' do
|
||||
expect(NotificationMailer).not_to receive(:new_answer)
|
||||
expect(NotificationMailer).not_to receive(:deliver_now!)
|
||||
|
||||
post :create, params: {dossier_id: dossier_id, texte_commentaire: texte_commentaire}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,102 +1,154 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe InvitesController, type: :controller do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:dossier) { create(:dossier, :replied) }
|
||||
let(:email) { 'plop@octo.com' }
|
||||
|
||||
describe '#POST create' do
|
||||
let(:invite) { Invite.last }
|
||||
|
||||
before do
|
||||
sign_in create(:gestionnaire)
|
||||
sign_in signed_in_profile
|
||||
end
|
||||
|
||||
subject { post :create, params: {dossier_id: dossier.id, email: email} }
|
||||
|
||||
it { expect { subject }.to change(InviteGestionnaire, :count).by(1) }
|
||||
context "when gestionnaire is signed_in" do
|
||||
let(:signed_in_profile) { create(:gestionnaire) }
|
||||
|
||||
context 'when is a user who is loged' do
|
||||
before do
|
||||
sign_in create(:user)
|
||||
shared_examples_for "he can not create invitation" do
|
||||
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
|
||||
it { expect { subject rescue nil }.to change(InviteGestionnaire, :count).by(0) }
|
||||
end
|
||||
|
||||
it { expect { subject }.to change(InviteGestionnaire, :count).by(1) }
|
||||
end
|
||||
|
||||
context 'when email is assign to an user' do
|
||||
let! (:user) { create(:user, email: email) }
|
||||
|
||||
before do
|
||||
subject
|
||||
context 'when gestionnaire has no access to dossier' do
|
||||
it_behaves_like "he can not create invitation"
|
||||
end
|
||||
|
||||
describe 'Invite information' do
|
||||
let(:email) { 'PLIP@octo.com' }
|
||||
let(:invite) { Invite.last }
|
||||
context 'when gestionnaire is invited for avis on dossier' do
|
||||
before { Avis.create(gestionnaire: signed_in_profile, claimant: create(:gestionnaire), dossier: dossier) }
|
||||
|
||||
it 'email is on lower case' do
|
||||
expect(invite.email).to eq 'plip@octo.com'
|
||||
end
|
||||
it_behaves_like "he can not create invitation"
|
||||
end
|
||||
|
||||
it { expect(invite.user).to eq user }
|
||||
it { expect(flash[:notice]).to be_present }
|
||||
end
|
||||
|
||||
context 'when email is not assign to an user' do
|
||||
before do
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(invite.user).to be_nil }
|
||||
it { expect(flash[:notice]).to be_present }
|
||||
end
|
||||
|
||||
describe 'not an email' do
|
||||
context 'when email is not valid' do
|
||||
let(:email) { 'plip.com' }
|
||||
|
||||
context 'when gestionnaire has access to dossier' do
|
||||
before do
|
||||
subject
|
||||
signed_in_profile.procedures << dossier.procedure
|
||||
end
|
||||
|
||||
it { expect { subject }.not_to change(Invite, :count) }
|
||||
it { expect(flash[:alert]).to be_present }
|
||||
end
|
||||
it { expect { subject }.to change(InviteGestionnaire, :count).by(1) }
|
||||
|
||||
context 'when email is already used' do
|
||||
let!(:invite) { create(:invite, dossier: dossier) }
|
||||
context 'when is a user who is loged' do
|
||||
before do
|
||||
sign_in create(:user)
|
||||
end
|
||||
|
||||
before do
|
||||
subject
|
||||
it { expect { subject }.to change(InviteGestionnaire, :count).by(1) }
|
||||
end
|
||||
|
||||
it { expect { subject }.not_to change(Invite, :count) }
|
||||
it { expect(flash[:alert]).to be_present }
|
||||
context 'when email is assign to an user' do
|
||||
let! (:user) { create(:user, email: email) }
|
||||
|
||||
before do
|
||||
subject
|
||||
end
|
||||
|
||||
describe 'Invite information' do
|
||||
let(:email) { 'PLIP@octo.com' }
|
||||
let(:invite) { Invite.last }
|
||||
|
||||
it 'email is on lower case' do
|
||||
expect(invite.email).to eq 'plip@octo.com'
|
||||
end
|
||||
end
|
||||
|
||||
it { expect(invite.user).to eq user }
|
||||
it { expect(flash[:notice]).to be_present }
|
||||
end
|
||||
|
||||
context 'when email is not assign to an user' do
|
||||
before do
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(invite.user).to be_nil }
|
||||
it { expect(flash[:notice]).to be_present }
|
||||
end
|
||||
|
||||
describe 'not an email' do
|
||||
context 'when email is not valid' do
|
||||
let(:email) { 'plip.com' }
|
||||
|
||||
before do
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect { subject }.not_to change(Invite, :count) }
|
||||
it { expect(flash[:alert]).to be_present }
|
||||
end
|
||||
|
||||
context 'when email is already used' do
|
||||
let!(:invite) { create(:invite, dossier: dossier) }
|
||||
|
||||
before do
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect { subject }.not_to change(Invite, :count) }
|
||||
it { expect(flash[:alert]).to be_present }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'send invitation email' do
|
||||
context 'when user does not exist' do
|
||||
it 'send email' do
|
||||
expect(InviteMailer).to receive(:invite_guest).and_return(InviteMailer)
|
||||
expect(InviteMailer).to receive(:deliver_now!)
|
||||
|
||||
subject
|
||||
end
|
||||
end
|
||||
|
||||
context 'when user exist' do
|
||||
before do
|
||||
create :user, email: email
|
||||
end
|
||||
|
||||
it 'send email' do
|
||||
expect(InviteMailer).to receive(:invite_user).and_return(InviteMailer)
|
||||
expect(InviteMailer).to receive(:deliver_now!)
|
||||
|
||||
subject
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'send invitation email' do
|
||||
context 'when user does not exist' do
|
||||
it 'send email' do
|
||||
expect(InviteMailer).to receive(:invite_guest).and_return(InviteMailer)
|
||||
expect(InviteMailer).to receive(:deliver_now!)
|
||||
context "when user is signed_in" do
|
||||
let(:signed_in_profile) { create(:user) }
|
||||
|
||||
subject
|
||||
end
|
||||
shared_examples_for "he can not create a invite" do
|
||||
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
|
||||
it { expect { subject rescue nil }.to change(InviteUser, :count).by(0) }
|
||||
end
|
||||
|
||||
context 'when user exist' do
|
||||
context 'when user has no access to dossier' do
|
||||
it_behaves_like "he can not create a invite"
|
||||
end
|
||||
|
||||
context 'when user is invited on dossier' do
|
||||
before { Invite.create(user: signed_in_profile, email: signed_in_profile.email, dossier: dossier) }
|
||||
|
||||
it_behaves_like "he can not create a invite"
|
||||
end
|
||||
|
||||
context 'when user has access to dossier' do
|
||||
before do
|
||||
create :user, email: email
|
||||
dossier.update_attributes(user: signed_in_profile)
|
||||
end
|
||||
|
||||
it 'send email' do
|
||||
expect(InviteMailer).to receive(:invite_user).and_return(InviteMailer)
|
||||
expect(InviteMailer).to receive(:deliver_now!)
|
||||
|
||||
subject
|
||||
end
|
||||
it { expect { subject }.to change(InviteUser, :count).by(1) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,6 +11,28 @@ describe Users::CommentairesController, type: :controller do
|
|||
end
|
||||
|
||||
describe '#POST create' do
|
||||
context "when user has no access to dossier" do
|
||||
before do
|
||||
sign_in create(:user)
|
||||
end
|
||||
subject { post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire } }
|
||||
|
||||
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
|
||||
it { expect { subject rescue nil }.to change(Commentaire, :count).by(0) }
|
||||
end
|
||||
|
||||
context "when user is invited on dossier" do
|
||||
let(:user) { create(:user) }
|
||||
subject { post :create, params: { dossier_id: dossier_id, texte_commentaire: texte_commentaire } }
|
||||
|
||||
before do
|
||||
sign_in user
|
||||
InviteUser.create(dossier: dossier, user: user, email: user.email, email_sender: "test@test.com")
|
||||
end
|
||||
|
||||
it { expect{ subject }.to change(Commentaire, :count).by(1) }
|
||||
end
|
||||
|
||||
context 'création correct d\'un commentaire' do
|
||||
subject do
|
||||
sign_in dossier.user
|
||||
|
|
Loading…
Reference in a new issue