Merge branch 'dev'

This commit is contained in:
Simon Lehericey 2017-07-18 16:07:12 +02:00
commit d027330bb6
4 changed files with 20 additions and 12 deletions

View file

@ -0,0 +1,7 @@
class AddUniqConstraintOnGestionnaireDossierCouple < ActiveRecord::Migration[5.0]
def up
change_column_null :follows, :gestionnaire_id, false
change_column_null :follows, :dossier_id, false
add_index :follows, [:gestionnaire_id, :dossier_id], unique: true
end
end

View file

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170711125726) do ActiveRecord::Schema.define(version: 20170713151123) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -230,9 +230,10 @@ ActiveRecord::Schema.define(version: 20170711125726) do
end end
create_table "follows", force: :cascade do |t| create_table "follows", force: :cascade do |t|
t.integer "gestionnaire_id" t.integer "gestionnaire_id", null: false
t.integer "dossier_id" t.integer "dossier_id", null: false
t.index ["dossier_id"], name: "index_follows_on_dossier_id", using: :btree t.index ["dossier_id"], name: "index_follows_on_dossier_id", using: :btree
t.index ["gestionnaire_id", "dossier_id"], name: "index_follows_on_gestionnaire_id_and_dossier_id", unique: true, using: :btree
t.index ["gestionnaire_id"], name: "index_follows_on_gestionnaire_id", using: :btree t.index ["gestionnaire_id"], name: "index_follows_on_gestionnaire_id", using: :btree
end end

View file

@ -488,11 +488,11 @@ describe Dossier do
context 'when dossier is followed' do context 'when dossier is followed' do
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private) } let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private) }
let(:gestionnaire) { create(:gestionnaire) } let(:gestionnaire) { create(:gestionnaire) }
let(:follow) { create(:follow, gestionnaire: gestionnaire) }
let(:date1) { 1.day.ago } let(:date1) { 1.day.ago }
let(:date2) { 1.hour.ago } let(:date2) { 1.hour.ago }
let(:date3) { 1.minute.ago } let(:date3) { 1.minute.ago }
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure, follows: [follow], initiated_at: date1, received_at: date2, processed_at: date3, motivation: "Motivation") } let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure, initiated_at: date1, received_at: date2, processed_at: date3, motivation: "Motivation") }
let!(:follow) { create(:follow, gestionnaire: gestionnaire, dossier: dossier) }
describe '#export_headers' do describe '#export_headers' do
subject { dossier.export_headers } subject { dossier.export_headers }

View file

@ -3,26 +3,26 @@ require 'spec_helper'
describe DossierTableExportSerializer do describe DossierTableExportSerializer do
describe '#emails_accompagnateurs' do describe '#emails_accompagnateurs' do
let(:gestionnaire){ create(:gestionnaire) } let(:gestionnaire){ create(:gestionnaire) }
let(:follow) { create(:follow, gestionnaire: gestionnaire) } let(:gestionnaire2) { create :gestionnaire}
let(:dossier) { create(:dossier) }
subject { DossierTableExportSerializer.new(dossier).emails_accompagnateurs } subject { DossierTableExportSerializer.new(dossier).emails_accompagnateurs }
context 'when there is no accompagnateurs' do context 'when there is no accompagnateurs' do
let(:dossier) { create(:dossier, follows: []) }
it { is_expected.to eq('') } it { is_expected.to eq('') }
end end
context 'when there one accompagnateur' do context 'when there one accompagnateur' do
let(:dossier) { create(:dossier, follows: [follow]) } before { gestionnaire.followed_dossiers << dossier }
it { is_expected.to eq(gestionnaire.email) } it { is_expected.to eq(gestionnaire.email) }
end end
context 'when there is 2 followers' do context 'when there is 2 followers' do
let(:gestionnaire2) { create :gestionnaire} before do
let(:follow2) { create(:follow, gestionnaire: gestionnaire2) } gestionnaire.followed_dossiers << dossier
let(:dossier) { create(:dossier, follows: [follow, follow2]) } gestionnaire2.followed_dossiers << dossier
end
it { is_expected.to eq "#{gestionnaire.email} #{gestionnaire2.email}" } it { is_expected.to eq "#{gestionnaire.email} #{gestionnaire2.email}" }
end end