remove email_notifications_enabled column because of the new daily_email_notifications_enabled

This commit is contained in:
kara Diaby 2020-02-27 11:09:19 +01:00
parent 4934a6359b
commit 4a70a7fcc8
9 changed files with 14 additions and 16 deletions

View file

@ -232,7 +232,6 @@ module Instructeurs
def update_email_notifications def update_email_notifications
assign_to.update!(assign_to_params) assign_to.update!(assign_to_params)
assign_to.update!(daily_email_notifications_enabled: params[:assign_to][:email_notifications_enabled])
flash.notice = 'Vos notifications sont enregistrées.' flash.notice = 'Vos notifications sont enregistrées.'
redirect_to instructeur_procedure_path(procedure) redirect_to instructeur_procedure_path(procedure)
end end
@ -247,7 +246,7 @@ module Instructeurs
private private
def assign_to_params def assign_to_params
params.require(:assign_to).permit(:email_notifications_enabled, :weekly_email_notifications_enabled) params.require(:assign_to).permit(:daily_email_notifications_enabled, :weekly_email_notifications_enabled)
end end
def assign_exports def assign_exports

View file

@ -3,13 +3,8 @@ class AssignTo < ApplicationRecord
belongs_to :groupe_instructeur belongs_to :groupe_instructeur
has_one :procedure_presentation, dependent: :destroy has_one :procedure_presentation, dependent: :destroy
has_one :procedure, through: :groupe_instructeur has_one :procedure, through: :groupe_instructeur
before_save :save_to_new_daily_email_column
scope :with_email_notifications, -> { where(email_notifications_enabled: true) } scope :with_email_notifications, -> { where(daily_email_notifications_enabled: true) }
def save_to_new_daily_email_column
self.daily_email_notifications_enabled = email_notifications_enabled
end
def procedure_presentation_or_default_and_errors def procedure_presentation_or_default_and_errors
errors = reset_procedure_presentation_if_invalid errors = reset_procedure_presentation_if_invalid

View file

@ -3,7 +3,7 @@ class NotificationService
def send_instructeur_email_notification def send_instructeur_email_notification
Instructeur Instructeur
.includes(assign_to: { procedure: :dossiers }) .includes(assign_to: { procedure: :dossiers })
.where(assign_tos: { email_notifications_enabled: true }) .where(assign_tos: { daily_email_notifications_enabled: true })
.find_in_batches { |instructeurs| send_batch_of_instructeurs_email_notification(instructeurs) } .find_in_batches { |instructeurs| send_batch_of_instructeurs_email_notification(instructeurs) }
end end

View file

@ -20,11 +20,11 @@
.radios .radios
%label %label
= form.radio_button :email_notifications_enabled, true = form.radio_button :daily_email_notifications_enabled, true
Oui Oui
%label %label
= form.radio_button :email_notifications_enabled, false = form.radio_button :daily_email_notifications_enabled, false
Non Non
= form.label :email_notification, "Recevoir un récapitulatif hebdomadaire" = form.label :email_notification, "Recevoir un récapitulatif hebdomadaire"

View file

@ -0,0 +1,5 @@
class RemoveEmailNotificationsEnabledFromAssignTos < ActiveRecord::Migration[5.2]
def change
remove_column :assign_tos, :email_notifications_enabled
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: 2020_02_18_144724) do ActiveRecord::Schema.define(version: 2020_02_27_100001) 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"
@ -100,7 +100,6 @@ ActiveRecord::Schema.define(version: 2020_02_18_144724) do
t.integer "procedure_id" t.integer "procedure_id"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.boolean "email_notifications_enabled", default: false, null: false
t.bigint "groupe_instructeur_id" t.bigint "groupe_instructeur_id"
t.boolean "weekly_email_notifications_enabled", default: true, null: false t.boolean "weekly_email_notifications_enabled", default: true, null: false
t.boolean "daily_email_notifications_enabled", default: false, null: false t.boolean "daily_email_notifications_enabled", default: false, null: false

View file

@ -424,7 +424,7 @@ describe Instructeurs::ProceduresController, type: :controller do
let(:assign_to) { instructeur.assign_to.joins(:groupe_instructeur).find_by(groupe_instructeurs: { procedure: procedure }) } let(:assign_to) { instructeur.assign_to.joins(:groupe_instructeur).find_by(groupe_instructeurs: { procedure: procedure }) }
before do before do
patch :update_email_notifications, params: { procedure_id: procedure.id, assign_to: { id: assign_to.id, email_notifications_enabled: true } } patch :update_email_notifications, params: { procedure_id: procedure.id, assign_to: { id: assign_to.id, daily_email_notifications_enabled: true } }
end end
it { expect(instructeur.groupe_instructeur_with_email_notifications).to eq([procedure.defaut_groupe_instructeur]) } it { expect(instructeur.groupe_instructeur_with_email_notifications).to eq([procedure.defaut_groupe_instructeur]) }

View file

@ -384,7 +384,7 @@ describe Instructeur, type: :model do
let(:procedure_to_assign) { create(:procedure) } let(:procedure_to_assign) { create(:procedure) }
before do before do
create(:assign_to, instructeur: instructeur, procedure: procedure_to_assign, email_notifications_enabled: true, groupe_instructeur: procedure_to_assign.defaut_groupe_instructeur) create(:assign_to, instructeur: instructeur, procedure: procedure_to_assign, daily_email_notifications_enabled: true, groupe_instructeur: procedure_to_assign.defaut_groupe_instructeur)
end end
context 'when a dossier in construction exists' do context 'when a dossier in construction exists' do

View file

@ -28,7 +28,7 @@ describe NotificationService do
create(:assign_to, create(:assign_to,
instructeur: instructeur_with_email_notifications, instructeur: instructeur_with_email_notifications,
procedure: procedure, procedure: procedure,
email_notifications_enabled: true) daily_email_notifications_enabled: true)
end end
context "when there is no activity on the instructeur's procedures" do context "when there is no activity on the instructeur's procedures" do