Merge pull request #107 from sgmap/procedure_path_can_contain_dashes

Procedure path can contain dashes
This commit is contained in:
gregoirenovel 2017-04-21 16:37:41 +02:00 committed by GitHub
commit 1d205e97b5
10 changed files with 44 additions and 11 deletions

View file

@ -52,7 +52,7 @@ function path_validation(el) {
}
function validatePath(path) {
var re = /^[a-z0-9_]{3,30}$/;
var re = /^[a-z0-9_\-]{3,50}$/;
return re.test(path);
}

View file

@ -53,7 +53,7 @@ class Procedure < ActiveRecord::Base
end
def default_path
libelle.downcase.gsub(/[^a-z0-9\-_]/, "_").gsub(/_*$/, '').gsub(/_+/, '_')
libelle.parameterize.first(50)
end
def types_de_champ_ordered

View file

@ -1,5 +1,5 @@
class ProcedurePath < ActiveRecord::Base
validates :path, procedure_path_format: true, presence: true, allow_blank: false, allow_nil: false
validates :path, format: { with: /\A[a-z0-9_\-]{3,50}\z/ }, 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

View file

@ -28,7 +28,7 @@
id: 'procedure_path',
placeholder: 'Chemin vers la procédure',
class: 'form-control',
maxlength: 30,
maxlength: 50,
style: 'width: 300px; display: inline;')
#path-messages
#path_is_mine.text-warning.center.message
@ -40,7 +40,7 @@
%br
Vous ne pouvez pas l'utiliser car il appartient à un autre administrateur.
#path_is_invalid.text-danger.center.message
Ce lien n'est pas valide. Il doit comporter au moins 3 caractères et seuls les caractères a-z, 0-9 et '_' sont autorisés.
= t('activerecord.errors.models.procedure_path.attributes.path.format')
.modal-footer
= submit_tag "#{@procedure.archived? ? 'Réactiver' : 'Publier'}", class: %w(btn btn btn-success),
id: 'publish',

View file

@ -0,0 +1,8 @@
fr:
activerecord:
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.

View file

@ -0,0 +1,5 @@
class RemoveFieldLimitForProcedurePaths < ActiveRecord::Migration[5.0]
def change
change_column :procedure_paths, :path, :string, limit: nil, null: true, unique: true, index: true
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170328142700) do
ActiveRecord::Schema.define(version: 20170414095411) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -319,7 +319,7 @@ ActiveRecord::Schema.define(version: 20170328142700) do
end
create_table "procedure_paths", force: :cascade do |t|
t.string "path", limit: 30
t.string "path"
t.integer "procedure_id"
t.integer "administrateur_id"
t.index ["path"], name: "index_procedure_paths_on_path", using: :btree

View file

@ -92,7 +92,7 @@ feature 'As an administrateur I wanna create a new procedure', js: true do
expect(page).to have_selector('#publish-procedure', visible: true)
page.find_by_id('publish-procedure').click
expect(page.find_by_id('procedure_path')['value']).to eq('libelle_de_la_procedure')
expect(page.find_by_id('procedure_path')['value']).to eq('libelle-de-la-procedure')
page.find_by_id('publish').click
expect(page).to have_selector('.procedure-lien')
end

View file

@ -24,14 +24,26 @@ describe ProcedurePath do
let(:path) { '' }
it { expect{procedure_path}.to raise_error ActiveRecord::RecordInvalid }
end
context 'when path is invalid' do
context 'when path contains spaces' do
let(:path) { 'Demande de subvention' }
it { expect{procedure_path}.to raise_error ActiveRecord::RecordInvalid }
end
context 'when path is valid' do
let(:path) { 'ma_super_procedure' }
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

View file

@ -284,4 +284,12 @@ describe Procedure do
it_behaves_like "export is empty"
end
end
describe '#default_path' do
let(:procedure){ create(:procedure, libelle: 'A long libelle with àccênts, blabla coucou hello un deux trois voila') }
subject { procedure.default_path }
it { is_expected.to eq('a-long-libelle-with-accents-blabla-coucou-hello-un') }
end
end