Remove ProcedurePath

This commit is contained in:
Paul Chavard 2018-10-25 17:40:23 +02:00
parent 46e5e0a4fd
commit 78dc582588
13 changed files with 13 additions and 144 deletions

View file

@ -9,7 +9,6 @@ class Procedure < ApplicationRecord
has_one :module_api_carto, dependent: :destroy has_one :module_api_carto, dependent: :destroy
has_one :attestation_template, dependent: :destroy has_one :attestation_template, dependent: :destroy
has_one :procedure_path, dependent: :destroy
belongs_to :administrateur belongs_to :administrateur
belongs_to :parent_procedure, class_name: 'Procedure' belongs_to :parent_procedure, class_name: 'Procedure'

View file

@ -1,36 +0,0 @@
class ProcedurePath < ApplicationRecord
validates :path, format: { with: /\A[a-z0-9_\-]{3,50}\z/ }, uniqueness: true, presence: true, allow_blank: false, allow_nil: false
validates :administrateur_id, presence: true, allow_blank: false, allow_nil: false
validates :procedure_id, presence: true, allow_blank: false, allow_nil: false
belongs_to :procedure
belongs_to :administrateur
def self.valid?(procedure, path)
create_with(procedure: procedure, administrateur: procedure.administrateur)
.find_or_initialize_by(path: path).validate
end
def self.mine?(administrateur, path)
procedure_path = find_by(path: path)
procedure_path && administrateur.owns?(procedure_path)
end
def self.find_with_path(path)
joins(:procedure)
.where.not(procedures: { aasm_state: :archivee })
.where("procedure_paths.path LIKE ?", "%#{path}%")
.order(:id)
end
def hide!
destroy!
end
def publish!(new_procedure)
if procedure&.publiee? && procedure != new_procedure
procedure.archive!
end
update!(procedure: new_procedure)
end
end

View file

@ -1,15 +0,0 @@
class ProcedurePathFormatValidator < ActiveModel::Validator
def path_regex
/^[a-z0-9_]{3,30}$/
end
def validate(record)
if record.path.blank?
return false
end
if !path_regex.match(record.path)
record.errors[:path] << "Path invalide"
end
end
end

View file

@ -2,6 +2,13 @@ fr:
activerecord: activerecord:
attributes: attributes:
procedure: procedure:
path: Lien
organisation: Organisme organisation: Organisme
duree_conservation_dossiers_dans_ds: Durée de conservation des dossiers sur demarches-simplifiees.fr duree_conservation_dossiers_dans_ds: Durée de conservation des dossiers sur demarches-simplifiees.fr
duree_conservation_dossiers_hors_ds: Durée de conservation des dossiers hors demarches-simplifiees.fr duree_conservation_dossiers_hors_ds: Durée de conservation des dossiers hors demarches-simplifiees.fr
errors:
models:
procedure:
attributes:
path:
format: Ce lien n'est pas valide. Il doit comporter au moins 3 caractères, au plus 50 caractères et seuls les caractères a-z, 0-9, '_' et '-' sont autorisés.

View file

@ -1,12 +0,0 @@
fr:
activerecord:
attributes:
procedure_path:
path: Lien
errors:
models:
procedure_path:
attributes:
path:
format: Ce lien n'est pas valide. Il doit comporter au moins 3 caractères, au plus 50 caractères et seuls les caractères a-z, 0-9, '_' et '-' sont autorisés.
taken: est déjà utilisé par une procédure.

View file

@ -27,11 +27,6 @@ namespace :support do
rake_puts("Changing owner of procedure ##{procedure_id} from ##{procedure.administrateur_id} to ##{new_owner.id}") rake_puts("Changing owner of procedure ##{procedure_id} from ##{procedure.administrateur_id} to ##{new_owner.id}")
procedure.update(administrateur: new_owner) procedure.update(administrateur: new_owner)
ProcedurePath.where(procedure_id: procedure_id).each do |pp|
rake_puts("Changing owner of procedure_path #{pp.path} from ##{pp.administrateur_id} to ##{new_owner.id}")
pp.update(administrateur: new_owner)
end
end end
desc <<~EOD desc <<~EOD
@ -74,13 +69,6 @@ namespace :support do
end end
procedures.update_all(administrateur_id: new_owner.id) procedures.update_all(administrateur_id: new_owner.id)
procedures.pluck(:id).each do |procedure_id|
ProcedurePath.where(procedure_id: procedure_id).each do |pp|
rake_puts("Changing owner of procedure_path #{pp.path} from ##{pp.administrateur_id} to ##{new_owner.id}")
pp.update(administrateur: new_owner)
end
end
end end
desc <<~EOD desc <<~EOD

View file

@ -3,7 +3,6 @@ require 'spec_helper'
describe ProcedureDecorator do describe ProcedureDecorator do
let(:published_at) { Time.zone.local(2017, 12, 24, 14, 12) } let(:published_at) { Time.zone.local(2017, 12, 24, 14, 12) }
let(:procedure) { create(:procedure, published_at: published_at, created_at: Time.zone.local(2015, 12, 24, 14, 10)) } let(:procedure) { create(:procedure, published_at: published_at, created_at: Time.zone.local(2015, 12, 24, 14, 10)) }
let!(:procedure_path) { create(:procedure_path, administrateur: create(:administrateur), procedure: procedure) }
subject { procedure.decorate } subject { procedure.decorate }

View file

@ -37,12 +37,7 @@ FactoryBot.define do
end end
trait :with_path do trait :with_path do
after(:create) do |procedure| path { generate(:published_path) }
create(:procedure_path,
procedure: procedure,
administrateur: procedure.administrateur,
path: generate(:published_path))
end
end end
trait :with_service do trait :with_service do

View file

@ -1,5 +0,0 @@
FactoryBot.define do
factory :procedure_path do
path { 'fake_path' }
end
end

View file

@ -129,7 +129,7 @@ feature 'The user' do
private private
def log_in(email, password, procedure) def log_in(email, password, procedure)
visit "/commencer/#{procedure.procedure_path.path}" visit "/commencer/#{procedure.path}"
expect(page).to have_current_path(new_user_session_path) expect(page).to have_current_path(new_user_session_path)
fill_in 'user_email', with: email fill_in 'user_email', with: email

View file

@ -47,7 +47,7 @@ feature 'linked dropdown lists' do
private private
def log_in(email, password, procedure) def log_in(email, password, procedure)
visit "/commencer/#{procedure.procedure_path.path}" visit "/commencer/#{procedure.path}"
expect(page).to have_current_path(new_user_session_path) expect(page).to have_current_path(new_user_session_path)
fill_in 'user_email', with: email fill_in 'user_email', with: email

View file

@ -1,49 +0,0 @@
require 'spec_helper'
describe ProcedurePath do
describe 'assocations' do
it { is_expected.to belong_to(:administrateur) }
it { is_expected.to belong_to(:procedure) }
end
describe 'attributes' do
it { is_expected.to have_db_column(:path) }
end
describe 'validation' do
describe 'path' do
let(:admin) { create(:administrateur) }
let(:procedure) { create(:procedure) }
let(:procedure_path) { create(:procedure_path, administrateur: admin, procedure: procedure, path: path) }
context 'when path is nil' do
let(:path) { nil }
it { expect{ procedure_path }.to raise_error ActiveRecord::RecordInvalid }
end
context 'when path is empty' do
let(:path) { '' }
it { expect{ procedure_path }.to raise_error ActiveRecord::RecordInvalid }
end
context 'when path contains spaces' do
let(:path) { 'Demande de subvention' }
it { expect{ procedure_path }.to raise_error ActiveRecord::RecordInvalid }
end
context 'when path contains alphanumerics and underscores' do
let(:path) { 'ma_super_procedure_1' }
it { expect{ procedure_path }.not_to raise_error }
end
context 'when path contains dashes' do
let(:path) { 'ma-super-procedure' }
it { expect{ procedure_path }.not_to raise_error }
end
context 'when path is too long' do
let(:path) { 'ma-super-procedure-12345678901234567890123456789012345678901234567890' }
it { expect{ procedure_path }.to raise_error ActiveRecord::RecordInvalid }
end
context 'when path is too short' do
let(:path) { 'pr' }
it { expect{ procedure_path }.to raise_error ActiveRecord::RecordInvalid }
end
end
end
end

View file

@ -439,9 +439,8 @@ describe Procedure do
it { expect(procedure.archived_at).to eq(nil) } it { expect(procedure.archived_at).to eq(nil) }
it { expect(procedure.published_at).to eq(now) } it { expect(procedure.published_at).to eq(now) }
it { expect(ProcedurePath.find_by(path: "example-path")).to be } it { expect(Procedure.find_by(path: "example-path")).to eq(procedure) }
it { expect(ProcedurePath.find_by(path: "example-path").procedure).to eq(procedure) } it { expect(Procedure.find_by(path: "example-path").administrateur).to eq(procedure.administrateur) }
it { expect(ProcedurePath.find_by(path: "example-path").administrateur).to eq(procedure.administrateur) }
end end
describe "#brouillon?" do describe "#brouillon?" do
@ -486,7 +485,6 @@ describe Procedure do
describe 'archive' do describe 'archive' do
let(:procedure) { create(:procedure, :published) } let(:procedure) { create(:procedure, :published) }
let(:procedure_path) { ProcedurePath.find(procedure.procedure_path.id) }
let(:now) { Time.zone.now.beginning_of_minute } let(:now) { Time.zone.now.beginning_of_minute }
before do before do
Timecop.freeze(now) Timecop.freeze(now)
@ -634,7 +632,7 @@ describe Procedure do
context "with a path" do context "with a path" do
let(:procedure) { create(:procedure, :published) } let(:procedure) { create(:procedure, :published) }
it { is_expected.to eq("dossiers_#{procedure.procedure_path.path}_2018-01-02_23-11") } it { is_expected.to eq("dossiers_#{procedure.path}_2018-01-02_23-11") }
end end
context "without a path" do context "without a path" do