style check

This commit is contained in:
Tanguy PATTE 2015-08-20 16:52:36 +02:00
parent 32da0fa891
commit 3a68a0d0ad
8 changed files with 114 additions and 119 deletions

View file

@ -5,39 +5,39 @@ RSpec.describe Admin::DossierController, type: :controller do
let(:dossier_id) { dossier.id }
let(:bad_dossier_id) { Dossier.count + 10 }
describe "GET #show" do
describe 'GET #show' do
context 'l\'utilisateur est connecté' do
before do
sign_in
end
it "returns http success" do
get :show, :dossier_id => dossier_id
it 'returns http success' do
get :show, dossier_id: dossier_id
expect(response).to have_http_status(200)
end
it 'le numéro de dossier n\'existe pas' 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
context 'L\'utilisateur n\'est pas connecté avec un dossier_id correct' do
it {
get :show, :dossier_id => dossier_id
it do
get :show, dossier_id: dossier_id
expect(response).to redirect_to('/')
}
end
end
end
describe "GET #index" do
describe 'GET #index' do
let(:user) { create(:user) }
before do
sign_in
end
it 'le numéro de dossier est correct' do
get :index, :dossier_id => dossier_id
get :index, dossier_id: dossier_id
expect(response).to redirect_to("/admin/dossiers/#{dossier_id}")
end
@ -47,7 +47,7 @@ RSpec.describe Admin::DossierController, type: :controller do
end
it 'le numéro de dossier n\'existe pas' do
get :index, :dossier_id => bad_dossier_id
get :index, dossier_id: bad_dossier_id
expect(response).to redirect_to('/start/error_dossier')
end
end

View file

@ -1,10 +1,8 @@
require 'spec_helper'
RSpec.describe CarteController, type: :controller do
let(:bad_adresse) { 'babouba' }
let(:dossier) { create(:dossier) }
let!(:entreprise) { create(:entreprise, dossier: dossier) }
let!(:etablissement) { create(:etablissement, dossier: dossier) }
@ -13,9 +11,8 @@ RSpec.describe CarteController, type: :controller do
let(:ref_dossier) { 'IATRQPQY' }
let(:adresse) { etablissement.adresse }
describe "GET #show" do
it "returns http success" do
describe 'GET #show' do
it 'returns http success' do
get :show, dossier_id: dossier_id
expect(response).to have_http_status(:success)
end
@ -28,16 +25,16 @@ RSpec.describe CarteController, type: :controller do
describe 'POST #save_ref_api_carto' do
context 'Aucune localisation n\'a jamais été enregistrée' do
it {
post :save_ref_api_carto, :dossier_id => dossier_id, :ref_dossier => ref_dossier, :back_url => ''
it do
post :save_ref_api_carto, dossier_id: dossier_id, ref_dossier: ref_dossier, back_url: ''
expect(response).to redirect_to("/dossiers/#{dossier_id}/description")
}
end
end
context 'En train de modifier la localisation' do
let(:dossier) { create(:dossier, ref_dossier: ref_dossier) }
before do
post :save_ref_api_carto, :dossier_id => dossier_id, :ref_dossier => ref_dossier
post :save_ref_api_carto, dossier_id: dossier_id, ref_dossier: ref_dossier
end
context 'Enregistrement d\'un commentaire informant la modification' do
@ -67,9 +64,9 @@ RSpec.describe CarteController, type: :controller do
let(:etablissement) { create(:etablissement, adresse: bad_adresse) }
let(:dossier) { create(:dossier, etablissement: etablissement) }
before do
stub_request(:get, "http://api-adresse.data.gouv.fr/search?limit=1&q=#{bad_adresse}").
to_return(:status => 200, :body => '{"query": "babouba", "version": "draft", "licence": "ODbL 1.0", "features": [], "type": "FeatureCollection", "attribution": "BAN"}', :headers => {})
get :get_position, :dossier_id => dossier.id
stub_request(:get, "http://api-adresse.data.gouv.fr/search?limit=1&q=#{bad_adresse}")
.to_return(status: 200, body: '{"query": "babouba", "version": "draft", "licence": "ODbL 1.0", "features": [], "type": "FeatureCollection", "attribution": "BAN"}', headers: {})
get :get_position, dossier_id: dossier.id
end
subject { dossier.reload }
@ -82,10 +79,10 @@ RSpec.describe CarteController, type: :controller do
context 'retour d\'un fichier JSON avec 3 attributs' do
before do
stub_request(:get, "http://api-adresse.data.gouv.fr/search?limit=1&q=#{adresse}").
to_return(:status => 200, :body => '{"query": "50 avenue des champs \u00e9lys\u00e9es Paris 75008", "version": "draft", "licence": "ODbL 1.0", "features": [{"geometry": {"coordinates": [2.306888, 48.870374], "type": "Point"}, "type": "Feature", "properties": {"city": "Paris", "label": "50 Avenue des Champs \u00c9lys\u00e9es 75008 Paris", "housenumber": "50", "id": "ADRNIVX_0000000270748251", "postcode": "75008", "name": "50 Avenue des Champs \u00c9lys\u00e9es", "citycode": "75108", "context": "75, \u00cele-de-France", "score": 0.9054545454545454, "type": "housenumber"}}], "type": "FeatureCollection", "attribution": "BAN"}', :headers => {})
stub_request(:get, "http://api-adresse.data.gouv.fr/search?limit=1&q=#{adresse}")
.to_return(status: 200, body: '{"query": "50 avenue des champs \u00e9lys\u00e9es Paris 75008", "version": "draft", "licence": "ODbL 1.0", "features": [{"geometry": {"coordinates": [2.306888, 48.870374], "type": "Point"}, "type": "Feature", "properties": {"city": "Paris", "label": "50 Avenue des Champs \u00c9lys\u00e9es 75008 Paris", "housenumber": "50", "id": "ADRNIVX_0000000270748251", "postcode": "75008", "name": "50 Avenue des Champs \u00c9lys\u00e9es", "citycode": "75108", "context": "75, \u00cele-de-France", "score": 0.9054545454545454, "type": "housenumber"}}], "type": "FeatureCollection", "attribution": "BAN"}', headers: {})
get :get_position, :dossier_id => dossier_id
get :get_position, dossier_id: dossier_id
end
subject { JSON.parse(response.body) }

View file

@ -9,14 +9,14 @@ describe CommentairesController, type: :controller do
describe '#POST create' do
context 'création correct d\'un commentaire' do
it 'depuis la page récapitulatif' do
request.env["HTTP_REFERER"] = "/recapitulatif"
post :create, :dossier_id => dossier_id, :email_commentaire => email_commentaire, :texte_commentaire => texte_commentaire
request.env['HTTP_REFERER'] = '/recapitulatif'
post :create, dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire
expect(response).to redirect_to("/dossiers/#{dossier_id}/recapitulatif")
end
it 'depuis la page admin' do
request.env["HTTP_REFERER"] = "/admin/dossiers"
post :create, :dossier_id => dossier_id, :email_commentaire => email_commentaire, :texte_commentaire => texte_commentaire
request.env['HTTP_REFERER'] = '/admin/dossiers'
post :create, dossier_id: dossier_id, email_commentaire: email_commentaire, texte_commentaire: texte_commentaire
expect(response).to redirect_to("/admin/dossiers/#{dossier_id}")
end
end

View file

@ -4,9 +4,9 @@ RSpec.describe DemandesController, type: :controller do
let(:dossier) { create(:dossier, formulaire_id: '') }
let(:dossier_id) { dossier.id }
describe "GET #show" do
it "returns http success" do
get :show, :dossier_id => dossier_id
describe 'GET #show' do
it 'returns http success' do
get :show, dossier_id: dossier_id
expect(response).to have_http_status(:success)
end
end
@ -14,13 +14,13 @@ RSpec.describe DemandesController, type: :controller do
describe 'POST #upated' do
context 'when dossier is not linked to formulaire' do
it 'redirect to carte controller' do
post :update, :dossier_id => dossier_id, :formulaire => '1'
post :update, dossier_id: dossier_id, formulaire: '1'
expect(response).to redirect_to(controller: :carte, action: :show, dossier_id: dossier_id)
end
end
context 'when dossier is already linked to formaulaire' do
let(:dossier) { create(:dossier) }
subject { post :update, :dossier_id => dossier_id, :formulaire => '1' }
subject { post :update, dossier_id: dossier_id, formulaire: '1' }
it 'raise error' do
expect { subject }.to raise_error("La modification du formulaire n'est pas possible")
end

View file

@ -5,8 +5,8 @@ describe DescriptionController, type: :controller do
let(:dossier_id) { dossier.id }
let(:bad_dossier_id) { Dossier.count + 10 }
describe "GET #show" do
it "returns http success" do
describe 'GET #show' do
it 'returns http success' do
get :show, dossier_id: dossier_id
expect(response).to have_http_status(:success)
end
@ -17,11 +17,11 @@ describe DescriptionController, type: :controller do
end
end
describe "POST #create" do
describe 'POST #create' do
let(:timestamp) { Time.now }
let(:nom_projet) { 'Projet de test' }
let(:description) { 'Description de test Coucou, je suis un saut à la ligne Je suis un double saut la ligne.' }
let(:montant_projet){12000}
let(:montant_projet) { 12_000 }
let(:montant_aide_demande) { 3000 }
let(:date_previsionnelle) { '20/01/2016' }
let(:mail_contact) { 'test@test.com' }
@ -34,18 +34,17 @@ describe DescriptionController, type: :controller do
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') }
context 'Tous les attributs sont bons' do
# TODO separer en deux tests : check donnees et check redirect
it 'Premier enregistrement des données' 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
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
expect(response).to redirect_to("/dossiers/#{dossier_id}/recapitulatif")
end
# TODO changer les valeurs des champs et check in bdd
context 'En train de modifier les données de description du projet' do
before 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, :back_url => 'recapitulatif'
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, back_url: 'recapitulatif'
end
context 'Enregistrement d\'un commentaire informant la modification' do
@ -72,39 +71,39 @@ describe DescriptionController, type: :controller do
context 'Attribut(s) manquant(s)' do
it 'nom_projet manquant' do
post :create, :dossier_id => dossier_id, :nom_projet => '', :description => description, :montant_projet => montant_projet, :montant_aide_demande => montant_aide_demande, :date_previsionnelle => date_previsionnelle, :mail_contact => mail_contact
post :create, dossier_id: dossier_id, nom_projet: '', description: description, montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle, mail_contact: mail_contact
expect(response).to redirect_to("/dossiers/#{dossier_id}/description/error")
end
it 'description manquante' do
post :create, :dossier_id => dossier_id, :nom_projet => nom_projet, :description => '', :montant_projet => montant_projet, :montant_aide_demande => montant_aide_demande, :date_previsionnelle => date_previsionnelle, :mail_contact => mail_contact
post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: '', montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle, mail_contact: mail_contact
expect(response).to redirect_to("/dossiers/#{dossier_id}/description/error")
end
it 'montant_projet manquant' do
post :create, :dossier_id => dossier_id, :nom_projet => nom_projet, :description => description, :montant_projet => '', :montant_aide_demande => montant_aide_demande, :date_previsionnelle => date_previsionnelle, :mail_contact => mail_contact
post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: '', montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle, mail_contact: mail_contact
expect(response).to redirect_to("/dossiers/#{dossier_id}/description/error")
end
it 'montant_aide_demande manquant' do
post :create, :dossier_id => dossier_id, :nom_projet => nom_projet, :description => description, :montant_projet => montant_projet, :montant_aide_demande => '', :date_previsionnelle => date_previsionnelle, :mail_contact => mail_contact
post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: montant_projet, montant_aide_demande: '', date_previsionnelle: date_previsionnelle, mail_contact: mail_contact
expect(response).to redirect_to("/dossiers/#{dossier_id}/description/error")
end
it 'date_previsionnelle manquante' 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 => '', :mail_contact => mail_contact
post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: '', mail_contact: mail_contact
expect(response).to redirect_to("/dossiers/#{dossier_id}/description/error")
end
it 'mail_contact manquant' 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 => ''
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: ''
expect(response).to redirect_to("/dossiers/#{dossier_id}/description/error")
end
end
context 'Mauvais format(s)' do
it 'mail_contact n\'est un format d\'email' 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 => 'test.com'
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: 'test.com'
expect(response).to redirect_to("/dossiers/#{dossier_id}/description/error")
end
end
@ -112,14 +111,14 @@ describe DescriptionController, type: :controller do
context 'Sauvegarde du CERFA PDF' do
before do
dossier.build_default_pieces_jointes
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
dossier.reload
end
@ -136,7 +135,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
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(type_piece_jointe_id: '0', dossier_id: dossier_id)
expect(cerfa.many?).to eq(false)
end
@ -150,15 +149,15 @@ describe DescriptionController, type: :controller do
context 'Sauvegarde des pièces jointes' do
before do
dossier.build_default_pieces_jointes
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
dossier.reload
end

View file

@ -3,34 +3,34 @@ require 'spec_helper'
RSpec.describe DossiersController, type: :controller do
let(:dossier) { create(:dossier, :with_entreprise) }
let(:dossier_id) { dossier.id }
let(:siret_not_found) { 999999999999 }
let(:siret_not_found) { 999_999_999_999 }
let(:siren) { dossier.siren }
let(:siret) { dossier.siret }
let(:bad_siret) { 1 }
describe 'GET #show' do
it "returns http success with dossier_id valid" do
get :show, :id => dossier_id
it 'returns http success with dossier_id valid' do
get :show, id: dossier_id
expect(response).to have_http_status(:success)
end
it 'redirection vers start si mauvais dossier ID' do
get :show, :id => siret_not_found
get :show, id: siret_not_found
expect(response).to redirect_to('/start/error_dossier')
end
end
describe 'POST #create' do
before do
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret_not_found}?token=#{SIADETOKEN}").
to_return(:status => 404, :body => 'fake body')
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret_not_found}?token=#{SIADETOKEN}")
.to_return(status: 404, body: 'fake body')
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}").
to_return(:status => 200, :body => File.read('spec/support/files/etablissement.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/etablissements/#{siret}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/etablissement.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}").
to_return(:status => 200, :body => File.read('spec/support/files/entreprise.json'))
stub_request(:get, "https://api-dev.apientreprise.fr/api/v1/entreprises/#{siren}?token=#{SIADETOKEN}")
.to_return(status: 200, body: File.read('spec/support/files/entreprise.json'))
end
describe 'professionnel fills form' do
@ -79,7 +79,7 @@ RSpec.describe DossiersController, type: :controller do
end
context 'when pro_dossier_id is not empty' do
let!(:dossier) { create(:dossier, :with_entreprise) }
subject { post :create, siret: dossier.siret ,pro_dossier_id: 99999999999}
subject { post :create, siret: dossier.siret, pro_dossier_id: 99_999_999_999 }
context 'when dossier not found' do
it 'redirects to start with error_dossier' do
@ -92,7 +92,6 @@ RSpec.describe DossiersController, type: :controller do
it 'redirects to controller recapitulatif' do
expect(subject).to redirect_to(controller: :recapitulatif, action: :show, dossier_id: dossier.id)
end
end
context 'when siret does not match' do
subject { post :create, siret: '11111111111111', pro_dossier_id: dossier.id }
@ -107,7 +106,7 @@ RSpec.describe DossiersController, type: :controller do
describe 'PUT #update' do
before do
put :update, :id => dossier_id, dossier: { autorisation_donnees: autorisation_donnees }
put :update, id: dossier_id, dossier: { autorisation_donnees: autorisation_donnees }
end
context 'when Checkbox is checked' do
let(:autorisation_donnees) { '1' }

View file

@ -5,8 +5,8 @@ RSpec.describe RecapitulatifController, type: :controller do
let(:bad_dossier_id) { Dossier.count + 10 }
describe "GET #show" do
it "returns http success" do
describe 'GET #show' do
it 'returns http success' do
get :show, dossier_id: dossier.id
expect(response).to have_http_status(:success)
end

View file

@ -1,19 +1,19 @@
require 'spec_helper'
RSpec.describe StartController, type: :controller do
describe "GET #index" do
it "returns http success" do
describe 'GET #index' do
it 'returns http success' do
get :index
expect(response).to have_http_status(:success)
end
end
describe "GET #index with bad SIRET" do
describe 'GET #index with bad SIRET' do
before do
get :error_siret
end
it "returns http success and flash alert is present" do
it 'returns http success and flash alert is present' do
expect(response).to have_http_status(:success)
end
it 'la flash alert est présente' do
@ -24,12 +24,12 @@ RSpec.describe StartController, type: :controller do
end
end
describe "GET #index with bad LOGIN" do
describe 'GET #index with bad LOGIN' do
before do
get :error_login
end
it "returns http success and flash alert is present" do
it 'returns http success and flash alert is present' do
expect(response).to have_http_status(:success)
end
it 'la flash alert est présente' do
@ -40,12 +40,12 @@ RSpec.describe StartController, type: :controller do
end
end
describe "GET #index with bad DOSSIER" do
describe 'GET #index with bad DOSSIER' do
before do
get :error_dossier
end
it "returns http success and flash alert is present" do
it 'returns http success and flash alert is present' do
expect(response).to have_http_status(:success)
end
it 'la flash alert est présente' do