Delete default description in dossier

This commit is contained in:
Xavier J 2016-06-13 12:03:05 +02:00
parent fdee7154cf
commit 866565495d
18 changed files with 75 additions and 56 deletions

View file

@ -80,7 +80,7 @@ class Admin::ProceduresController < AdminController
end end
def archive def archive
change_status({archived: true}) change_status({archived: params[:archive]})
end end
def active_class def active_class

View file

@ -94,6 +94,6 @@ class Users::DescriptionController < UsersController
private private
def create_params def create_params
params.permit(:nom_projet, :description) params.permit(:nom_projet)
end end
end end

View file

@ -30,7 +30,6 @@ class Dossier < ActiveRecord::Base
after_save :build_default_champs, if: Proc.new { procedure_id_changed? } after_save :build_default_champs, if: Proc.new { procedure_id_changed? }
validates :nom_projet, presence: true, allow_blank: false, allow_nil: true 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 validates :user, presence: true
WAITING_FOR_GESTIONNAIRE = %w(initiated updated submitted) WAITING_FOR_GESTIONNAIRE = %w(initiated updated submitted)

View file

@ -1,7 +1,6 @@
class DossierSerializer < ActiveModel::Serializer class DossierSerializer < ActiveModel::Serializer
attributes :id, attributes :id,
:nom_projet, :nom_projet,
:description,
:created_at, :created_at,
:updated_at, :updated_at,
:archived, :archived,

View file

@ -2,7 +2,7 @@
%ul.nav.nav-tabs %ul.nav.nav-tabs
%li{class: @draft_class} %li{class: @draft_class}
%a{:href => "#{url_for :admin_procedures_draft}"} %a{:href => "#{url_for :admin_procedures_draft}"}
%h5{style: 'color: black'} %h5.text-primary
="Brouillons" ="Brouillons"
%li{class: @active_class} %li{class: @active_class}

View file

@ -6,9 +6,6 @@
%h4 %h4
= @facade.dossier.procedure.libelle = @facade.dossier.procedure.libelle
.description
= h @facade.dossier.description.html_safe
- if @facade.dossier.mandataire_social && gestionnaire_signed_in? - if @facade.dossier.mandataire_social && gestionnaire_signed_in?
.mandataire_social.text-success.center .mandataire_social.text-success.center
%br %br

View file

@ -15,9 +15,10 @@
= '*' = '*'
-if champ.type_champ == 'textarea' -if champ.type_champ == 'textarea'
%textarea.form-control{name:"champs['#{champ.id}']", %textarea.form-control.wysihtml5{name:"champs['#{champ.id}']",
placeholder: champ.libelle, placeholder: champ.description,
id: "champs_#{champ.id}"} id: "champs_#{champ.id}",
row: '6'}
=champ.value =champ.value
-elsif champ.type_champ == 'civilite' -elsif champ.type_champ == 'civilite'
%label.radio-inline %label.radio-inline
@ -36,6 +37,7 @@
type: champ.type_champ, type: champ.type_champ,
'data-provide' => champ.data_provide, 'data-provide' => champ.data_provide,
'data-date-format' => ('dd/mm/yyyy' if champ.type_champ == 'datetime')} 'data-date-format' => ('dd/mm/yyyy' if champ.type_champ == 'datetime')}
- unless champ.description.empty? - unless champ.description.empty?
.row .row
.col-lg-8.col-md-8{class: 'description_div', id:"description_champs_#{champ.id}"} .col-lg-8.col-md-8{class: 'description_div', id:"description_champs_#{champ.id}"}

View file

@ -12,11 +12,6 @@
.col-md-12 .col-md-12
%h4 Libellé pour votre dossier * %h4 Libellé pour votre dossier *
= text_field_tag :nom_projet, @dossier.nom_projet, placeholder: 'Nom du projet', class: 'form-control' = 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 #liste_champs
-unless @champs.nil? -unless @champs.nil?

View file

@ -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

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" 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 add_index "commentaires", ["dossier_id"], name: "index_commentaires_on_dossier_id", using: :btree
create_table "dossiers", force: :cascade do |t| create_table "dossiers", force: :cascade do |t|
t.string "description"
t.boolean "autorisation_donnees" t.boolean "autorisation_donnees"
t.string "nom_projet" t.string "nom_projet"
t.integer "procedure_id" t.integer "procedure_id"

View file

@ -116,7 +116,7 @@ describe API::V1::DossiersController do
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } } let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure) } }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
let(:body) { JSON.parse(retour.body, symbolize_names: true) } 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] } subject { body[:dossier] }
it 'return REST code 200', :show_in_doc do 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[:nom_projet]).to eq(dossier.nom_projet) }
it { expect(subject[:created_at]).to eq('2008-09-01T08:05:00.000Z') } 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[: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[:archived]).to eq(dossier.archived) }
it { expect(subject[:mandataire_social]).to eq(dossier.mandataire_social) } it { expect(subject[:mandataire_social]).to eq(dossier.mandataire_social) }

View file

@ -116,12 +116,6 @@ describe Users::DescriptionController, type: :controller, vcr: { cassette_name:
it { is_expected.to render_template(:show) } it { is_expected.to render_template(:show) }
it { expect(flash[:alert]).to be_present } it { expect(flash[:alert]).to be_present }
end end
context 'description empty' do
let(:description) { '' }
it { is_expected.to render_template(:show) }
it { expect(flash[:alert]).to be_present }
end
end end
context 'Quand la procédure accepte les CERFA' do context 'Quand la procédure accepte les CERFA' do

View file

@ -1,7 +1,6 @@
FactoryGirl.define do FactoryGirl.define do
factory :dossier do factory :dossier do
nom_projet "Demande de subvention dans le cadre d'accompagnement d'enfant à l'étranger" nom_projet "Demande de subvention dans le cadre d'accompagnement d'enfant à l'étranger"
description "Ma super description"
state 'draft' state 'draft'
association :user, factory: [:user] association :user, factory: [:user]

View file

@ -22,7 +22,6 @@ feature 'user is on description page' do
context 'he fill description fields' do context 'he fill description fields' do
before do before do
find_by_id('nom_projet').set 'mon nom' find_by_id('nom_projet').set 'mon nom'
find_by_id('description').set 'ma description'
end end
context 'before submit' do context 'before submit' do
it 'dossier cerfa is empty' do it 'dossier cerfa is empty' do

View file

@ -55,7 +55,6 @@ feature 'user path for dossier creation' do
context 'user fill and validate description page' do context 'user fill and validate description page' do
before do before do
page.find_by_id('nom_projet').set 'Mon super projet' 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' page.click_on 'Soumettre mon dossier'
end end
scenario 'user is on recap page' do scenario 'user is on recap page' do

View file

@ -3,7 +3,6 @@ require 'spec_helper'
describe Dossier do describe Dossier do
let(:user) { create(:user) } let(:user) { create(:user) }
describe 'database columns' do 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(:autorisation_donnees) }
it { is_expected.to have_db_column(:nom_projet) } it { is_expected.to have_db_column(:nom_projet) }
it { is_expected.to have_db_column(:created_at) } 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.not_to allow_value('').for(:nom_projet) }
it { is_expected.to allow_value('mon super projet').for(:nom_projet) } it { is_expected.to allow_value('mon super projet').for(:nom_projet) }
end 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 end
describe 'methods' do describe 'methods' do
@ -115,6 +109,7 @@ describe Dossier do
describe '#save' do describe '#save' do
subject { build(:dossier, procedure: procedure, user: user) } subject { build(:dossier, procedure: procedure, user: user) }
let!(:procedure) { create(:procedure) } let!(:procedure) { create(:procedure) }
context 'when is linked to a procedure' do context 'when is linked to a procedure' do
it 'creates default champs' do it 'creates default champs' do
expect(subject).to receive(:build_default_champs) expect(subject).to receive(:build_default_champs)
@ -122,11 +117,11 @@ describe Dossier do
end end
end end
context 'when is not linked to a procedure' do 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 it 'does not create default champs' do
expect(subject).not_to receive(:build_default_champs) expect(subject).not_to receive(:build_default_champs)
subject.update_attributes(description: 'plop') subject.update_attributes(nom_projet: 'plop')
end end
end end
end end
@ -541,7 +536,6 @@ describe Dossier do
subject { dossier.as_csv } 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[: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[:archived]).to be_falsey }
it { expect(subject['etablissement.siret']).to eq('44011762001530') } it { expect(subject['etablissement.siret']).to eq('44011762001530') }
it { expect(subject['etablissement.siege_social']).to be_truthy } it { expect(subject['etablissement.siege_social']).to be_truthy }

View file

@ -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]') expect(rendered).to have_selector('input[id=nom_projet][name=nom_projet]')
end end
it 'Description du projet' do
expect(rendered).to have_selector('textarea[id=description][name=description]')
end
it 'Charger votre CERFA (PDF)' do it 'Charger votre CERFA (PDF)' do
expect(rendered).to have_selector('input[type=file][name=cerfa_pdf][id=cerfa_pdf]') expect(rendered).to have_selector('input[type=file][name=cerfa_pdf][id=cerfa_pdf]')
end end
@ -71,7 +67,6 @@ describe 'admin/previsualisations/show.html.haml', type: :view do
let!(:dossier) do let!(:dossier) do
create(:dossier, create(:dossier,
nom_projet: 'Projet de test', nom_projet: 'Projet de test',
description: 'Description de test',
user: user) user: user)
end end
@ -82,10 +77,6 @@ describe 'admin/previsualisations/show.html.haml', type: :view do
it 'Nom du projet' do it 'Nom du projet' do
expect(rendered).to have_selector("input[id=nom_projet][value='#{dossier.nom_projet}']") expect(rendered).to have_selector("input[id=nom_projet][value='#{dossier.nom_projet}']")
end end
it 'Description du projet' do
expect(rendered).to have_content("#{dossier.description}")
end
end end
context 'Champs' do context 'Champs' do

View file

@ -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]') expect(rendered).to have_selector('input[id=nom_projet][name=nom_projet]')
end end
it 'Description du projet' do
expect(rendered).to have_selector('textarea[id=description][name=description]')
end
it 'Charger votre CERFA (PDF)' do it 'Charger votre CERFA (PDF)' do
expect(rendered).to have_selector('input[type=file][name=cerfa_pdf][id=cerfa_pdf]') expect(rendered).to have_selector('input[type=file][name=cerfa_pdf][id=cerfa_pdf]')
end end
@ -72,7 +68,6 @@ describe 'users/description/show.html.haml', type: :view do
let!(:dossier) do let!(:dossier) do
create(:dossier, create(:dossier,
nom_projet: 'Projet de test', nom_projet: 'Projet de test',
description: 'Description de test',
user: user) user: user)
end end
@ -83,10 +78,6 @@ describe 'users/description/show.html.haml', type: :view do
it 'Nom du projet' do it 'Nom du projet' do
expect(rendered).to have_selector("input[id=nom_projet][value='#{dossier.nom_projet}']") expect(rendered).to have_selector("input[id=nom_projet][value='#{dossier.nom_projet}']")
end end
it 'Description du projet' do
expect(rendered).to have_content("#{dossier.description}")
end
end end
context 'Champs' do context 'Champs' do