From 866565495d135ccaf212cca6a42c143a82f8d81f Mon Sep 17 00:00:00 2001 From: Xavier J Date: Mon, 13 Jun 2016 12:03:05 +0200 Subject: [PATCH] Delete default description in dossier --- .../admin/procedures_controller.rb | 2 +- .../users/description_controller.rb | 2 +- app/models/dossier.rb | 1 - app/serializers/dossier_serializer.rb | 1 - app/views/admin/procedures/_onglets.html.haml | 2 +- app/views/dossiers/_infos_dossier.html.haml | 3 - app/views/users/description/_champs.html.haml | 8 ++- app/views/users/description/_show.html.haml | 5 -- ...7_delete_default_description_to_dossier.rb | 62 +++++++++++++++++++ db/schema.rb | 3 +- .../api/v1/dossiers_controller_spec.rb | 3 +- .../users/description_controller_spec.rb | 6 -- spec/factories/dossier.rb | 1 - .../upload_piece_justificative_spec.rb | 1 - spec/features/users/complete_demande_spec.rb | 1 - spec/models/dossier_spec.rb | 12 +--- .../previsualisations/show.html.haml_spec.rb | 9 --- .../users/description/show.html.haml_spec.rb | 9 --- 18 files changed, 75 insertions(+), 56 deletions(-) create mode 100644 db/migrate/20160609145737_delete_default_description_to_dossier.rb diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 461cf9ce0..4539cc02f 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -80,7 +80,7 @@ class Admin::ProceduresController < AdminController end def archive - change_status({archived: true}) + change_status({archived: params[:archive]}) end def active_class diff --git a/app/controllers/users/description_controller.rb b/app/controllers/users/description_controller.rb index fb6ecb930..ea9a9954f 100644 --- a/app/controllers/users/description_controller.rb +++ b/app/controllers/users/description_controller.rb @@ -94,6 +94,6 @@ class Users::DescriptionController < UsersController private def create_params - params.permit(:nom_projet, :description) + params.permit(:nom_projet) end end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 900b71fcb..7c00a303f 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -30,7 +30,6 @@ class Dossier < ActiveRecord::Base after_save :build_default_champs, if: Proc.new { procedure_id_changed? } validates :nom_projet, presence: true, allow_blank: false, allow_nil: true - validates :description, presence: true, allow_blank: false, allow_nil: true validates :user, presence: true WAITING_FOR_GESTIONNAIRE = %w(initiated updated submitted) diff --git a/app/serializers/dossier_serializer.rb b/app/serializers/dossier_serializer.rb index ad772388d..90b391f66 100644 --- a/app/serializers/dossier_serializer.rb +++ b/app/serializers/dossier_serializer.rb @@ -1,7 +1,6 @@ class DossierSerializer < ActiveModel::Serializer attributes :id, :nom_projet, - :description, :created_at, :updated_at, :archived, diff --git a/app/views/admin/procedures/_onglets.html.haml b/app/views/admin/procedures/_onglets.html.haml index 5c8e0a8c0..99835a39b 100644 --- a/app/views/admin/procedures/_onglets.html.haml +++ b/app/views/admin/procedures/_onglets.html.haml @@ -2,7 +2,7 @@ %ul.nav.nav-tabs %li{class: @draft_class} %a{:href => "#{url_for :admin_procedures_draft}"} - %h5{style: 'color: black'} + %h5.text-primary ="Brouillons" %li{class: @active_class} diff --git a/app/views/dossiers/_infos_dossier.html.haml b/app/views/dossiers/_infos_dossier.html.haml index a477395b5..f916f5dcb 100644 --- a/app/views/dossiers/_infos_dossier.html.haml +++ b/app/views/dossiers/_infos_dossier.html.haml @@ -6,9 +6,6 @@ %h4 = @facade.dossier.procedure.libelle - .description - = h @facade.dossier.description.html_safe - - if @facade.dossier.mandataire_social && gestionnaire_signed_in? .mandataire_social.text-success.center %br diff --git a/app/views/users/description/_champs.html.haml b/app/views/users/description/_champs.html.haml index 464572686..db6decbf3 100644 --- a/app/views/users/description/_champs.html.haml +++ b/app/views/users/description/_champs.html.haml @@ -15,9 +15,10 @@ = '*' -if champ.type_champ == 'textarea' - %textarea.form-control{name:"champs['#{champ.id}']", - placeholder: champ.libelle, - id: "champs_#{champ.id}"} + %textarea.form-control.wysihtml5{name:"champs['#{champ.id}']", + placeholder: champ.description, + id: "champs_#{champ.id}", + row: '6'} =champ.value -elsif champ.type_champ == 'civilite' %label.radio-inline @@ -36,6 +37,7 @@ type: champ.type_champ, 'data-provide' => champ.data_provide, 'data-date-format' => ('dd/mm/yyyy' if champ.type_champ == 'datetime')} + - unless champ.description.empty? .row .col-lg-8.col-md-8{class: 'description_div', id:"description_champs_#{champ.id}"} diff --git a/app/views/users/description/_show.html.haml b/app/views/users/description/_show.html.haml index a42e114b0..c0db91dc6 100644 --- a/app/views/users/description/_show.html.haml +++ b/app/views/users/description/_show.html.haml @@ -12,11 +12,6 @@ .col-md-12 %h4 Libellé pour votre dossier * = text_field_tag :nom_projet, @dossier.nom_projet, placeholder: 'Nom du projet', class: 'form-control' - %br - .row - .col-md-12 - %h4 Description * - = text_area_tag :description, @dossier.description, rows: '6', placeholder: 'Description du projet', class: 'form-control wysihtml5' #liste_champs -unless @champs.nil? diff --git a/db/migrate/20160609145737_delete_default_description_to_dossier.rb b/db/migrate/20160609145737_delete_default_description_to_dossier.rb new file mode 100644 index 000000000..185e5ff4d --- /dev/null +++ b/db/migrate/20160609145737_delete_default_description_to_dossier.rb @@ -0,0 +1,62 @@ +class DeleteDefaultDescriptionToDossier < ActiveRecord::Migration + class Dossier < ActiveRecord::Base + + end + + class Champ < ActiveRecord::Base + + end + + class Procedure < ActiveRecord::Base + + end + + class TypeDeChamp < ActiveRecord::Base + + end + + def up + Procedure.all.each do |procedure| + #change all type_de_champ place_order by +1 to insert new type_de_champ description on first place + TypeDeChamp.where(procedure_id: procedure.id).each do |type_de_champ| + type_de_champ.order_place += 1 + type_de_champ.save + end + + #insert type_de_champ description on first place + TypeDeChamp.create(libelle: 'Description', description: 'Description de votre demande', type_champ: 'textarea', order_place: 0, procedure_id: procedure.id, mandatory: true) + end + + Dossier.all.each do |dossier| + #get the new type de champ + new_type_de_champ = TypeDeChamp.where(libelle: 'Description', type_champ: 'textarea', order_place: 0, procedure_id: dossier.procedure_id, mandatory: true) + + #create a new champ with the actual description value + Champ.create(value: dossier.description, type_de_champ_id: new_type_de_champ.first.id, dossier_id: dossier.id) + end + + remove_column :dossiers, :description + end + + def down + add_column :dossiers, :description, :text + + TypeDeChamp.where(libelle: 'Description', type_champ: 'textarea', order_place: 0, mandatory: true).each do |type_de_champ| + Champ.where(type_de_champ_id: type_de_champ.id).each do |champ| + dossier = Dossier.find(champ.dossier_id) + dossier.description = champ.value + dossier.save + + champ.delete + end + + procedure_id = type_de_champ.procedure_id + type_de_champ.delete + + TypeDeChamp.where(procedure_id: procedure_id).each do |type_de_champ_2| + type_de_champ_2.order_place -= 1 + type_de_champ_2.save + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 4839009ec..c990bd982 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: 20160609125949) do +ActiveRecord::Schema.define(version: 20160609145737) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -113,7 +113,6 @@ ActiveRecord::Schema.define(version: 20160609125949) do add_index "commentaires", ["dossier_id"], name: "index_commentaires_on_dossier_id", using: :btree create_table "dossiers", force: :cascade do |t| - t.string "description" t.boolean "autorisation_donnees" t.string "nom_projet" t.integer "procedure_id" diff --git a/spec/controllers/api/v1/dossiers_controller_spec.rb b/spec/controllers/api/v1/dossiers_controller_spec.rb index ad06ed0ac..83518f772 100644 --- a/spec/controllers/api/v1/dossiers_controller_spec.rb +++ b/spec/controllers/api/v1/dossiers_controller_spec.rb @@ -116,7 +116,7 @@ describe API::V1::DossiersController do let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } } let(:dossier_id) { dossier.id } let(:body) { JSON.parse(retour.body, symbolize_names: true) } - let(:field_list) { [:id, :nom_projet, :created_at, :updated_at, :description, :archived, :mandataire_social, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :commentaires] } + let(:field_list) { [:id, :nom_projet, :created_at, :updated_at, :archived, :mandataire_social, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :commentaires] } subject { body[:dossier] } it 'return REST code 200', :show_in_doc do @@ -126,7 +126,6 @@ describe API::V1::DossiersController do it { expect(subject[:nom_projet]).to eq(dossier.nom_projet) } it { expect(subject[:created_at]).to eq('2008-09-01T08:05:00.000Z') } it { expect(subject[:updated_at]).to eq('2008-09-01T08:05:00.000Z') } - it { expect(subject[:description]).to eq(dossier.description) } it { expect(subject[:archived]).to eq(dossier.archived) } it { expect(subject[:mandataire_social]).to eq(dossier.mandataire_social) } diff --git a/spec/controllers/users/description_controller_spec.rb b/spec/controllers/users/description_controller_spec.rb index 2e6c17e65..29c8028d8 100644 --- a/spec/controllers/users/description_controller_spec.rb +++ b/spec/controllers/users/description_controller_spec.rb @@ -116,12 +116,6 @@ describe Users::DescriptionController, type: :controller, vcr: { cassette_name: it { is_expected.to render_template(:show) } it { expect(flash[:alert]).to be_present } end - - context 'description empty' do - let(:description) { '' } - it { is_expected.to render_template(:show) } - it { expect(flash[:alert]).to be_present } - end end context 'Quand la procédure accepte les CERFA' do diff --git a/spec/factories/dossier.rb b/spec/factories/dossier.rb index a36447b1a..3919ecccd 100644 --- a/spec/factories/dossier.rb +++ b/spec/factories/dossier.rb @@ -1,7 +1,6 @@ FactoryGirl.define do factory :dossier do nom_projet "Demande de subvention dans le cadre d'accompagnement d'enfant à l'étranger" - description "Ma super description" state 'draft' association :user, factory: [:user] diff --git a/spec/features/description_page/upload_piece_justificative_spec.rb b/spec/features/description_page/upload_piece_justificative_spec.rb index 3ec0e57c7..89b14e15a 100644 --- a/spec/features/description_page/upload_piece_justificative_spec.rb +++ b/spec/features/description_page/upload_piece_justificative_spec.rb @@ -22,7 +22,6 @@ feature 'user is on description page' do context 'he fill description fields' do before do find_by_id('nom_projet').set 'mon nom' - find_by_id('description').set 'ma description' end context 'before submit' do it 'dossier cerfa is empty' do diff --git a/spec/features/users/complete_demande_spec.rb b/spec/features/users/complete_demande_spec.rb index fb7a86e9f..0f219c031 100644 --- a/spec/features/users/complete_demande_spec.rb +++ b/spec/features/users/complete_demande_spec.rb @@ -55,7 +55,6 @@ feature 'user path for dossier creation' do context 'user fill and validate description page' do before do page.find_by_id('nom_projet').set 'Mon super projet' - page.find_by_id('description').set 'Ma super description' page.click_on 'Soumettre mon dossier' end scenario 'user is on recap page' do diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index e9e8d0a4a..0952b3592 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -3,7 +3,6 @@ require 'spec_helper' describe Dossier do let(:user) { create(:user) } describe 'database columns' do - it { is_expected.to have_db_column(:description) } it { is_expected.to have_db_column(:autorisation_donnees) } it { is_expected.to have_db_column(:nom_projet) } it { is_expected.to have_db_column(:created_at) } @@ -40,11 +39,6 @@ describe Dossier do it { is_expected.not_to allow_value('').for(:nom_projet) } it { is_expected.to allow_value('mon super projet').for(:nom_projet) } end - context 'description' do - it { is_expected.to allow_value(nil).for(:description) } - it { is_expected.not_to allow_value('').for(:description) } - it { is_expected.to allow_value('ma superbe description').for(:description) } - end end describe 'methods' do @@ -115,6 +109,7 @@ describe Dossier do describe '#save' do subject { build(:dossier, procedure: procedure, user: user) } let!(:procedure) { create(:procedure) } + context 'when is linked to a procedure' do it 'creates default champs' do expect(subject).to receive(:build_default_champs) @@ -122,11 +117,11 @@ describe Dossier do end end context 'when is not linked to a procedure' do - subject { create(:dossier, procedure: procedure, user: user) } + subject { create(:dossier, procedure: nil, user: user) } it 'does not create default champs' do expect(subject).not_to receive(:build_default_champs) - subject.update_attributes(description: 'plop') + subject.update_attributes(nom_projet: 'plop') end end end @@ -541,7 +536,6 @@ describe Dossier do subject { dossier.as_csv } it { expect(subject[:nom_projet]).to eq("Demande de subvention dans le cadre d'accompagnement d'enfant à l'étranger") } - it { expect(subject[:description]).to eq("Ma super description") } it { expect(subject[:archived]).to be_falsey } it { expect(subject['etablissement.siret']).to eq('44011762001530') } it { expect(subject['etablissement.siege_social']).to be_truthy } diff --git a/spec/views/admin/previsualisations/show.html.haml_spec.rb b/spec/views/admin/previsualisations/show.html.haml_spec.rb index 06fc2a884..4d97de3a8 100644 --- a/spec/views/admin/previsualisations/show.html.haml_spec.rb +++ b/spec/views/admin/previsualisations/show.html.haml_spec.rb @@ -25,10 +25,6 @@ describe 'admin/previsualisations/show.html.haml', type: :view do expect(rendered).to have_selector('input[id=nom_projet][name=nom_projet]') end - it 'Description du projet' do - expect(rendered).to have_selector('textarea[id=description][name=description]') - end - it 'Charger votre CERFA (PDF)' do expect(rendered).to have_selector('input[type=file][name=cerfa_pdf][id=cerfa_pdf]') end @@ -71,7 +67,6 @@ describe 'admin/previsualisations/show.html.haml', type: :view do let!(:dossier) do create(:dossier, nom_projet: 'Projet de test', - description: 'Description de test', user: user) end @@ -82,10 +77,6 @@ describe 'admin/previsualisations/show.html.haml', type: :view do it 'Nom du projet' do expect(rendered).to have_selector("input[id=nom_projet][value='#{dossier.nom_projet}']") end - - it 'Description du projet' do - expect(rendered).to have_content("#{dossier.description}") - end end context 'Champs' do diff --git a/spec/views/users/description/show.html.haml_spec.rb b/spec/views/users/description/show.html.haml_spec.rb index e6c123b9c..04e256317 100644 --- a/spec/views/users/description/show.html.haml_spec.rb +++ b/spec/views/users/description/show.html.haml_spec.rb @@ -26,10 +26,6 @@ describe 'users/description/show.html.haml', type: :view do expect(rendered).to have_selector('input[id=nom_projet][name=nom_projet]') end - it 'Description du projet' do - expect(rendered).to have_selector('textarea[id=description][name=description]') - end - it 'Charger votre CERFA (PDF)' do expect(rendered).to have_selector('input[type=file][name=cerfa_pdf][id=cerfa_pdf]') end @@ -72,7 +68,6 @@ describe 'users/description/show.html.haml', type: :view do let!(:dossier) do create(:dossier, nom_projet: 'Projet de test', - description: 'Description de test', user: user) end @@ -83,10 +78,6 @@ describe 'users/description/show.html.haml', type: :view do it 'Nom du projet' do expect(rendered).to have_selector("input[id=nom_projet][value='#{dossier.nom_projet}']") end - - it 'Description du projet' do - expect(rendered).to have_content("#{dossier.description}") - end end context 'Champs' do