diff --git a/app/models/procedure.rb b/app/models/procedure.rb index a93d73a5f..b9760fa41 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -66,7 +66,7 @@ class Procedure < ApplicationRecord validates :description, presence: true, allow_blank: false, allow_nil: false validates :administrateurs, presence: true validate :check_juridique - validates :path, format: { with: /\A[a-z0-9_\-]{3,50}\z/ }, uniqueness: { scope: :aasm_state, case_sensitive: false }, presence: true, allow_blank: false, allow_nil: true + validates :path, presence: true, format: { with: /\A[a-z0-9_\-]{3,50}\z/ }, uniqueness: { scope: [:path, :archived_at, :hidden_at], case_sensitive: false } # FIXME: remove duree_conservation_required flag once all procedures are converted to the new style validates :duree_conservation_dossiers_dans_ds, allow_nil: false, numericality: { only_integer: true, greater_than_or_equal_to: 1, less_than_or_equal_to: MAX_DUREE_CONSERVATION }, if: :durees_conservation_required validates :duree_conservation_dossiers_hors_ds, allow_nil: false, numericality: { only_integer: true, greater_than_or_equal_to: 0 }, if: :durees_conservation_required diff --git a/db/migrate/20190917151652_make_path_nonnull.rb b/db/migrate/20190917151652_make_path_nonnull.rb new file mode 100644 index 000000000..401a13c84 --- /dev/null +++ b/db/migrate/20190917151652_make_path_nonnull.rb @@ -0,0 +1,6 @@ +class MakePathNonnull < ActiveRecord::Migration[5.2] + def change + change_column_null :procedures, :path, false + add_index :procedures, [:path, :archived_at, :hidden_at], unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 330d17d99..9914c4180 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2019_09_17_120856) do +ActiveRecord::Schema.define(version: 2019_09_17_151652) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -480,12 +480,13 @@ ActiveRecord::Schema.define(version: 2019_09_17_120856) do t.string "cadre_juridique" t.boolean "juridique_required", default: true t.boolean "durees_conservation_required", default: true - t.string "path" + t.string "path", null: false t.string "declarative_with_state" t.text "monavis_embed" t.index ["declarative_with_state"], name: "index_procedures_on_declarative_with_state" t.index ["hidden_at"], name: "index_procedures_on_hidden_at" t.index ["parent_procedure_id"], name: "index_procedures_on_parent_procedure_id" + t.index ["path", "archived_at", "hidden_at"], name: "index_procedures_on_path_and_archived_at_and_hidden_at", unique: true t.index ["service_id"], name: "index_procedures_on_service_id" end diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index 118b1c7d5..23b32efa7 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -11,6 +11,7 @@ FactoryBot.define do duree_conservation_dossiers_hors_ds { 6 } ask_birthday { false } lien_site_web { "https://mon-site.gouv" } + path { SecureRandom.uuid } transient do administrateur {}