2015-08-17 11:43:01 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Commentaire do
|
|
|
|
it { is_expected.to have_db_column(:email) }
|
|
|
|
it { is_expected.to have_db_column(:body) }
|
|
|
|
it { is_expected.to have_db_column(:created_at) }
|
|
|
|
it { is_expected.to have_db_column(:updated_at) }
|
|
|
|
it { is_expected.to belong_to(:dossier) }
|
2016-04-20 16:51:57 +02:00
|
|
|
|
2019-07-01 18:14:02 +02:00
|
|
|
describe 'messagerie_available validation' do
|
|
|
|
subject { commentaire.valid?(:create) }
|
|
|
|
|
|
|
|
context 'with a commentaire created by the DS system' do
|
|
|
|
let(:commentaire) { build :commentaire, email: CONTACT_EMAIL }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on an archived dossier' do
|
|
|
|
let(:dossier) { create :dossier, :archived }
|
|
|
|
let(:commentaire) { build :commentaire, dossier: dossier }
|
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on a dossier en_construction' do
|
|
|
|
let(:dossier) { create :dossier, :en_construction }
|
|
|
|
let(:commentaire) { build :commentaire, dossier: dossier }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#sent_by_system?" do
|
|
|
|
subject { commentaire.sent_by_system? }
|
2019-07-01 18:14:02 +02:00
|
|
|
|
|
|
|
let(:commentaire) { build :commentaire, email: email }
|
|
|
|
|
|
|
|
context 'with a commentaire created by the DS system' do
|
|
|
|
let(:email) { CONTACT_EMAIL }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-01 18:14:02 +02:00
|
|
|
describe "#redacted_email" do
|
|
|
|
subject { commentaire.redacted_email }
|
|
|
|
|
|
|
|
context 'with a commentaire created by a gestionnaire' do
|
|
|
|
let(:commentaire) { build :commentaire, gestionnaire: gestionnaire }
|
|
|
|
let(:gestionnaire) { build :gestionnaire, email: 'some_user@exemple.fr' }
|
|
|
|
|
|
|
|
it { is_expected.to eq 'some_user' }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a commentaire created by a user' do
|
|
|
|
let(:commentaire) { build :commentaire, user: user }
|
|
|
|
let(:user) { build :user, email: 'some_user@exemple.fr' }
|
|
|
|
|
|
|
|
it { is_expected.to eq 'some_user@exemple.fr' }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-12 13:32:48 +02:00
|
|
|
describe "#notify" do
|
|
|
|
let(:procedure) { create(:procedure) }
|
|
|
|
let(:gestionnaire) { create(:gestionnaire) }
|
|
|
|
let(:assign_to) { create(:assign_to, gestionnaire: gestionnaire, procedure: procedure) }
|
|
|
|
let(:user) { create(:user) }
|
2019-07-01 18:14:02 +02:00
|
|
|
let(:dossier) { create(:dossier, :en_construction, procedure: procedure, user: user) }
|
2017-11-07 20:40:00 +01:00
|
|
|
let(:commentaire) { Commentaire.new(dossier: dossier, body: "Mon commentaire") }
|
2017-05-12 13:32:48 +02:00
|
|
|
|
|
|
|
context "with a commentaire created by a gestionnaire" do
|
|
|
|
it "calls notify_user" do
|
|
|
|
expect(commentaire).to receive(:notify_user)
|
|
|
|
|
|
|
|
commentaire.email = gestionnaire.email
|
|
|
|
commentaire.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with a commentaire automatically created (notification)" do
|
|
|
|
it "does not call notify_user or notify_gestionnaires" do
|
|
|
|
expect(commentaire).not_to receive(:notify_user)
|
|
|
|
expect(commentaire).not_to receive(:notify_gestionnaires)
|
|
|
|
|
2018-05-31 15:43:57 +02:00
|
|
|
commentaire.email = CONTACT_EMAIL
|
2017-05-12 13:32:48 +02:00
|
|
|
commentaire.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-08-20 17:30:17 +02:00
|
|
|
end
|