poc(batch_operation): habtm groupe instructeurs, permettra de visualiser plus facilement les batch en cours pour les instructeurs du meme groupe
This commit is contained in:
parent
eaf72162da
commit
e5944eed34
8 changed files with 39 additions and 4 deletions
|
@ -4,7 +4,7 @@ module Instructeurs
|
|||
before_action :ensure_ownership!
|
||||
|
||||
def create
|
||||
BatchOperation.safe_create!(batch_operation_params.merge(instructeur: current_instructeur))
|
||||
BatchOperation.safe_create!(batch_operation_params)
|
||||
redirect_back(fallback_location: instructeur_procedure_url(@procedure.id))
|
||||
end
|
||||
|
||||
|
@ -13,6 +13,8 @@ module Instructeurs
|
|||
def batch_operation_params
|
||||
params.require(:batch_operation)
|
||||
.permit(:operation, dossier_ids: [])
|
||||
.merge(instructeur: current_instructeur)
|
||||
.merge(groupe_instructeurs: current_instructeur.groupe_instructeurs.where(procedure_id: @procedure.id))
|
||||
end
|
||||
|
||||
def set_procedure
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
# operation :string not null
|
||||
# payload :jsonb not null
|
||||
# run_at :datetime
|
||||
# seen_at :datetime
|
||||
# success_dossier_ids :bigint default([]), not null, is an Array
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
|
@ -20,6 +21,7 @@ class BatchOperation < ApplicationRecord
|
|||
}
|
||||
|
||||
has_many :dossiers, dependent: :nullify
|
||||
has_and_belongs_to_many :groupe_instructeurs
|
||||
belongs_to :instructeur
|
||||
|
||||
validates :operation, presence: true
|
||||
|
|
|
@ -18,6 +18,7 @@ class GroupeInstructeur < ApplicationRecord
|
|||
has_many :deleted_dossiers
|
||||
has_and_belongs_to_many :exports, dependent: :destroy
|
||||
has_and_belongs_to_many :bulk_messages, dependent: :destroy
|
||||
has_and_belongs_to_many :batch_operations, dependent: :destroy
|
||||
|
||||
validates :label, presence: true, allow_nil: false
|
||||
validates :label, uniqueness: { scope: :procedure }
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
class CreateBatchOperationGroupeInstructeurJoinTable < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
safety_assured do
|
||||
create_table "batch_operations_groupe_instructeurs", force: :cascade do |t|
|
||||
t.bigint "batch_operation_id", null: false
|
||||
t.bigint "groupe_instructeur_id", null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class AddSeenAtToBatchOperations < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
add_column :batch_operations, :seen_at, :datetime
|
||||
end
|
||||
end
|
11
db/schema.rb
11
db/schema.rb
|
@ -10,7 +10,8 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2022_11_30_113745) do
|
||||
ActiveRecord::Schema.define(version: 2022_12_01_091658) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pgcrypto"
|
||||
enable_extension "plpgsql"
|
||||
|
@ -165,10 +166,18 @@ ActiveRecord::Schema.define(version: 2022_11_30_113745) do
|
|||
t.string "operation", null: false
|
||||
t.jsonb "payload", default: {}, null: false
|
||||
t.datetime "run_at"
|
||||
t.datetime "seen_at"
|
||||
t.bigint "success_dossier_ids", default: [], null: false, array: true
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
end
|
||||
|
||||
create_table "batch_operations_groupe_instructeurs", force: :cascade do |t|
|
||||
t.bigint "batch_operation_id", null: false
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.bigint "groupe_instructeur_id", null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
end
|
||||
|
||||
create_table "bill_signatures", force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.string "digest"
|
||||
|
|
|
@ -32,9 +32,12 @@ describe Instructeurs::BatchOperationsController, type: :controller do
|
|||
it 'creates a batch operation for our signed in instructeur' do
|
||||
expect { subject }.to change { instructeur.batch_operations.count }.by(1)
|
||||
end
|
||||
it 'created a batch operation contains dossiers' do
|
||||
it 'created a batch operation contains dossiers, instructeur, groupe_instructeur' do
|
||||
subject
|
||||
expect(BatchOperation.first.dossiers).to include(dossier)
|
||||
batch_operation = BatchOperation.first
|
||||
expect(batch_operation.dossiers).to include(dossier)
|
||||
expect(batch_operation.instructeur).to eq(instructeur)
|
||||
expect(batch_operation.groupe_instructeurs.to_a).to eq(instructeur.groupe_instructeurs.to_a)
|
||||
end
|
||||
it 'enqueues a BatchOperationJob' do
|
||||
expect { subject }.to have_enqueued_job(BatchOperationEnqueueAllJob).with(BatchOperation.last)
|
||||
|
|
|
@ -2,6 +2,7 @@ describe BatchOperation, type: :model do
|
|||
describe 'association' do
|
||||
it { is_expected.to have_many(:dossiers) }
|
||||
it { is_expected.to belong_to(:instructeur) }
|
||||
it { is_expected.to have_and_belong_to_many(:groupe_instructeurs) }
|
||||
end
|
||||
|
||||
describe 'attributes' do
|
||||
|
|
Loading…
Reference in a new issue