Merge branch 'dev'
This commit is contained in:
commit
7357ea796f
5 changed files with 52 additions and 2 deletions
|
@ -48,6 +48,8 @@ class Procedure < ApplicationRecord
|
|||
validates :description, presence: true, allow_blank: false, allow_nil: false
|
||||
validate :check_juridique
|
||||
|
||||
before_save :update_juridique_required
|
||||
|
||||
include AASM
|
||||
|
||||
aasm whiny_persistence: true do
|
||||
|
@ -343,6 +345,11 @@ class Procedure < ApplicationRecord
|
|||
|
||||
private
|
||||
|
||||
def update_juridique_required
|
||||
self.juridique_required ||= (cadre_juridique.present? || deliberation.attached?)
|
||||
true
|
||||
end
|
||||
|
||||
def clone_attachment(cloned_procedure, attachment_symbol)
|
||||
attachment = send(attachment_symbol)
|
||||
if attachment.attached?
|
||||
|
@ -357,7 +364,7 @@ class Procedure < ApplicationRecord
|
|||
end
|
||||
|
||||
def check_juridique
|
||||
if cadre_juridique.blank? && !deliberation.attached?
|
||||
if juridique_required? && (cadre_juridique.blank? && !deliberation.attached?)
|
||||
errors.add(:cadre_juridique, " : veuillez remplir le texte de loi ou la délibération")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddJuridiqueRequiredColumnToProcedure < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :procedures, :juridique_required, :boolean, default: true
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2018_05_30_095508) do
|
||||
ActiveRecord::Schema.define(version: 2018_06_01_084546) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -482,6 +482,7 @@ ActiveRecord::Schema.define(version: 2018_05_30_095508) do
|
|||
t.integer "duree_conservation_dossiers_dans_ds"
|
||||
t.integer "duree_conservation_dossiers_hors_ds"
|
||||
t.string "cadre_juridique"
|
||||
t.boolean "juridique_required", default: true
|
||||
t.index ["hidden_at"], name: "index_procedures_on_hidden_at"
|
||||
t.index ["parent_procedure_id"], name: "index_procedures_on_parent_procedure_id"
|
||||
t.index ["service_id"], name: "index_procedures_on_service_id"
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
namespace :'2018_06_01_optional_juridique_for_legacy_procedures' do
|
||||
task set: :environment do
|
||||
Procedure.all.update_all(juridique_required: false)
|
||||
end
|
||||
end
|
|
@ -193,6 +193,12 @@ describe Procedure do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when juridique_required is false' do
|
||||
let(:procedure) { build(:procedure, juridique_required: false, cadre_juridique: nil) }
|
||||
|
||||
it { expect(procedure.valid?).to eq(true) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#types_de_champ_ordered' do
|
||||
|
@ -671,4 +677,30 @@ describe Procedure do
|
|||
|
||||
it { expect(Champ.count).to eq(0) }
|
||||
end
|
||||
|
||||
describe '#juridique_required' do
|
||||
it 'automatically jumps to true once cadre_juridique or deliberation have been set' do
|
||||
p = create(
|
||||
:procedure,
|
||||
juridique_required: false,
|
||||
cadre_juridique: nil,
|
||||
)
|
||||
|
||||
expect(p.juridique_required).to be_falsey
|
||||
|
||||
p.update(cadre_juridique: 'cadre')
|
||||
expect(p.juridique_required).to be_truthy
|
||||
|
||||
p.update(cadre_juridique: nil)
|
||||
expect(p.juridique_required).to be_truthy
|
||||
|
||||
p.update_columns(cadre_juridique: nil, juridique_required: false)
|
||||
p.reload
|
||||
expect(p.juridique_required).to be_falsey
|
||||
|
||||
allow(p).to receive(:deliberation).and_return(double('attached?': true))
|
||||
p.save
|
||||
expect(p.juridique_required).to be_truthy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue