From 810395c428ee5a2e8c75b7379b72e71cfd3dd4a2 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Tue, 22 Sep 2015 13:58:32 +0200 Subject: [PATCH] Rename and remove attribut into Dossier --- app/controllers/carte_controller.rb | 4 +-- app/controllers/description_controller.rb | 2 +- app/controllers/recapitulatif_controller.rb | 3 ++- app/models/dossier.rb | 1 - app/views/admin/dossier/show.html.haml | 2 +- .../carte/_carte_sources_JS_backend.html.haml | 2 +- app/views/description/show.html.haml | 4 --- app/views/dossiers/_infos_dossier.html.haml | 7 ----- config/locales/models/dossier/fr.yml | 1 - ...50922113504_change_attributs_to_dossier.rb | 8 ++++++ db/schema.rb | 10 +++---- .../description_controller_spec.rb | 26 +++---------------- .../description_page/show_page_spec.rb | 15 +---------- .../upload_piece_justificative_spec.rb | 1 - spec/models/dossier_spec.rb | 7 ----- 15 files changed, 24 insertions(+), 69 deletions(-) create mode 100644 db/migrate/20150922113504_change_attributs_to_dossier.rb diff --git a/app/controllers/carte_controller.rb b/app/controllers/carte_controller.rb index 97a9c1788..d36f24d14 100644 --- a/app/controllers/carte_controller.rb +++ b/app/controllers/carte_controller.rb @@ -9,8 +9,8 @@ class CarteController < ApplicationController def save_ref_api_carto dossier = current_dossier - if dossier.ref_dossier.blank? - dossier.update_attributes(ref_dossier: params[:ref_dossier]) + if dossier.ref_dossier_carto.blank? + dossier.update_attributes(ref_dossier_carto: params[:ref_dossier]) redirect_to url_for(controller: :description, action: :show, dossier_id: params[:dossier_id]) else commentaire_params = { diff --git a/app/controllers/description_controller.rb b/app/controllers/description_controller.rb index e407fe332..7835f1e00 100644 --- a/app/controllers/description_controller.rb +++ b/app/controllers/description_controller.rb @@ -52,6 +52,6 @@ class DescriptionController < ApplicationController private def create_params - params.permit(:nom_projet, :description, :montant_projet, :montant_aide_demande, :date_previsionnelle, :lien_plus_infos, :mail_contact) + params.permit(:nom_projet, :description, :montant_projet, :montant_aide_demande, :date_previsionnelle) end end diff --git a/app/controllers/recapitulatif_controller.rb b/app/controllers/recapitulatif_controller.rb index 4d1e02e56..194cd0f0e 100644 --- a/app/controllers/recapitulatif_controller.rb +++ b/app/controllers/recapitulatif_controller.rb @@ -8,7 +8,8 @@ class RecapitulatifController < ApplicationController @commentaires = @commentaires.all.decorate - @commentaire_email = @dossier.mail_contact + #TODO load user email + @commentaire_email = 'user@email' rescue ActiveRecord::RecordNotFound redirect_to url_for(controller: :start, action: :error_dossier) end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index dd1455aa4..a4846cbda 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -14,7 +14,6 @@ class Dossier < ActiveRecord::Base after_save :build_default_pieces_justificatives, if: Proc.new { procedure_id_changed? } - validates :mail_contact, format: { with: /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/ }, unless: 'mail_contact.nil?' validates :nom_projet, presence: true, allow_blank: false, allow_nil: true validates :description, presence: true, allow_blank: false, allow_nil: true validates :montant_projet, presence: true, allow_blank: false, allow_nil: true diff --git a/app/views/admin/dossier/show.html.haml b/app/views/admin/dossier/show.html.haml index 1886e904b..3f91156f4 100644 --- a/app/views/admin/dossier/show.html.haml +++ b/app/views/admin/dossier/show.html.haml @@ -3,7 +3,7 @@ %script{type: 'text/javascript'} ="url_carte = '#{@dossier.id}/'" - ="ref_dossier = '#{@dossier.ref_dossier}'" + ="ref_dossier = '#{@dossier.ref_dossier_carto}'" = render partial: '/dossiers/infos_entreprise' %br diff --git a/app/views/carte/_carte_sources_JS_backend.html.haml b/app/views/carte/_carte_sources_JS_backend.html.haml index e9d961be2..cc0f8ce38 100644 --- a/app/views/carte/_carte_sources_JS_backend.html.haml +++ b/app/views/carte/_carte_sources_JS_backend.html.haml @@ -1,6 +1,6 @@ %script{type: 'text/javascript'} ="var dossier_id =#{@dossier.id}" - ="var ref_dossier=#{@dossier.ref_dossier}" + ="var ref_dossier=#{@dossier.ref_dossier_carto}" %div#sources_JS_api_carto_backend diff --git a/app/views/description/show.html.haml b/app/views/description/show.html.haml index 1868d421e..c109d31ef 100644 --- a/app/views/description/show.html.haml +++ b/app/views/description/show.html.haml @@ -33,10 +33,6 @@ %h4 Date prévisionnelle du début de votre projet * = text_field_tag :date_previsionnelle, @dossier.date_previsionnelle, placeholder: 'Date prévisionnelle', class: 'form-control', 'data-provide' => 'datepicker', 'data-date-format' => 'dd/mm/yyyy' - .col-lg-6.col-md-6 - %h4 Mail de contact * - = email_field_tag :mail_contact, @dossier.mail_contact, placeholder: 'Mail de contact', class: 'form-control' - %br %h3 Documents administratifs diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index c7ca90c76..c16d6f573 100644 --- a/app/views/dossiers/_infos_dossier.html.haml +++ b/app/views/dossiers/_infos_dossier.html.haml @@ -24,13 +24,6 @@ %p = @dossier.date_fr - .col-lg-6.col-md-6 - %br - %h4 Contact - - %a{ href: "mailto:#{@dossier.mail_contact}" } - = @dossier.mail_contact - -if !request.url.include?('admin') .col-lg-6.col-md-6 %br diff --git a/config/locales/models/dossier/fr.yml b/config/locales/models/dossier/fr.yml index 383373dde..56faa910b 100644 --- a/config/locales/models/dossier/fr.yml +++ b/config/locales/models/dossier/fr.yml @@ -4,7 +4,6 @@ fr: dossier: 'Dossier' attributes: dossier: - mail_contact: 'Le mail de contact' nom_projet: 'Le nom du projet' description: 'La description' montant_projet: 'Le montant du projet' diff --git a/db/migrate/20150922113504_change_attributs_to_dossier.rb b/db/migrate/20150922113504_change_attributs_to_dossier.rb new file mode 100644 index 000000000..f0db034e6 --- /dev/null +++ b/db/migrate/20150922113504_change_attributs_to_dossier.rb @@ -0,0 +1,8 @@ +class ChangeAttributsToDossier < ActiveRecord::Migration + def change + remove_column :dossiers, :lien_plus_infos + remove_column :dossiers, :mail_contact + + rename_column :dossiers, :ref_dossier, :ref_dossier_carto + end +end diff --git a/db/schema.rb b/db/schema.rb index 0433c7a4f..27b66f15f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150922110719) do +ActiveRecord::Schema.define(version: 20150922113504) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -38,17 +38,15 @@ ActiveRecord::Schema.define(version: 20150922110719) do t.boolean "autorisation_donnees" t.string "position_lat" t.string "position_lon" - t.string "ref_dossier" + t.string "ref_dossier_carto" t.string "nom_projet" t.string "montant_projet" t.string "montant_aide_demande" - t.string "lien_plus_infos" - t.string "mail_contact" t.boolean "dossier_termine" t.integer "procedure_id" t.date "date_previsionnelle" - t.datetime "created_at", default: '2015-09-22 09:25:29' - t.datetime "updated_at", default: '2015-09-22 09:25:29' + t.datetime "created_at" + t.datetime "updated_at" end add_index "dossiers", ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree diff --git a/spec/controllers/description_controller_spec.rb b/spec/controllers/description_controller_spec.rb index ba472659f..894378bd9 100644 --- a/spec/controllers/description_controller_spec.rb +++ b/spec/controllers/description_controller_spec.rb @@ -24,7 +24,6 @@ describe DescriptionController, type: :controller do let(:montant_projet) { 12_000 } let(:montant_aide_demande) { 3000 } let(:date_previsionnelle) { '20/01/2016' } - let(:mail_contact) { 'test@test.com' } let(:name_piece_justificative) { 'dossierPDF.pdf' } let(:name_piece_justificative_0) { 'piece_justificative_0.pdf' } @@ -37,14 +36,14 @@ describe DescriptionController, type: :controller do context 'Tous les attributs sont bons' do # TODO separer en deux tests : check donnees et check redirect it 'Premier enregistrement des données' do - post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle, mail_contact: mail_contact + post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle expect(response).to redirect_to("/dossiers/#{dossier_id}/recapitulatif") end # TODO changer les valeurs des champs et check in bdd context 'En train de modifier les données de description du projet' do before do - post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle, mail_contact: mail_contact, back_url: 'recapitulatif' + post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle, back_url: 'recapitulatif' end context 'Enregistrement d\'un commentaire informant la modification' do @@ -77,8 +76,7 @@ describe DescriptionController, type: :controller do description: description, montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, - date_previsionnelle: date_previsionnelle, - mail_contact: mail_contact + date_previsionnelle: date_previsionnelle } before { subject } @@ -111,20 +109,6 @@ describe DescriptionController, type: :controller do it { is_expected.to render_template(:show) } it { expect(flash[:alert]).to be_present } end - - it 'mail_contact manquant' do - post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle, mail_contact: '' - expect(response).to render_template('show') - expect(flash[:alert]).to be_present - end - end - - context 'Mauvais format(s)' do - it 'mail_contact n\'est un format d\'email' do - post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle, mail_contact: 'test.com' - expect(response).to render_template('show') - expect(flash[:alert]).to be_present - end end context 'Sauvegarde du CERFA PDF' do @@ -135,7 +119,6 @@ describe DescriptionController, type: :controller do montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle, - mail_contact: mail_contact, cerfa_pdf: cerfa_pdf dossier.reload end @@ -153,7 +136,7 @@ describe DescriptionController, type: :controller do context 'les anciens CERFA PDF sont écrasées à chaque fois' do it 'il n\'y a qu\'un CERFA PDF par dossier' do - post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle, mail_contact: mail_contact, cerfa_pdf: cerfa_pdf + post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle, cerfa_pdf: cerfa_pdf cerfa = PieceJustificative.where(type_de_piece_justificative_id: '0', dossier_id: dossier_id) expect(cerfa.many?).to eq(false) end @@ -173,7 +156,6 @@ describe DescriptionController, type: :controller do montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle, - mail_contact: mail_contact, 'piece_justificative_'+all_pj_type[0].to_s => piece_justificative_0, 'piece_justificative_'+all_pj_type[1].to_s => piece_justificative_1} dossier.reload diff --git a/spec/features/description_page/show_page_spec.rb b/spec/features/description_page/show_page_spec.rb index b72402987..226db6a9a 100644 --- a/spec/features/description_page/show_page_spec.rb +++ b/spec/features/description_page/show_page_spec.rb @@ -45,14 +45,6 @@ feature 'Description#Show Page' do expect(page).to have_selector('input[type=text][id=date_previsionnelle][data-provide=datepicker]') end - scenario 'Mail de contact' do - expect(page).to have_selector('input[id=mail_contact][name=mail_contact]') - end - - scenario 'Mail de contact est de type mail' do - expect(page).to have_selector('input[type=email][id=mail_contact]') - end - scenario 'Charger votre CERFA (PDF)' do expect(page).to have_selector('input[type=file][name=cerfa_pdf][id=cerfa_pdf]') end @@ -97,8 +89,7 @@ feature 'Description#Show Page' do description: 'Description de test', montant_projet: 12_000, montant_aide_demande: 3000, - date_previsionnelle: '20/01/2016', - mail_contact: 'test@test.com') + date_previsionnelle: '20/01/2016') end scenario 'Nom du projet' do @@ -120,10 +111,6 @@ feature 'Description#Show Page' do scenario 'Date prévisionnelle du projet' do expect(page).to have_selector("input[id=date_previsionnelle][value='#{dossier.date_previsionnelle}']") end - - scenario 'Mail de contact' do - expect(page).to have_selector("input[id=mail_contact][value='#{dossier.mail_contact}']") - end end context 'Pièces justificatives' do diff --git a/spec/features/description_page/upload_piece_justificative_spec.rb b/spec/features/description_page/upload_piece_justificative_spec.rb index 3612a9b9f..92ad922cc 100644 --- a/spec/features/description_page/upload_piece_justificative_spec.rb +++ b/spec/features/description_page/upload_piece_justificative_spec.rb @@ -14,7 +14,6 @@ feature 'user is on description page' do find_by_id('montant_projet').set 10_000 find_by_id('montant_aide_demande').set 100 find_by_id('date_previsionnelle').set '10/10/2010' - find_by_id('mail_contact').set 'plop@plop.com' end context 'before submit' do it 'dossier cerfa is empty' do diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 28ff0e1fd..e3928da5d 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -6,13 +6,10 @@ describe Dossier do it { is_expected.to have_db_column(:autorisation_donnees) } it { is_expected.to have_db_column(:position_lat) } it { is_expected.to have_db_column(:position_lon) } - it { is_expected.to have_db_column(:ref_dossier) } it { is_expected.to have_db_column(:nom_projet) } it { is_expected.to have_db_column(:montant_projet) } it { is_expected.to have_db_column(:montant_aide_demande) } it { is_expected.to have_db_column(:date_previsionnelle).of_type(:date) } - it { is_expected.to have_db_column(:lien_plus_infos) } - it { is_expected.to have_db_column(:mail_contact) } it { is_expected.to have_db_column(:dossier_termine) } it { is_expected.to have_db_column(:created_at) } it { is_expected.to have_db_column(:updated_at) } @@ -34,10 +31,6 @@ describe Dossier do end describe 'validation' do - context 'mail_contact' do - it { is_expected.to allow_value('tanguy@plop.com').for(:mail_contact) } - it { is_expected.not_to allow_value('tanguyplop.com').for(:mail_contact) } - end context 'nom_projet' do it { is_expected.to allow_value(nil).for(:nom_projet) } it { is_expected.not_to allow_value('').for(:nom_projet) }