diff --git a/app/controllers/new_administrateur/services_controller.rb b/app/controllers/new_administrateur/services_controller.rb index 4e1538fad..9e5d682a4 100644 --- a/app/controllers/new_administrateur/services_controller.rb +++ b/app/controllers/new_administrateur/services_controller.rb @@ -70,7 +70,7 @@ module NewAdministrateur private def service_params - params.require(:service).permit(:nom, :organisme, :type_organisme, :email, :telephone, :horaires, :adresse) + params.require(:service).permit(:nom, :organisme, :siret, :type_organisme, :email, :telephone, :horaires, :adresse) end def service diff --git a/app/models/service.rb b/app/models/service.rb index 2521a4f04..363190aa8 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -18,6 +18,7 @@ class Service < ApplicationRecord validates :nom, presence: { message: 'doit être renseigné' }, allow_nil: false validates :nom, uniqueness: { scope: :administrateur, message: 'existe déjà' } validates :organisme, presence: { message: 'doit être renseigné' }, allow_nil: false + validates :siret, length: { is: 14, message: 'doit être une suite de 14 chiffres' }, allow_nil: true validates :type_organisme, presence: { message: 'doit être renseigné' }, allow_nil: false validates :email, presence: { message: 'doit être renseigné' }, allow_nil: false validates :telephone, presence: { message: 'doit être renseigné' }, allow_nil: false diff --git a/app/views/new_administrateur/services/_form.html.haml b/app/views/new_administrateur/services/_form.html.haml index 80f50a57e..0fb2e0a3b 100644 --- a/app/views/new_administrateur/services/_form.html.haml +++ b/app/views/new_administrateur/services/_form.html.haml @@ -10,6 +10,16 @@ %span.mandatory * = f.text_field :organisme, placeholder: "mairie de Mours, préfecture de l'Oise, ministère de la Culture", required: true + = f.label :siret do + SIRET + %span.mandatory * + %p + Pour trouver votre numéro SIRET, utilisez + %a{ href: 'https://entreprise.data.gouv.fr/', target: '_blank' } + entreprise.data.gouv.fr + ou renseignez-vous auprès de votre service comptable + = f.number_field :siret, required: true + = f.label :type_organisme do Type d’organisme %span.mandatory * diff --git a/db/migrate/20180719125038_add_siret_to_services.rb b/db/migrate/20180719125038_add_siret_to_services.rb new file mode 100644 index 000000000..275be8b54 --- /dev/null +++ b/db/migrate/20180719125038_add_siret_to_services.rb @@ -0,0 +1,5 @@ +class AddSiretToServices < ActiveRecord::Migration[5.2] + def change + add_column :services, :siret, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 0dc4b2cc9..d756990b4 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: 2018_06_27_092237) do +ActiveRecord::Schema.define(version: 2018_07_19_125038) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -541,6 +541,7 @@ ActiveRecord::Schema.define(version: 2018_06_27_092237) do t.string "telephone" t.text "horaires" t.text "adresse" + t.string "siret" t.index ["administrateur_id", "nom"], name: "index_services_on_administrateur_id_and_nom", unique: true t.index ["administrateur_id"], name: "index_services_on_administrateur_id" end diff --git a/spec/controllers/new_administrateur/services_controller_spec.rb b/spec/controllers/new_administrateur/services_controller_spec.rb index c3fb96838..8bf213f79 100644 --- a/spec/controllers/new_administrateur/services_controller_spec.rb +++ b/spec/controllers/new_administrateur/services_controller_spec.rb @@ -13,6 +13,7 @@ describe NewAdministrateur::ServicesController, type: :controller do service: { nom: 'super service', organisme: 'organisme', + siret: '01234567891234', type_organisme: 'region', email: 'email@toto.com', telephone: '1234', @@ -27,6 +28,7 @@ describe NewAdministrateur::ServicesController, type: :controller do it { expect(flash.notice).to eq('super service créé') } it { expect(Service.last.nom).to eq('super service') } it { expect(Service.last.organisme).to eq('organisme') } + it { expect(Service.last.siret).to eq('01234567891234') } it { expect(Service.last.type_organisme).to eq('region') } it { expect(Service.last.email).to eq('email@toto.com') } it { expect(Service.last.telephone).to eq('1234') }