add database cleaner
add factory girl fix tests rename dossier_pdf into piece_jointe rename ref_piece_jointe into content
This commit is contained in:
parent
c16d7a12f2
commit
3c57643f76
48 changed files with 338 additions and 174 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -23,4 +23,6 @@
|
|||
*.iml
|
||||
*.iws
|
||||
|
||||
public/uploads
|
||||
public/uploads
|
||||
bin/*
|
||||
config/initializers/token.rb
|
||||
|
|
|
@ -332,6 +332,3 @@ DEPENDENCIES
|
|||
uglifier (>= 1.3.0)
|
||||
web-console (~> 2.0)
|
||||
webmock
|
||||
|
||||
BUNDLED WITH
|
||||
1.10.4
|
||||
|
|
|
@ -5,17 +5,16 @@ class Admin::DossierController < ApplicationController
|
|||
@dossier = Dossier.find(params[:dossier_id])
|
||||
@entreprise = @dossier.entreprise.decorate
|
||||
@etablissement = @dossier.etablissement
|
||||
@dossier_pdf = @dossier.dossier_pdf
|
||||
@pieces_jointes = @dossier.pieces_jointes
|
||||
@commentaires = @dossier.commentaires.order(created_at: :desc)
|
||||
@commentaires = @commentaires.all.decorate
|
||||
@commentaire_email = current_user.email
|
||||
|
||||
@formulaire = RefFormulaire.find(@dossier.ref_formulaire)
|
||||
@formulaire = @dossier.ref_formulaire
|
||||
@liste_pieces_jointes = RefPiecesJointe.get_liste_piece_jointe @dossier.ref_formulaire
|
||||
@array_id_pj_valides = DossierPdf.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
|
||||
rescue
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
redirect_start
|
||||
end
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ class DemandesController < ApplicationController
|
|||
|
||||
def choice
|
||||
@dossier = Dossier.find(params[:dossier_id])
|
||||
@dossier.update_attributes(ref_formulaire: params[:ref_formulaire])
|
||||
@dossier.update_attributes(ref_formulaire_id: params[:ref_formulaire])
|
||||
|
||||
redirect_to url_for( { controller: :carte, action: :show, :dossier_id => params[:dossier_id] } )
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ class DescriptionController < ApplicationController
|
|||
@dossier = Dossier.find(params[:dossier_id])
|
||||
@dossier = @dossier.decorate
|
||||
|
||||
@array_id_pj_valides = DossierPdf.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
|
||||
rescue
|
||||
|
@ -21,23 +21,23 @@ class DescriptionController < ApplicationController
|
|||
@dossier.update_attributes(create_params)
|
||||
|
||||
if params[:cerfa_pdf] != nil
|
||||
DossierPdf.destroy_all(dossier_id: @dossier.id, ref_pieces_jointes_id: 0)
|
||||
@dossier_pdf = DossierPdf.new
|
||||
@dossier_pdf.ref_dossier_pdf = params[:cerfa_pdf]
|
||||
@dossier_pdf.ref_pieces_jointes_id = 0
|
||||
@dossier_pdf.dossier = @dossier
|
||||
@dossier_pdf.save
|
||||
PieceJointe.destroy_all(dossier_id: @dossier.id, ref_pieces_jointes_id: 0)
|
||||
@piece_jointe = PieceJointe.new
|
||||
@piece_jointe.content = params[:cerfa_pdf]
|
||||
@piece_jointe.ref_pieces_jointes_id = 0
|
||||
@piece_jointe.dossier = @dossier
|
||||
@piece_jointe.save
|
||||
end
|
||||
|
||||
get_liste_piece_jointe.each do |pj|
|
||||
if params["piece_jointe_#{pj.id}"] != nil
|
||||
DossierPdf.destroy_all(dossier_id: @dossier.id, ref_pieces_jointes_id: pj.id)
|
||||
PieceJointe.destroy_all(dossier_id: @dossier.id, ref_pieces_jointes_id: pj.id)
|
||||
|
||||
@dossier_pdf = DossierPdf.new
|
||||
@dossier_pdf.ref_dossier_pdf = params["piece_jointe_#{pj.id}"]
|
||||
@dossier_pdf.ref_pieces_jointes_id = pj.id
|
||||
@dossier_pdf.dossier = @dossier
|
||||
@dossier_pdf.save
|
||||
@piece_jointe = PieceJointe.new
|
||||
@piece_jointe.content = params["piece_jointe_#{pj.id}"]
|
||||
@piece_jointe.ref_pieces_jointes_id = pj.id
|
||||
@piece_jointe.dossier = @dossier
|
||||
@piece_jointe.save
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -73,7 +73,7 @@ class DescriptionController < ApplicationController
|
|||
end
|
||||
|
||||
def get_liste_piece_jointe
|
||||
@formulaire = RefFormulaire.find(@dossier.ref_formulaire)
|
||||
@formulaire = @dossier.ref_formulaire
|
||||
RefPiecesJointe.where ("\"CERFA\" = '#{@formulaire.ref_demarche}'")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ class DossiersController < ApplicationController
|
|||
|
||||
@etablissement = @dossier.etablissement
|
||||
@entreprise = @dossier.entreprise.decorate
|
||||
rescue
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
redirect_to url_for({controller: :start, action: :error_dossier})
|
||||
end
|
||||
|
||||
|
@ -39,14 +39,16 @@ class DossiersController < ApplicationController
|
|||
|
||||
redirect_to url_for({controller: :dossiers, action: :show, id: @dossier.id})
|
||||
end
|
||||
# TODO: Remove rescue
|
||||
rescue
|
||||
redirect_to url_for({controller: :start, action: @rescue_redirect})
|
||||
end
|
||||
|
||||
def update
|
||||
|
||||
@dossier = Dossier.find(params[:id])
|
||||
@dossier.autorisation_donnees = (params[:autorisation_donnees] == 'on')
|
||||
@dossier.save
|
||||
return error if update_params[:autorisation_donnees] == '0'
|
||||
@dossier.update_attributes(update_params)
|
||||
|
||||
if @dossier.autorisation_donnees
|
||||
redirect_to url_for({controller: :demandes, action: :show, dossier_id: @dossier.id})
|
||||
|
@ -66,6 +68,10 @@ class DossiersController < ApplicationController
|
|||
|
||||
private
|
||||
|
||||
def update_params
|
||||
params.require(:dossier).permit(:autorisation_donnees)
|
||||
end
|
||||
|
||||
def dossier_id_is_present?
|
||||
|
||||
end
|
||||
|
|
|
@ -5,9 +5,12 @@ class RecapitulatifController < ApplicationController
|
|||
|
||||
#mettre dans le modèle
|
||||
@commentaires = @dossier.commentaires.order(created_at: :desc)
|
||||
|
||||
@commentaires = @commentaires.all.decorate
|
||||
|
||||
@commentaire_email = @dossier.mail_contact
|
||||
rescue
|
||||
rescue => e
|
||||
|
||||
redirect_to url_for({controller: :start, action: :error_dossier})
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
class Dossier < ActiveRecord::Base
|
||||
has_one :etablissement
|
||||
has_one :entreprise
|
||||
has_many :dossier_pdf
|
||||
has_many :pieces_jointes
|
||||
belongs_to :ref_formulaire
|
||||
has_many :commentaires
|
||||
|
||||
delegate :siren, to: :entreprise
|
||||
delegate :siret, to: :etablissement
|
||||
|
||||
def get_pj piece_jointe_id
|
||||
dossier_pdf.where(ref_pieces_jointes_id: piece_jointe_id).last
|
||||
pieces_jointes.where(ref_pieces_jointes_id: piece_jointe_id).last
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
class DossierPdf < ActiveRecord::Base
|
||||
belongs_to :dossier
|
||||
|
||||
mount_uploader :ref_dossier_pdf, DossierPdfUploader
|
||||
|
||||
def self.get_array_id_pj_valid_for_dossier dossier_id
|
||||
@array_id_pj_valides = Array.new
|
||||
|
||||
DossierPdf.where(dossier_id: dossier_id).each do |pj_valide|
|
||||
@array_id_pj_valides << pj_valide.ref_pieces_jointes_id
|
||||
end
|
||||
|
||||
@array_id_pj_valides
|
||||
end
|
||||
end
|
14
app/models/piece_jointe.rb
Normal file
14
app/models/piece_jointe.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
class PieceJointe < ActiveRecord::Base
|
||||
belongs_to :dossier
|
||||
|
||||
mount_uploader :content, PieceJointeUploader
|
||||
|
||||
def self.get_array_id_pj_valid_for_dossier(dossier_id)
|
||||
@array_id_pj_valides = []
|
||||
where(dossier_id: dossier_id).each do |pj_valide|
|
||||
@array_id_pj_valides << pj_valide.ref_pieces_jointes_id
|
||||
end
|
||||
|
||||
@array_id_pj_valides
|
||||
end
|
||||
end
|
|
@ -1,8 +1,8 @@
|
|||
class RefPiecesJointe < ActiveRecord::Base
|
||||
|
||||
# TODO: test this methods
|
||||
def self.get_liste_piece_jointe ref_formulaire
|
||||
@formulaire = RefFormulaire.find(ref_formulaire)
|
||||
RefPiecesJointe.where ("\"CERFA\" = '#{@formulaire.ref_demarche}'")
|
||||
RefPiecesJointe.where ("\"CERFA\" = '#{ref_formulaire.ref_demarche}'")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# encoding: utf-8
|
||||
|
||||
class DossierPdfUploader < CarrierWave::Uploader::Base
|
||||
class PieceJointeUploader < CarrierWave::Uploader::Base
|
||||
|
||||
# Include RMagick or MiniMagick support:
|
||||
# include CarrierWave::RMagick
|
|
@ -23,7 +23,7 @@
|
|||
='CERFA'
|
||||
%td.col-lg-4.col-md-4
|
||||
- if @array_id_pj_valides.include?(0)
|
||||
%a{ href: "#{@dossier.get_pj(0).ref_dossier_pdf}", target: '_blank' } Consulter
|
||||
%a{ href: "#{@dossier.get_pj(0).content}", target: '_blank' } Consulter
|
||||
- else
|
||||
= 'Pièce non fournie'
|
||||
|
||||
|
@ -35,7 +35,7 @@
|
|||
- if pj.api_entreprise
|
||||
%a{ href: '' } Récupérer
|
||||
- elsif @array_id_pj_valides.include?(pj.id)
|
||||
%a{ href: "#{@dossier.get_pj(pj.id).ref_dossier_pdf}", target: '_blank' } Consulter
|
||||
%a{ href: "#{@dossier.get_pj(pj.id).content}", target: '_blank' } Consulter
|
||||
- else
|
||||
= 'Pièce non fournie'
|
||||
|
||||
|
|
|
@ -4,12 +4,19 @@
|
|||
%div{class:'row', style:'margin-left:5%'}
|
||||
= render partial: 'infos_entreprise'
|
||||
|
||||
= form_tag(url_for({controller: :dossiers, action: :update}), class: 'form-inline', method: 'PUT') do
|
||||
= form_for @dossier do |f|
|
||||
%label{ style:'font-weight:normal' }
|
||||
= f.check_box :autorisation_donnees
|
||||
J'autorise les organismes publics à vérifier les informations de mon entreprise auprès des administrations concernées. Ces informations resteront strictement confidentielles.
|
||||
%br
|
||||
= f.submit 'Etape suivante', class: "btn btn btn-info", style: 'float:right'
|
||||
|
||||
= form_tag(url_for({controller: :dossiers, action: :update, id: @dossier.id}), class: 'form-inline', method: 'PUT') do
|
||||
%br
|
||||
%div
|
||||
%label{ style:'font-weight:normal' }
|
||||
%input{type:'checkbox', name: 'autorisation_donnees', id: 'autorisation_donnees'}
|
||||
='J’autorise les organismes publics à vérifier les informations de mon entreprise auprès des administrations concernées. Ces informations resteront strictement confidentielles.'
|
||||
= "J'autorise les organismes publics à vérifier les informations de mon entreprise auprès des administrations concernées. Ces informations resteront strictement confidentielles."
|
||||
%br
|
||||
%br
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ Rails.application.configure do
|
|||
# Debug mode disables concatenation and preprocessing of assets.
|
||||
# This option may cause significant delays in view rendering with a large
|
||||
# number of complex assets.
|
||||
config.assets.debug = true
|
||||
config.assets.debug = false
|
||||
|
||||
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
|
||||
# yet still be able to expire them through the digest params.
|
||||
|
|
|
@ -3,12 +3,14 @@
|
|||
# Add new inflection rules using the following format. Inflections
|
||||
# are locale specific, and you may define rules for as many different
|
||||
# locales as you wish. All of these examples are active by default:
|
||||
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
||||
# inflect.plural /^(ox)$/i, '\1en'
|
||||
# inflect.singular /^(ox)en/i, '\1'
|
||||
# inflect.irregular 'person', 'people'
|
||||
# inflect.uncountable %w( fish sheep )
|
||||
# end
|
||||
ActiveSupport::Inflector.inflections(:en) do |inflect|
|
||||
# inflect.plural /^(ox)$/i, '\1en'
|
||||
# inflect.singular /^(ox)en/i, '\1'
|
||||
# inflect.irregular 'person', 'people'
|
||||
# inflect.uncountable %w( fish sheep )
|
||||
inflect.irregular 'piece_jointe', 'pieces_jointes'
|
||||
|
||||
end
|
||||
|
||||
# These inflection rules are supported but not enabled by default:
|
||||
# ActiveSupport::Inflector.inflections(:en) do |inflect|
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
class FixRefFormulaireToDossier < ActiveRecord::Migration
|
||||
def change
|
||||
remove_column :dossiers, :ref_formulaire, :integer
|
||||
add_reference :dossiers, :ref_formulaire, index: true
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class RenameRefDossierPdfIntoContent < ActiveRecord::Migration
|
||||
def change
|
||||
rename_column :dossier_pdfs, :ref_dossier_pdf, :content
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class RenameDossierPdfintofPieceJointe < ActiveRecord::Migration
|
||||
def change
|
||||
rename_table :dossier_pdfs, :pieces_jointes
|
||||
end
|
||||
end
|
22
db/schema.rb
22
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: 20150810130957) do
|
||||
ActiveRecord::Schema.define(version: 20150813095939) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -26,14 +26,6 @@ ActiveRecord::Schema.define(version: 20150810130957) do
|
|||
|
||||
add_index "commentaires", ["dossier_id"], name: "index_commentaires_on_dossier_id", using: :btree
|
||||
|
||||
create_table "dossier_pdfs", force: :cascade do |t|
|
||||
t.string "ref_dossier_pdf"
|
||||
t.integer "dossier_id"
|
||||
t.integer "ref_pieces_jointes_id"
|
||||
end
|
||||
|
||||
add_index "dossier_pdfs", ["ref_pieces_jointes_id"], name: "index_dossier_pdfs_on_ref_pieces_jointes_id", using: :btree
|
||||
|
||||
create_table "dossiers", force: :cascade do |t|
|
||||
t.string "description"
|
||||
t.boolean "autorisation_donnees"
|
||||
|
@ -47,9 +39,11 @@ ActiveRecord::Schema.define(version: 20150810130957) do
|
|||
t.string "lien_plus_infos"
|
||||
t.string "mail_contact"
|
||||
t.boolean "dossier_termine"
|
||||
t.string "ref_formulaire"
|
||||
t.integer "ref_formulaire_id"
|
||||
end
|
||||
|
||||
add_index "dossiers", ["ref_formulaire_id"], name: "index_dossiers_on_ref_formulaire_id", using: :btree
|
||||
|
||||
create_table "entreprises", force: :cascade do |t|
|
||||
t.string "siren"
|
||||
t.integer "capital_social"
|
||||
|
@ -90,6 +84,14 @@ ActiveRecord::Schema.define(version: 20150810130957) do
|
|||
t.boolean "use_admi_facile"
|
||||
end
|
||||
|
||||
create_table "pieces_jointes", force: :cascade do |t|
|
||||
t.string "content"
|
||||
t.integer "dossier_id"
|
||||
t.integer "ref_pieces_jointes_id"
|
||||
end
|
||||
|
||||
add_index "pieces_jointes", ["ref_pieces_jointes_id"], name: "index_pieces_jointes_on_ref_pieces_jointes_id", using: :btree
|
||||
|
||||
create_table "pros", force: :cascade do |t|
|
||||
t.string "email", default: "", null: false
|
||||
t.string "encrypted_password", default: "", null: false
|
||||
|
|
19
db/seeds.rb
19
db/seeds.rb
|
@ -8,24 +8,5 @@
|
|||
|
||||
Dir[File.join(Rails.root, 'db', 'seeds', '*.rb')].sort.each { |seed| load seed }
|
||||
|
||||
#SEEDS DEV, TEST
|
||||
User.create({
|
||||
email: 'test@localhost.com',
|
||||
password: 'password'
|
||||
})
|
||||
|
||||
@dossier = Dossier.create({
|
||||
id: 10000,
|
||||
nom_projet: 'Projet de test',
|
||||
description: 'Description de test.',
|
||||
montant_projet: 12000,
|
||||
montant_aide_demande: 3000,
|
||||
date_previsionnelle: '20/01/2016',
|
||||
mail_contact: 'test@test.com',
|
||||
ref_formulaire: '12'
|
||||
})
|
||||
|
||||
@entreprise = Entreprise.create({id: 10000, siren: 431449040, date_creation: 1437665347, dossier: @dossier, raison_sociale: 'Coucou', code_effectif_entreprise: '00'})
|
||||
@etablissement = Etablissement.create({id: 10000, siret: 43144904000028, siege_social: true, adresse: '50 avenue des champs élysées Paris 75008', entreprise: @entreprise, dossier: @dossier})
|
||||
|
||||
Commentaire.create({email: 'test@test.com', body: 'Commentaire de test', dossier: @dossier})
|
|
@ -1,8 +1,9 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Admin::DossierController, type: :controller do
|
||||
let (:dossier_id){10000}
|
||||
let (:bad_dossier_id){10}
|
||||
let(:dossier) { create(:dossier, :with_entreprise) }
|
||||
let (:dossier_id) { dossier.id }
|
||||
let (:bad_dossier_id) { Dossier.count + 10 }
|
||||
|
||||
describe "GET #show" do
|
||||
context 'l\'utilisateur est connecté' do
|
||||
|
@ -12,7 +13,7 @@ RSpec.describe Admin::DossierController, type: :controller do
|
|||
|
||||
it "returns http success" do
|
||||
get :show, :dossier_id => dossier_id
|
||||
expect(response).to have_http_status(302)
|
||||
expect(response).to have_http_status(200)
|
||||
end
|
||||
|
||||
it 'le numéro de dossier n\'existe pas' do
|
||||
|
@ -30,6 +31,7 @@ RSpec.describe Admin::DossierController, type: :controller do
|
|||
end
|
||||
|
||||
describe "GET #index" do
|
||||
let(:user) { create(:user) }
|
||||
before do
|
||||
sign_in
|
||||
end
|
||||
|
|
|
@ -1,13 +1,19 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe CarteController, type: :controller do
|
||||
let(:dossier_id){10000}
|
||||
let(:bad_dossier_id){1000}
|
||||
let(:ref_dossier){'IATRQPQY'}
|
||||
let(:adresse){'50 avenue des champs élysées Paris 75008'}
|
||||
|
||||
let(:bad_adresse){'babouba'}
|
||||
|
||||
|
||||
let(:dossier) { create(:dossier) }
|
||||
let!(:entreprise) { create(:entreprise, dossier: dossier) }
|
||||
let!(:etablissement) { create(:etablissement, dossier: dossier) }
|
||||
let(:dossier_id) { dossier.id }
|
||||
let(:bad_dossier_id) { Dossier.count + 10 }
|
||||
let(:ref_dossier) { 'IATRQPQY' }
|
||||
let(:adresse) { etablissement.adresse }
|
||||
|
||||
|
||||
describe "GET #show" do
|
||||
it "returns http success" do
|
||||
get :show, dossier_id: dossier_id
|
||||
|
@ -96,7 +102,7 @@ RSpec.describe CarteController, type: :controller do
|
|||
end
|
||||
|
||||
it 'dossier_id' do
|
||||
expect(subject['dossier_id']).to eq('10000')
|
||||
expect(subject['dossier_id']).to eq(dossier.id.to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe CommentairesController, type: :controller do
|
||||
let (:dossier_id){10000}
|
||||
let (:email_commentaire){'test@test.com'}
|
||||
let (:texte_commentaire){'Commentaire de test'}
|
||||
let(:dossier) { create(:dossier) }
|
||||
let (:dossier_id) { dossier.id }
|
||||
let (:email_commentaire) { 'test@test.com' }
|
||||
let (:texte_commentaire) { 'Commentaire de test' }
|
||||
|
||||
describe '#POST create' do
|
||||
context 'création correct d\'un commentaire' do
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe DemandesController, type: :controller do
|
||||
|
||||
let (:dossier_id){10000}
|
||||
let(:dossier) { create(:dossier) }
|
||||
let (:dossier_id) { dossier.id }
|
||||
|
||||
describe "GET #show" do
|
||||
it "returns http success" do
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe DescriptionController, type: :controller do
|
||||
let (:dossier_id){10000}
|
||||
let (:bad_dossier_id){1000}
|
||||
let(:dossier) { create(:dossier) }
|
||||
let (:dossier_id) { dossier.id }
|
||||
let (:bad_dossier_id) { Dossier.count + 10 }
|
||||
|
||||
describe "GET #show" do
|
||||
it "returns http success" do
|
||||
|
@ -25,11 +26,11 @@ describe DescriptionController, type: :controller do
|
|||
let(:date_previsionnelle){'20/01/2016'}
|
||||
let(:mail_contact){'test@test.com'}
|
||||
|
||||
let(:name_dossier_pdf){'dossierPDF.pdf'}
|
||||
let(:name_piece_jointe){'dossierPDF.pdf'}
|
||||
let(:name_piece_jointe_103){'piece_jointe_103.pdf'}
|
||||
let(:name_piece_jointe_692){'piece_jointe_692.pdf'}
|
||||
|
||||
let(:cerfa_pdf) {Rack::Test::UploadedFile.new("./spec/support/files/#{name_dossier_pdf}", 'application/pdf')}
|
||||
let(:cerfa_pdf) {Rack::Test::UploadedFile.new("./spec/support/files/#{name_piece_jointe}", 'application/pdf')}
|
||||
let(:piece_jointe_103) {Rack::Test::UploadedFile.new("./spec/support/files/#{name_piece_jointe_103}", 'application/pdf')}
|
||||
let(:piece_jointe_692) {Rack::Test::UploadedFile.new("./spec/support/files/#{name_piece_jointe_692}", 'application/pdf')}
|
||||
|
||||
|
@ -114,9 +115,9 @@ describe DescriptionController, type: :controller do
|
|||
end
|
||||
|
||||
context 'un CERFA PDF est envoyé' do
|
||||
subject{DossierPdf.last}
|
||||
it 'ref_dossier_pdf' do
|
||||
expect(subject['ref_dossier_pdf']).to eq(name_dossier_pdf)
|
||||
subject{PieceJointe.last}
|
||||
it 'content' do
|
||||
expect(subject['content']).to eq(name_piece_jointe)
|
||||
end
|
||||
|
||||
it 'dossier_id' do
|
||||
|
@ -131,7 +132,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
|
||||
cerfa = DossierPdf.where(ref_pieces_jointes_id: '0', dossier_id: dossier_id)
|
||||
cerfa = PieceJointe.where(ref_pieces_jointes_id: '0', dossier_id: dossier_id)
|
||||
expect(cerfa.many?).to eq(false)
|
||||
end
|
||||
end
|
||||
|
@ -148,19 +149,20 @@ describe DescriptionController, type: :controller do
|
|||
|
||||
context 'sauvegarde de 2 pieces jointes' do
|
||||
it 'les deux pièces sont présentes en base' do
|
||||
piece_jointe_1 = DossierPdf.where(ref_pieces_jointes_id: '103', dossier_id: dossier_id)
|
||||
piece_jointe_2 = DossierPdf.where(ref_pieces_jointes_id: '692', dossier_id: dossier_id)
|
||||
piece_jointe_1 = PieceJointe.where(ref_pieces_jointes_id: '103', dossier_id: dossier_id)
|
||||
piece_jointe_2 = PieceJointe.where(ref_pieces_jointes_id: '692', dossier_id: dossier_id)
|
||||
|
||||
expect(piece_jointe_1.first['ref_dossier_pdf']).to eq(name_piece_jointe_103)
|
||||
expect(piece_jointe_2.first['ref_dossier_pdf']).to eq(name_piece_jointe_692)
|
||||
expect(piece_jointe_1.first['content']).to eq(name_piece_jointe_103)
|
||||
expect(piece_jointe_2.first['content']).to eq(name_piece_jointe_692)
|
||||
end
|
||||
|
||||
# TODO: refactor
|
||||
context 'les pièces sont ecrasées à chaque fois' 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
|
||||
|
||||
piece_jointe_1 = DossierPdf.where(ref_pieces_jointes_id: '103', dossier_id: dossier_id)
|
||||
piece_jointe_2 = DossierPdf.where(ref_pieces_jointes_id: '692', dossier_id: dossier_id)
|
||||
piece_jointe_1 = PieceJointe.where(ref_pieces_jointes_id: '103', dossier_id: dossier_id)
|
||||
piece_jointe_2 = PieceJointe.where(ref_pieces_jointes_id: '692', dossier_id: dossier_id)
|
||||
|
||||
expect(piece_jointe_1.many?).to eq(false)
|
||||
expect(piece_jointe_2.many?).to eq(false)
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe DossiersController, type: :controller do
|
||||
let (:dossier_id){10000}
|
||||
let (:bad_dossier_id){1000}
|
||||
let (:autorisation_donnees){'on'}
|
||||
let(:dossier) { create(:dossier, :with_entreprise) }
|
||||
let (:dossier_id) { dossier.id }
|
||||
let (:bad_dossier_id) { Dossier.count + 10 }
|
||||
# let (:autorisation_donnees){'on'}
|
||||
|
||||
let (:siren){431449040}
|
||||
let (:siret){43144904000028}
|
||||
let (:siren) { dossier.siren }
|
||||
let (:siret) { dossier.siret }
|
||||
let (:bad_siret){1}
|
||||
|
||||
describe 'GET #show' do
|
||||
|
@ -62,23 +63,30 @@ RSpec.describe DossiersController, type: :controller do
|
|||
end
|
||||
|
||||
describe 'PUT #update' do
|
||||
it 'Checkbox conditions validée' do
|
||||
put :update, :id => dossier_id, :autorisation_donnees => autorisation_donnees
|
||||
expect(response).to redirect_to("/dossiers/#{dossier_id}/demande")
|
||||
context 'when Checkbox is checked' do
|
||||
it 'redirects to demande' do
|
||||
put :update, :id => dossier_id, dossier: { autorisation_donnees: '1' }
|
||||
expect(response).to redirect_to("/dossiers/#{dossier_id}/demande")
|
||||
end
|
||||
|
||||
it 'update dossier' do
|
||||
put :update, :id => dossier_id, dossier: { autorisation_donnees: '1' }
|
||||
dossier = Dossier.find(dossier_id)
|
||||
expect(dossier.autorisation_donnees).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
context 'Checkbox conditions non validée' do
|
||||
before do
|
||||
put :update, :id => dossier_id
|
||||
end
|
||||
|
||||
it 'affichage alert' do
|
||||
expect(flash[:alert]).to be_present
|
||||
end
|
||||
|
||||
it 'Affichage message d\'erreur condition non validé' do
|
||||
context 'when Checkbox is not checked' do
|
||||
it 'uses flash alert to display message' do
|
||||
put :update, :id => dossier_id, dossier: { autorisation_donnees: '0' }
|
||||
expect(flash[:alert]).to have_content('Les conditions sont obligatoires.')
|
||||
end
|
||||
|
||||
it "doesn't update dossier autorisation_donnees" do
|
||||
put :update, :id => dossier_id, dossier: { autorisation_donnees: '0' }
|
||||
dossier = Dossier.find(dossier_id)
|
||||
expect(dossier.autorisation_donnees).to be_falsy
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
require 'spec_helper'
|
||||
|
||||
RSpec.describe RecapitulatifController, type: :controller do
|
||||
let (:dossier_id){10000}
|
||||
let (:bad_dossier_id){1000}
|
||||
let(:dossier) { create(:dossier) }
|
||||
|
||||
let (:bad_dossier_id) { Dossier.count + 10 }
|
||||
|
||||
describe "GET #show" do
|
||||
it "returns http success" do
|
||||
get :show, :dossier_id => dossier_id
|
||||
get :show, dossier_id: dossier.id
|
||||
expect(response).to have_http_status(:success)
|
||||
end
|
||||
|
||||
it 'redirection vers start si mauvais dossier ID' do
|
||||
get :show, :dossier_id => bad_dossier_id
|
||||
get :show, dossier_id: bad_dossier_id
|
||||
expect(response).to redirect_to('/start/error_dossier')
|
||||
end
|
||||
end
|
||||
|
|
5
spec/factories/commentaire.rb
Normal file
5
spec/factories/commentaire.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
FactoryGirl.define do
|
||||
factory :commentaire do
|
||||
|
||||
end
|
||||
end
|
14
spec/factories/dossier.rb
Normal file
14
spec/factories/dossier.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
FactoryGirl.define do
|
||||
factory :dossier do
|
||||
ref_formulaire_id 12
|
||||
|
||||
trait :with_entreprise do
|
||||
after(:build) do |dossier, evaluator|
|
||||
etablissement = create(:etablissement)
|
||||
entreprise = create(:entreprise, etablissement: etablissement)
|
||||
dossier.entreprise = entreprise
|
||||
dossier.etablissement = etablissement
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
14
spec/factories/entreprise.rb
Normal file
14
spec/factories/entreprise.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
FactoryGirl.define do
|
||||
factory :entreprise do
|
||||
siren '440117620'
|
||||
capital_social 537_100_000
|
||||
numero_tva_intracommunautaire 'FR27440117620'
|
||||
forme_juridique 'SA à conseil d\'administration (s.a.i.)'
|
||||
forme_juridique_code '5599'
|
||||
nom_commercial 'GRTGAZ'
|
||||
raison_sociale 'GRTGAZ'
|
||||
siret_siege_social '44011762001530'
|
||||
code_effectif_entreprise '51'
|
||||
date_creation 1_004_914_800
|
||||
end
|
||||
end
|
16
spec/factories/etablissement.rb
Normal file
16
spec/factories/etablissement.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
FactoryGirl.define do
|
||||
factory :etablissement do
|
||||
siret '44011762001530'
|
||||
siege_social true
|
||||
naf '4950Z'
|
||||
libelle_naf 'Transports par conduites'
|
||||
adresse "GRTGAZ\r IMMEUBLE BORA\r 6 RUE RAOUL NORDLING\r 92270 BOIS COLOMBES\r"
|
||||
numero_voie '6'
|
||||
type_voie 'RUE'
|
||||
nom_voie 'RAOUL NORDLING'
|
||||
complement_adresse 'IMMEUBLE BORA'
|
||||
code_postal '92270'
|
||||
localite 'BOIS COLOMBES'
|
||||
code_insee_localite '92009'
|
||||
end
|
||||
end
|
5
spec/factories/piece_jointe.rb
Normal file
5
spec/factories/piece_jointe.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
FactoryGirl.define do
|
||||
factory :piece_jointe do
|
||||
|
||||
end
|
||||
end
|
6
spec/factories/user.rb
Normal file
6
spec/factories/user.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
FactoryGirl.define do
|
||||
factory :user do
|
||||
email 'toto@sgmap.fr'
|
||||
password 'password'
|
||||
end
|
||||
end
|
|
@ -2,10 +2,12 @@ require 'spec_helper'
|
|||
|
||||
feature '_Commentaires_Flux Admin/Dossier#Show Page' do
|
||||
|
||||
let(:dossier_id){10000}
|
||||
let(:email_pre_rempli){'test@localhost.com'}
|
||||
let(:email_commentaire){'test@test.com'}
|
||||
let(:body){'Commentaire de test'}
|
||||
let(:dossier) { create(:dossier, :with_entreprise) }
|
||||
let(:dossier_id) { dossier.id }
|
||||
let!(:commentaire) { create(:commentaire, dossier: dossier, email: 'toto@toto.com')}
|
||||
let(:email_commentaire) { 'test@test.com' }
|
||||
let(:email_pre_rempli) { 'toto@sgmap.fr' }
|
||||
let(:body) { 'Commentaire de test' }
|
||||
|
||||
before do
|
||||
login_admin
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'Admin/Dossier#Show Page' do
|
||||
let(:dossier_id){10000}
|
||||
let(:dossier) { create(:dossier, :with_entreprise) }
|
||||
let(:dossier_id) { dossier.id }
|
||||
|
||||
before do
|
||||
login_admin
|
||||
|
@ -61,9 +62,10 @@ feature 'Admin/Dossier#Show Page' do
|
|||
context 'Devis' do
|
||||
let(:id_piece_jointe){388}
|
||||
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) }
|
||||
|
||||
before do
|
||||
DossierPdf.create(dossier_id: dossier_id, ref_pieces_jointes_id: id_piece_jointe, ref_dossier_pdf: piece_jointe_388)
|
||||
visit "/admin/dossier/#{dossier_id}"
|
||||
end
|
||||
|
||||
scenario 'la ligne de la pièce jointe est présente' do
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'Carte#Show Page' do
|
||||
let (:dossier_id){10000}
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:dossier_id) { dossier.id }
|
||||
|
||||
before do
|
||||
visit "/dossiers/#{dossier_id}/carte"
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'Demandes#Show Page' do
|
||||
let (:dossier_id){10000}
|
||||
let(:dossier) { create(:dossier)}
|
||||
let (:dossier_id) { dossier.id }
|
||||
|
||||
before do
|
||||
visit "/dossiers/#{dossier_id}/demande"
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'Description#Show Page' do
|
||||
let (:dossier_id){10000}
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:dossier_id) { dossier.id }
|
||||
|
||||
before do
|
||||
visit "/dossiers/#{dossier_id}/description"
|
||||
|
@ -90,35 +91,38 @@ feature 'Description#Show Page' do
|
|||
end
|
||||
|
||||
context 'les valeurs sont réaffichées si elles sont présentes dans la BDD' do
|
||||
let(:nom_projet){'Projet de test'}
|
||||
let(:description){'Description de test.'}
|
||||
let(:montant_projet){12000}
|
||||
let(:montant_aide_demande){3000}
|
||||
let(:date_previsionnelle){'20/01/2016'}
|
||||
let(:mail_contact){'test@test.com'}
|
||||
let(:dossier) do
|
||||
create(:dossier,
|
||||
nom_projet: 'Projet de test',
|
||||
description: 'Description de test',
|
||||
montant_projet: 12_000,
|
||||
montant_aide_demande: 3000,
|
||||
date_previsionnelle: '20/01/2016',
|
||||
mail_contact: 'test@test.com')
|
||||
end
|
||||
|
||||
scenario 'Nom du projet' do
|
||||
expect(page).to have_selector("input[id=nom_projet][value='#{nom_projet}']")
|
||||
expect(page).to have_selector("input[id=nom_projet][value='#{dossier.nom_projet}']")
|
||||
end
|
||||
|
||||
scenario 'Description du projet' do
|
||||
expect(page).to have_content("#{description}")
|
||||
expect(page).to have_content("#{dossier.description}")
|
||||
end
|
||||
|
||||
scenario 'Montant du projet' do
|
||||
expect(page).to have_selector("input[id=montant_projet][value='#{montant_projet}']")
|
||||
expect(page).to have_selector("input[id=montant_projet][value='#{dossier.montant_projet}']")
|
||||
end
|
||||
|
||||
scenario 'Montant des aides du projet' do
|
||||
expect(page).to have_selector("input[id=montant_aide_demande][value='#{montant_aide_demande}']")
|
||||
expect(page).to have_selector("input[id=montant_aide_demande][value='#{dossier.montant_aide_demande}']")
|
||||
end
|
||||
|
||||
scenario 'Date prévisionnelle du projet' do
|
||||
expect(page).to have_selector("input[id=date_previsionnelle][value='#{date_previsionnelle}']")
|
||||
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='#{mail_contact}']")
|
||||
expect(page).to have_selector("input[id=mail_contact][value='#{dossier.mail_contact}']")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'Dossier#Show Page' do
|
||||
let (:dossier_id){10000}
|
||||
let(:dossier) { create(:dossier, :with_entreprise) }
|
||||
|
||||
let(:dossier_id) { dossier.id }
|
||||
|
||||
before do
|
||||
visit "/dossiers/#{dossier_id}"
|
||||
|
@ -21,7 +23,7 @@ feature 'Dossier#Show Page' do
|
|||
end
|
||||
|
||||
scenario 'le texte d\'information des droits est correct' do
|
||||
expect(page).to have_content ("J’autorise les organismes publics à vérifier les informations de mon entreprise auprès des administrations concernées. Ces informations resteront strictement confidentielles.")
|
||||
expect(page).to have_content ("J'autorise les organismes publics à vérifier les informations de mon entreprise auprès des administrations concernées. Ces informations resteront strictement confidentielles.")
|
||||
end
|
||||
|
||||
scenario 'les informations de l\'entreprise sont présents' do
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature '_Commentaires_Flux Recapitulatif#Show Page' do
|
||||
|
||||
let(:dossier_id){10000}
|
||||
let(:email_commentaire){'test@test.com'}
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:dossier_id) { dossier.id }
|
||||
let(:email_commentaire) { 'mon_mail_de_commentaire@test.com' }
|
||||
let!(:commentaire) { create(:commentaire, dossier: dossier, email: email_commentaire, body: 'ma super description') }
|
||||
let(:body){'Commentaire de test'}
|
||||
|
||||
before do
|
||||
|
@ -39,7 +40,7 @@ feature '_Commentaires_Flux Recapitulatif#Show Page' do
|
|||
end
|
||||
|
||||
scenario 'Champs email est prérempli' do
|
||||
expect(page).to have_selector("input[id=email_commentaire][value='#{email_commentaire}']")
|
||||
expect(page).to have_content(email_commentaire)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,7 +2,8 @@ require 'spec_helper'
|
|||
|
||||
|
||||
feature 'Recapitulatif#Show Page' do
|
||||
let(:dossier_id){10000}
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:dossier_id) { dossier.id }
|
||||
|
||||
before do
|
||||
Capybara.current_session.driver.header('Referer', '/description')
|
||||
|
|
22
spec/models/dossier_spec.rb
Normal file
22
spec/models/dossier_spec.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Dossier do
|
||||
let(:dossier) { create(:dossier, :with_entreprise) }
|
||||
|
||||
let(:entreprise) { dossier.entreprise }
|
||||
let(:etablissement) { dossier.etablissement }
|
||||
|
||||
subject { dossier }
|
||||
|
||||
describe '#siren' do
|
||||
it 'returns entreprise siren' do
|
||||
expect(subject.siren).to eq(entreprise.siren)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#siret' do
|
||||
it 'returns etablissement siret' do
|
||||
expect(subject.siret).to eq(etablissement.siret)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -45,14 +45,8 @@ Dir[Rails.root.join("spec/factories/**/*.rb")].each { |f| require f }
|
|||
# If you are not using ActiveRecord, you can remove this line.
|
||||
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
|
||||
|
||||
class ActiveRecord::Base
|
||||
mattr_accessor :shared_connection
|
||||
@@shared_connection = nil
|
||||
DatabaseCleaner.strategy = :truncation, {:except => %w[evenement_vies ref_formulaires ref_pieces_jointes]}
|
||||
|
||||
def self.connection
|
||||
@@shared_connection || retrieve_connection
|
||||
end
|
||||
end
|
||||
|
||||
if !(defined? SIADETOKEN)
|
||||
SIADETOKEN = :valid_token
|
||||
|
|
|
@ -5,7 +5,7 @@ module ControllerHelpers
|
|||
allow(controller).to receive(:current_user).and_return(nil)
|
||||
else
|
||||
allow(request.env['warden']).to receive(:authenticate!).and_return(user)
|
||||
allow(controller).to receive(:current_user).and_return({:email => 'test@localhost.com'})
|
||||
allow(controller).to receive(:current_user).and_return(create(:user))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
21
spec/support/database_cleaner.rb
Normal file
21
spec/support/database_cleaner.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
RSpec.configure do |config|
|
||||
config.before(:suite) do
|
||||
DatabaseCleaner.clean_with(:truncation, {:except => %w[evenement_vies ref_formulaires ref_pieces_jointes]})
|
||||
end
|
||||
|
||||
config.before(:each) do
|
||||
DatabaseCleaner.strategy = :transaction
|
||||
end
|
||||
|
||||
# config.before(:each, :js => true) do
|
||||
# DatabaseCleaner.strategy = :truncation, {:except => %w[evenement_vies ref_formulaires ref_pieces_jointes]}
|
||||
# end
|
||||
|
||||
config.before(:each) do
|
||||
DatabaseCleaner.start
|
||||
end
|
||||
|
||||
config.after(:each) do
|
||||
DatabaseCleaner.clean
|
||||
end
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
module FeatureHelpers
|
||||
def login_admin
|
||||
user = User.first
|
||||
user = create :user
|
||||
login_as user, scope: :user
|
||||
user
|
||||
end
|
||||
|
|
15
spec/views/dossiers/show.html.haml_spec.rb
Normal file
15
spec/views/dossiers/show.html.haml_spec.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe 'dossiers/show.html.haml', type: :view do
|
||||
let(:dossier) { create(:dossier, :with_entreprise) }
|
||||
before do
|
||||
assign(:dossier, dossier)
|
||||
assign(:entreprise, dossier.entreprise.decorate)
|
||||
assign(:etablissement, dossier.etablissement)
|
||||
|
||||
render
|
||||
end
|
||||
it 'have autorisation_donnees check box' do
|
||||
expect(rendered).to have_css('#autorisation_donnees')
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue