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
def archive
change_status({archived: true})
change_status({archived: params[:archive]})
end
def active_class

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

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.
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"

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_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) }

View file

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

View file

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

View file

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

View file

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

View file

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

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]')
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

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]')
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