diff --git a/.gitignore b/.gitignore index 6259848bb..bc326eca0 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,6 @@ *.iml *.iws -public/uploads \ No newline at end of file +public/uploads +bin/* +config/initializers/token.rb diff --git a/Gemfile.lock b/Gemfile.lock index 1b2289a41..5a3b6a5f5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -332,6 +332,3 @@ DEPENDENCIES uglifier (>= 1.3.0) web-console (~> 2.0) webmock - -BUNDLED WITH - 1.10.4 diff --git a/app/controllers/admin/dossier_controller.rb b/app/controllers/admin/dossier_controller.rb index f28a4e532..1f0b7647c 100644 --- a/app/controllers/admin/dossier_controller.rb +++ b/app/controllers/admin/dossier_controller.rb @@ -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 diff --git a/app/controllers/demandes_controller.rb b/app/controllers/demandes_controller.rb index b8fdfdf24..f184703b8 100644 --- a/app/controllers/demandes_controller.rb +++ b/app/controllers/demandes_controller.rb @@ -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 diff --git a/app/controllers/description_controller.rb b/app/controllers/description_controller.rb index d9e0dc12f..9e3eb8abf 100644 --- a/app/controllers/description_controller.rb +++ b/app/controllers/description_controller.rb @@ -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 diff --git a/app/controllers/dossiers_controller.rb b/app/controllers/dossiers_controller.rb index 707afdf8e..a04a219dd 100644 --- a/app/controllers/dossiers_controller.rb +++ b/app/controllers/dossiers_controller.rb @@ -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 diff --git a/app/controllers/recapitulatif_controller.rb b/app/controllers/recapitulatif_controller.rb index 4389ae781..7f5bf4f87 100644 --- a/app/controllers/recapitulatif_controller.rb +++ b/app/controllers/recapitulatif_controller.rb @@ -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 diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 9930f53fe..ac0c976f2 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -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 diff --git a/app/models/dossier_pdf.rb b/app/models/dossier_pdf.rb deleted file mode 100644 index 948cd53db..000000000 --- a/app/models/dossier_pdf.rb +++ /dev/null @@ -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 diff --git a/app/models/piece_jointe.rb b/app/models/piece_jointe.rb new file mode 100644 index 000000000..149316072 --- /dev/null +++ b/app/models/piece_jointe.rb @@ -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 diff --git a/app/models/ref_pieces_jointe.rb b/app/models/ref_pieces_jointe.rb index cd8c2525b..978903810 100644 --- a/app/models/ref_pieces_jointe.rb +++ b/app/models/ref_pieces_jointe.rb @@ -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 diff --git a/app/uploaders/dossier_pdf_uploader.rb b/app/uploaders/piece_jointe_uploader.rb similarity index 96% rename from app/uploaders/dossier_pdf_uploader.rb rename to app/uploaders/piece_jointe_uploader.rb index bce5495af..d0b61c57b 100644 --- a/app/uploaders/dossier_pdf_uploader.rb +++ b/app/uploaders/piece_jointe_uploader.rb @@ -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 diff --git a/app/views/admin/dossier/show.html.haml b/app/views/admin/dossier/show.html.haml index 651a0553e..44494fda2 100644 --- a/app/views/admin/dossier/show.html.haml +++ b/app/views/admin/dossier/show.html.haml @@ -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' diff --git a/app/views/dossiers/show.html.haml b/app/views/dossiers/show.html.haml index e8257500c..5116ec48d 100644 --- a/app/views/dossiers/show.html.haml +++ b/app/views/dossiers/show.html.haml @@ -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 diff --git a/config/environments/development.rb b/config/environments/development.rb index 5fafdd184..d803d0a2d 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -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. diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index ac033bf9d..dc5fe76ad 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -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| diff --git a/db/migrate/20150812091703_fix_ref_formulaire_to_dossier.rb b/db/migrate/20150812091703_fix_ref_formulaire_to_dossier.rb new file mode 100644 index 000000000..fa9b7ef54 --- /dev/null +++ b/db/migrate/20150812091703_fix_ref_formulaire_to_dossier.rb @@ -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 diff --git a/db/migrate/20150813095218_rename_ref_dossier_pdf_into_content.rb b/db/migrate/20150813095218_rename_ref_dossier_pdf_into_content.rb new file mode 100644 index 000000000..a1566f4f8 --- /dev/null +++ b/db/migrate/20150813095218_rename_ref_dossier_pdf_into_content.rb @@ -0,0 +1,5 @@ +class RenameRefDossierPdfIntoContent < ActiveRecord::Migration + def change + rename_column :dossier_pdfs, :ref_dossier_pdf, :content + end +end diff --git a/db/migrate/20150813095939_rename_dossier_pdfintof_piece_jointe.rb b/db/migrate/20150813095939_rename_dossier_pdfintof_piece_jointe.rb new file mode 100644 index 000000000..43bf00714 --- /dev/null +++ b/db/migrate/20150813095939_rename_dossier_pdfintof_piece_jointe.rb @@ -0,0 +1,5 @@ +class RenameDossierPdfintofPieceJointe < ActiveRecord::Migration + def change + rename_table :dossier_pdfs, :pieces_jointes + end +end diff --git a/db/schema.rb b/db/schema.rb index 773e43828..b417dfe26 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: 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 diff --git a/db/seeds.rb b/db/seeds.rb index f14ca5a70..0976c496f 100644 --- a/db/seeds.rb +++ b/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}) \ No newline at end of file diff --git a/spec/controllers/admin/dossier_controller_spec.rb b/spec/controllers/admin/dossier_controller_spec.rb index f078945c6..93a975ae0 100644 --- a/spec/controllers/admin/dossier_controller_spec.rb +++ b/spec/controllers/admin/dossier_controller_spec.rb @@ -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 diff --git a/spec/controllers/carte_controller_spec.rb b/spec/controllers/carte_controller_spec.rb index 78fd4590c..91345a89b 100644 --- a/spec/controllers/carte_controller_spec.rb +++ b/spec/controllers/carte_controller_spec.rb @@ -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 diff --git a/spec/controllers/commentaires_controller_spec.rb b/spec/controllers/commentaires_controller_spec.rb index 14e1e1321..1c24f9ec6 100644 --- a/spec/controllers/commentaires_controller_spec.rb +++ b/spec/controllers/commentaires_controller_spec.rb @@ -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 diff --git a/spec/controllers/demandes_controller_spec.rb b/spec/controllers/demandes_controller_spec.rb index 61e1f3074..e64cf07fd 100644 --- a/spec/controllers/demandes_controller_spec.rb +++ b/spec/controllers/demandes_controller_spec.rb @@ -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 diff --git a/spec/controllers/description_controller_spec.rb b/spec/controllers/description_controller_spec.rb index 81b01087e..6d8b7c30d 100644 --- a/spec/controllers/description_controller_spec.rb +++ b/spec/controllers/description_controller_spec.rb @@ -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) diff --git a/spec/controllers/dossiers_controller_spec.rb b/spec/controllers/dossiers_controller_spec.rb index 41cc85946..3c67d5787 100644 --- a/spec/controllers/dossiers_controller_spec.rb +++ b/spec/controllers/dossiers_controller_spec.rb @@ -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 diff --git a/spec/controllers/recapitulatif_controller_spec.rb b/spec/controllers/recapitulatif_controller_spec.rb index 98fc6f433..5f3ac97f4 100644 --- a/spec/controllers/recapitulatif_controller_spec.rb +++ b/spec/controllers/recapitulatif_controller_spec.rb @@ -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 diff --git a/spec/factories/commentaire.rb b/spec/factories/commentaire.rb new file mode 100644 index 000000000..ef0eb0685 --- /dev/null +++ b/spec/factories/commentaire.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :commentaire do + + end +end \ No newline at end of file diff --git a/spec/factories/dossier.rb b/spec/factories/dossier.rb new file mode 100644 index 000000000..fbdae4f17 --- /dev/null +++ b/spec/factories/dossier.rb @@ -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 \ No newline at end of file diff --git a/spec/factories/entreprise.rb b/spec/factories/entreprise.rb new file mode 100644 index 000000000..4343fb45c --- /dev/null +++ b/spec/factories/entreprise.rb @@ -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 \ No newline at end of file diff --git a/spec/factories/etablissement.rb b/spec/factories/etablissement.rb new file mode 100644 index 000000000..7476f5d98 --- /dev/null +++ b/spec/factories/etablissement.rb @@ -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 \ No newline at end of file diff --git a/spec/factories/piece_jointe.rb b/spec/factories/piece_jointe.rb new file mode 100644 index 000000000..16457efaf --- /dev/null +++ b/spec/factories/piece_jointe.rb @@ -0,0 +1,5 @@ +FactoryGirl.define do + factory :piece_jointe do + + end +end \ No newline at end of file diff --git a/spec/factories/user.rb b/spec/factories/user.rb new file mode 100644 index 000000000..b43f71428 --- /dev/null +++ b/spec/factories/user.rb @@ -0,0 +1,6 @@ +FactoryGirl.define do + factory :user do + email 'toto@sgmap.fr' + password 'password' + end +end diff --git a/spec/features/admin/dossier_page/_commentaires_flux_spec.rb b/spec/features/admin/dossier_page/_commentaires_flux_spec.rb index bf810162c..d1693a25b 100644 --- a/spec/features/admin/dossier_page/_commentaires_flux_spec.rb +++ b/spec/features/admin/dossier_page/_commentaires_flux_spec.rb @@ -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 diff --git a/spec/features/admin/dossier_page/show_page_spec.rb b/spec/features/admin/dossier_page/show_page_spec.rb index b4977afba..aea2ed281 100644 --- a/spec/features/admin/dossier_page/show_page_spec.rb +++ b/spec/features/admin/dossier_page/show_page_spec.rb @@ -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 diff --git a/spec/features/carte_page/show_page_spec.rb b/spec/features/carte_page/show_page_spec.rb index 8f402e786..c255ce57e 100644 --- a/spec/features/carte_page/show_page_spec.rb +++ b/spec/features/carte_page/show_page_spec.rb @@ -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" diff --git a/spec/features/demandes_page/show_page_spec.rb b/spec/features/demandes_page/show_page_spec.rb index 37e9ff7b5..8fbfaa29b 100644 --- a/spec/features/demandes_page/show_page_spec.rb +++ b/spec/features/demandes_page/show_page_spec.rb @@ -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" diff --git a/spec/features/description_page/show_page_spec.rb b/spec/features/description_page/show_page_spec.rb index 475c7e8ea..86602e06f 100644 --- a/spec/features/description_page/show_page_spec.rb +++ b/spec/features/description_page/show_page_spec.rb @@ -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 diff --git a/spec/features/dossiers_page/show_page_spec.rb b/spec/features/dossiers_page/show_page_spec.rb index f04e3ef0f..e99e98d07 100644 --- a/spec/features/dossiers_page/show_page_spec.rb +++ b/spec/features/dossiers_page/show_page_spec.rb @@ -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 diff --git a/spec/features/recapitulatif_page/_commentaires_flux_spec.rb b/spec/features/recapitulatif_page/_commentaires_flux_spec.rb index aa360ab31..1a09d40a9 100644 --- a/spec/features/recapitulatif_page/_commentaires_flux_spec.rb +++ b/spec/features/recapitulatif_page/_commentaires_flux_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/features/recapitulatif_page/show_page_spec.rb b/spec/features/recapitulatif_page/show_page_spec.rb index 3d11562ca..a40de8507 100644 --- a/spec/features/recapitulatif_page/show_page_spec.rb +++ b/spec/features/recapitulatif_page/show_page_spec.rb @@ -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') diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb new file mode 100644 index 000000000..4f936b9c9 --- /dev/null +++ b/spec/models/dossier_spec.rb @@ -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 \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0f0213125..97299321a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 diff --git a/spec/support/controller_helpers.rb b/spec/support/controller_helpers.rb index 44280a4a9..108d8f007 100644 --- a/spec/support/controller_helpers.rb +++ b/spec/support/controller_helpers.rb @@ -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 diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb new file mode 100644 index 000000000..a27401802 --- /dev/null +++ b/spec/support/database_cleaner.rb @@ -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 diff --git a/spec/support/feature_helpers.rb b/spec/support/feature_helpers.rb index 2d923316b..52c7388ad 100644 --- a/spec/support/feature_helpers.rb +++ b/spec/support/feature_helpers.rb @@ -1,6 +1,6 @@ module FeatureHelpers def login_admin - user = User.first + user = create :user login_as user, scope: :user user end diff --git a/spec/views/dossiers/show.html.haml_spec.rb b/spec/views/dossiers/show.html.haml_spec.rb new file mode 100644 index 000000000..4884499ad --- /dev/null +++ b/spec/views/dossiers/show.html.haml_spec.rb @@ -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 \ No newline at end of file