rename ref piece jointe into type piece jointe
This commit is contained in:
parent
b9b17e2b0c
commit
a807ba5ae9
18 changed files with 961 additions and 940 deletions
2
Gemfile
2
Gemfile
|
@ -80,7 +80,7 @@ group :development, :test do
|
||||||
|
|
||||||
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
|
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
|
||||||
gem 'spring'
|
gem 'spring'
|
||||||
|
gem 'spring-commands-rspec'
|
||||||
gem 'rspec-rails', '~> 3.0'
|
gem 'rspec-rails', '~> 3.0'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -257,6 +257,8 @@ GEM
|
||||||
simplecov-html (0.8.0)
|
simplecov-html (0.8.0)
|
||||||
slop (3.6.0)
|
slop (3.6.0)
|
||||||
spring (1.3.6)
|
spring (1.3.6)
|
||||||
|
spring-commands-rspec (1.0.4)
|
||||||
|
spring (>= 0.9.1)
|
||||||
sprockets (3.2.0)
|
sprockets (3.2.0)
|
||||||
rack (~> 1.0)
|
rack (~> 1.0)
|
||||||
sprockets-rails (2.3.2)
|
sprockets-rails (2.3.2)
|
||||||
|
@ -328,6 +330,7 @@ DEPENDENCIES
|
||||||
shoulda-matchers
|
shoulda-matchers
|
||||||
simplecov
|
simplecov
|
||||||
spring
|
spring
|
||||||
|
spring-commands-rspec
|
||||||
turbolinks
|
turbolinks
|
||||||
uglifier (>= 1.3.0)
|
uglifier (>= 1.3.0)
|
||||||
web-console (~> 2.0)
|
web-console (~> 2.0)
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Admin::DossierController < ApplicationController
|
||||||
@commentaire_email = current_user.email
|
@commentaire_email = current_user.email
|
||||||
|
|
||||||
@formulaire = @dossier.ref_formulaire
|
@formulaire = @dossier.ref_formulaire
|
||||||
@liste_pieces_jointes = RefPiecesJointe.get_liste_piece_jointe @dossier.ref_formulaire
|
@liste_pieces_jointes = TypePieceJointe.get_liste_piece_jointe @dossier.ref_formulaire
|
||||||
@array_id_pj_valides = PieceJointe.get_array_id_pj_valid_for_dossier @dossier.id
|
@array_id_pj_valides = PieceJointe.get_array_id_pj_valid_for_dossier @dossier.id
|
||||||
@dossier = @dossier.decorate
|
@dossier = @dossier.decorate
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
|
|
@ -4,7 +4,6 @@ class DescriptionController < ApplicationController
|
||||||
@dossier = @dossier.decorate
|
@dossier = @dossier.decorate
|
||||||
|
|
||||||
@array_id_pj_valides = PieceJointe.get_array_id_pj_valid_for_dossier @dossier.id
|
@array_id_pj_valides = PieceJointe.get_array_id_pj_valid_for_dossier @dossier.id
|
||||||
|
|
||||||
@liste_pieces_jointes = get_liste_piece_jointe
|
@liste_pieces_jointes = get_liste_piece_jointe
|
||||||
rescue
|
rescue
|
||||||
redirect_to url_for({controller: :start, action: :error_dossier})
|
redirect_to url_for({controller: :start, action: :error_dossier})
|
||||||
|
@ -21,21 +20,21 @@ class DescriptionController < ApplicationController
|
||||||
@dossier.update_attributes(create_params)
|
@dossier.update_attributes(create_params)
|
||||||
|
|
||||||
if params[:cerfa_pdf] != nil
|
if params[:cerfa_pdf] != nil
|
||||||
PieceJointe.destroy_all(dossier_id: @dossier.id, ref_pieces_jointes_id: 0)
|
PieceJointe.destroy_all(dossier_id: @dossier.id, type_piece_jointe_id: 0)
|
||||||
@piece_jointe = PieceJointe.new
|
@piece_jointe = PieceJointe.new
|
||||||
@piece_jointe.content = params[:cerfa_pdf]
|
@piece_jointe.content = params[:cerfa_pdf]
|
||||||
@piece_jointe.ref_pieces_jointes_id = 0
|
@piece_jointe.type_piece_jointe_id = 0
|
||||||
@piece_jointe.dossier = @dossier
|
@piece_jointe.dossier = @dossier
|
||||||
@piece_jointe.save
|
@piece_jointe.save
|
||||||
end
|
end
|
||||||
|
|
||||||
get_liste_piece_jointe.each do |pj|
|
get_liste_piece_jointe.each do |pj|
|
||||||
if params["piece_jointe_#{pj.id}"] != nil
|
if params["piece_jointe_#{pj.id}"] != nil
|
||||||
PieceJointe.destroy_all(dossier_id: @dossier.id, ref_pieces_jointes_id: pj.id)
|
PieceJointe.destroy_all(dossier_id: @dossier.id, type_piece_jointe_id: pj.id)
|
||||||
|
|
||||||
@piece_jointe = PieceJointe.new
|
@piece_jointe = PieceJointe.new
|
||||||
@piece_jointe.content = params["piece_jointe_#{pj.id}"]
|
@piece_jointe.content = params["piece_jointe_#{pj.id}"]
|
||||||
@piece_jointe.ref_pieces_jointes_id = pj.id
|
@piece_jointe.type_piece_jointe_id = pj.id
|
||||||
@piece_jointe.dossier = @dossier
|
@piece_jointe.dossier = @dossier
|
||||||
@piece_jointe.save
|
@piece_jointe.save
|
||||||
end
|
end
|
||||||
|
@ -74,6 +73,6 @@ class DescriptionController < ApplicationController
|
||||||
|
|
||||||
def get_liste_piece_jointe
|
def get_liste_piece_jointe
|
||||||
@formulaire = @dossier.ref_formulaire
|
@formulaire = @dossier.ref_formulaire
|
||||||
RefPiecesJointe.where ("\"CERFA\" = '#{@formulaire.ref_demarche}'")
|
TypePieceJointe.where ("\"CERFA\" = '#{@formulaire.ref_demarche}'")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,6 +9,10 @@ class Dossier < ActiveRecord::Base
|
||||||
delegate :siret, to: :etablissement
|
delegate :siret, to: :etablissement
|
||||||
|
|
||||||
def get_pj piece_jointe_id
|
def get_pj piece_jointe_id
|
||||||
pieces_jointes.where(ref_pieces_jointes_id: piece_jointe_id).last
|
pieces_jointes.where(type_piece_jointe_id: piece_jointe_id).last
|
||||||
|
end
|
||||||
|
|
||||||
|
def liste_piece_justificative
|
||||||
|
ref_formulaire.liste_piece_justificative
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@ class PieceJointe < ActiveRecord::Base
|
||||||
def self.get_array_id_pj_valid_for_dossier(dossier_id)
|
def self.get_array_id_pj_valid_for_dossier(dossier_id)
|
||||||
@array_id_pj_valides = []
|
@array_id_pj_valides = []
|
||||||
where(dossier_id: dossier_id).each do |pj_valide|
|
where(dossier_id: dossier_id).each do |pj_valide|
|
||||||
@array_id_pj_valides << pj_valide.ref_pieces_jointes_id
|
@array_id_pj_valides << pj_valide.type_piece_jointe_id
|
||||||
end
|
end
|
||||||
|
|
||||||
@array_id_pj_valides
|
@array_id_pj_valides
|
||||||
|
|
|
@ -1,2 +1,7 @@
|
||||||
class RefFormulaire < ActiveRecord::Base
|
class RefFormulaire < ActiveRecord::Base
|
||||||
|
has_many :types_piece_jointe
|
||||||
|
|
||||||
|
def liste_piece_justificative
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
class RefPiecesJointe < ActiveRecord::Base
|
|
||||||
|
|
||||||
# TODO: test this methods
|
|
||||||
def self.get_liste_piece_jointe ref_formulaire
|
|
||||||
RefPiecesJointe.where ("\"CERFA\" = '#{ref_formulaire.ref_demarche}'")
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
8
app/models/type_piece_jointe.rb
Normal file
8
app/models/type_piece_jointe.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
class TypePieceJointe < ActiveRecord::Base
|
||||||
|
|
||||||
|
# TODO: test this methods
|
||||||
|
def self.get_liste_piece_jointe ref_formulaire
|
||||||
|
where ("\"CERFA\" = '#{ref_formulaire.ref_demarche}'")
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -9,7 +9,7 @@ ActiveSupport::Inflector.inflections(:en) do |inflect|
|
||||||
# inflect.irregular 'person', 'people'
|
# inflect.irregular 'person', 'people'
|
||||||
# inflect.uncountable %w( fish sheep )
|
# inflect.uncountable %w( fish sheep )
|
||||||
inflect.irregular 'piece_jointe', 'pieces_jointes'
|
inflect.irregular 'piece_jointe', 'pieces_jointes'
|
||||||
|
inflect.irregular 'type_piece_jointe', 'types_piece_jointe'
|
||||||
end
|
end
|
||||||
|
|
||||||
# These inflection rules are supported but not enabled by default:
|
# These inflection rules are supported but not enabled by default:
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
class RenameRefPieceJointToTypePieceJointe < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
rename_table :ref_pieces_jointes, :types_piece_jointe
|
||||||
|
rename_column :pieces_jointes, :ref_pieces_jointes_id, :type_piece_jointe_id
|
||||||
|
end
|
||||||
|
end
|
|
@ -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: 20150813095939) do
|
ActiveRecord::Schema.define(version: 20150814090717) 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"
|
||||||
|
@ -87,10 +87,10 @@ ActiveRecord::Schema.define(version: 20150813095939) do
|
||||||
create_table "pieces_jointes", force: :cascade do |t|
|
create_table "pieces_jointes", force: :cascade do |t|
|
||||||
t.string "content"
|
t.string "content"
|
||||||
t.integer "dossier_id"
|
t.integer "dossier_id"
|
||||||
t.integer "ref_pieces_jointes_id"
|
t.integer "type_piece_jointe_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "pieces_jointes", ["ref_pieces_jointes_id"], name: "index_pieces_jointes_on_ref_pieces_jointes_id", using: :btree
|
add_index "pieces_jointes", ["type_piece_jointe_id"], name: "index_pieces_jointes_on_type_piece_jointe_id", using: :btree
|
||||||
|
|
||||||
create_table "pros", force: :cascade do |t|
|
create_table "pros", force: :cascade do |t|
|
||||||
t.string "email", default: "", null: false
|
t.string "email", default: "", null: false
|
||||||
|
@ -129,7 +129,7 @@ ActiveRecord::Schema.define(version: 20150813095939) do
|
||||||
t.boolean "use_admi_facile"
|
t.boolean "use_admi_facile"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "ref_pieces_jointes", force: :cascade do |t|
|
create_table "types_piece_jointe", force: :cascade do |t|
|
||||||
t.string "CERFA"
|
t.string "CERFA"
|
||||||
t.string "nature"
|
t.string "nature"
|
||||||
t.string "libelle_complet"
|
t.string "libelle_complet"
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -124,15 +124,15 @@ describe DescriptionController, type: :controller do
|
||||||
expect(subject.dossier_id).to eq(dossier_id)
|
expect(subject.dossier_id).to eq(dossier_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'ref_pieces_jointes_id' do
|
it 'type_piece_jointe_id' do
|
||||||
expect(subject.ref_pieces_jointes_id).to eq(0)
|
expect(subject.type_piece_jointe_id).to eq(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'les anciens CERFA PDF sont écrasées à chaque fois' do
|
context 'les anciens CERFA PDF sont écrasées à chaque fois' do
|
||||||
it 'il n\'y a qu\'un CERFA PDF par dossier' 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, :mail_contact => mail_contact, :cerfa_pdf => cerfa_pdf
|
||||||
cerfa = PieceJointe.where(ref_pieces_jointes_id: '0', dossier_id: dossier_id)
|
cerfa = PieceJointe.where(type_piece_jointe_id: '0', dossier_id: dossier_id)
|
||||||
expect(cerfa.many?).to eq(false)
|
expect(cerfa.many?).to eq(false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -148,7 +148,7 @@ describe DescriptionController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'sauvegarde de 2 pieces jointes' do
|
context 'sauvegarde de 2 pieces jointes' do
|
||||||
subject { dossier.pieces_jointes.pluck(:ref_pieces_jointes_id) }
|
subject { dossier.pieces_jointes.pluck(:type_piece_jointe_id) }
|
||||||
it 'les deux pièces sont présentes en base' do
|
it 'les deux pièces sont présentes en base' do
|
||||||
expect(subject).to include(103)
|
expect(subject).to include(103)
|
||||||
expect(subject).to include(692)
|
expect(subject).to include(692)
|
||||||
|
@ -159,8 +159,8 @@ describe DescriptionController, type: :controller do
|
||||||
it 'il n\'y a qu\'une pièce jointe par type par dossier' do
|
it 'il n\'y a qu\'une pièce jointe par type 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, :piece_jointe_692 => piece_jointe_692, :piece_jointe_103 => piece_jointe_103
|
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, :piece_jointe_692 => piece_jointe_692, :piece_jointe_103 => piece_jointe_103
|
||||||
|
|
||||||
piece_jointe_1 = PieceJointe.where(ref_pieces_jointes_id: '103', dossier_id: dossier_id)
|
piece_jointe_1 = PieceJointe.where(type_piece_jointe_id: '103', dossier_id: dossier_id)
|
||||||
piece_jointe_2 = PieceJointe.where(ref_pieces_jointes_id: '692', dossier_id: dossier_id)
|
piece_jointe_2 = PieceJointe.where(type_piece_jointe_id: '692', dossier_id: dossier_id)
|
||||||
|
|
||||||
expect(piece_jointe_1.many?).to eq(false)
|
expect(piece_jointe_1.many?).to eq(false)
|
||||||
expect(piece_jointe_2.many?).to eq(false)
|
expect(piece_jointe_2.many?).to eq(false)
|
||||||
|
|
|
@ -62,7 +62,7 @@ feature 'Admin/Dossier#Show Page' do
|
||||||
context 'Devis' do
|
context 'Devis' do
|
||||||
let(:id_piece_jointe){388}
|
let(:id_piece_jointe){388}
|
||||||
let(:piece_jointe_388) {File.open('./spec/support/files/piece_jointe_388.pdf')}
|
let(:piece_jointe_388) {File.open('./spec/support/files/piece_jointe_388.pdf')}
|
||||||
let!(:piece_jointe) { create(:piece_jointe, dossier: dossier, ref_pieces_jointes_id: id_piece_jointe, content: piece_jointe_388) }
|
let!(:piece_jointe) { create(:piece_jointe, dossier: dossier, type_piece_jointe_id: id_piece_jointe, content: piece_jointe_388) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
visit "/admin/dossier/#{dossier_id}"
|
visit "/admin/dossier/#{dossier_id}"
|
||||||
|
|
|
@ -19,4 +19,12 @@ describe Dossier do
|
||||||
expect(subject.siret).to eq(etablissement.siret)
|
expect(subject.siret).to eq(etablissement.siret)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#liste_piece_justificative' do
|
||||||
|
subject { dossier.liste_piece_justificative }
|
||||||
|
it 'returns list of required piece justificative' do
|
||||||
|
expect(subject.size).to eq(7)
|
||||||
|
expect(subject).to include(23)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -45,7 +45,7 @@ Dir[Rails.root.join("spec/factories/**/*.rb")].each { |f| require f }
|
||||||
# If you are not using ActiveRecord, you can remove this line.
|
# If you are not using ActiveRecord, you can remove this line.
|
||||||
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
|
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
|
||||||
|
|
||||||
DatabaseCleaner.strategy = :truncation, {:except => %w[evenement_vies ref_formulaires ref_pieces_jointes]}
|
DatabaseCleaner.strategy = :truncation, {:except => %w[evenement_vies ref_formulaires types_piece_jointe]}
|
||||||
|
|
||||||
|
|
||||||
if !(defined? SIADETOKEN)
|
if !(defined? SIADETOKEN)
|
||||||
|
|
|
@ -1,16 +1,12 @@
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.before(:suite) do
|
config.before(:suite) do
|
||||||
DatabaseCleaner.clean_with(:truncation, {:except => %w[evenement_vies ref_formulaires ref_pieces_jointes]})
|
DatabaseCleaner.clean_with(:truncation, {:except => %w[evenement_vies ref_formulaires types_piece_jointe]})
|
||||||
end
|
end
|
||||||
|
|
||||||
config.before(:each) do
|
config.before(:each) do
|
||||||
DatabaseCleaner.strategy = :transaction
|
DatabaseCleaner.strategy = :transaction
|
||||||
end
|
end
|
||||||
|
|
||||||
# config.before(:each, :js => true) do
|
|
||||||
# DatabaseCleaner.strategy = :truncation, {:except => %w[evenement_vies ref_formulaires ref_pieces_jointes]}
|
|
||||||
# end
|
|
||||||
|
|
||||||
config.before(:each) do
|
config.before(:each) do
|
||||||
DatabaseCleaner.start
|
DatabaseCleaner.start
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue