Add some tests

This commit is contained in:
Mathieu Magnin 2017-02-15 17:09:25 +01:00
parent 1d0a236813
commit 6979f6b5f6
3 changed files with 33 additions and 9 deletions

View file

@ -195,7 +195,7 @@ class Admin::ProceduresController < AdminController
if @procedure.try(:locked?)
params.require(:procedure).permit(:libelle, :description, :organisation, :direction, :lien_site_web, :lien_notice, :euro_flag, :logo)
else
params.require(:procedure).permit(:libelle, :description, :organisation, :direction, :lien_demarche, :lien_site_web, :lien_notice, :euro_flag, :logo, :cerfa_flag, :for_individual, :individual_with_siret, module_api_carto_attributes: [:id, :use_api_carto, :quartiers_prioritaires, :cadastre]).merge(administrateur_id: current_administrateur.id)
params.require(:procedure).permit(:libelle, :description, :organisation, :direction, :lien_site_web, :lien_notice, :euro_flag, :logo, :lien_demarche, :cerfa_flag, :for_individual, :individual_with_siret, module_api_carto_attributes: [:id, :use_api_carto, :quartiers_prioritaires, :cadastre]).merge(administrateur_id: current_administrateur.id)
end
end

View file

@ -1,4 +1,5 @@
require 'spec_helper'
require 'spec_helper'
describe Admin::ProceduresController, type: :controller do
let(:admin) { create(:administrateur) }
@ -13,6 +14,7 @@ describe Admin::ProceduresController, type: :controller do
let(:use_api_carto) { '0' }
let(:quartiers_prioritaires) { '0' }
let(:cadastre) { '0' }
let(:cerfa_flag) { true }
let(:procedure_params) {
{
@ -21,6 +23,7 @@ describe Admin::ProceduresController, type: :controller do
organisation: organisation,
direction: direction,
lien_demarche: lien_demarche,
cerfa_flag: cerfa_flag,
module_api_carto_attributes: {
use_api_carto: use_api_carto,
quartiers_prioritaires: quartiers_prioritaires,
@ -105,24 +108,24 @@ describe Admin::ProceduresController, type: :controller do
sign_out admin
end
it { expect(subject).to redirect_to new_user_session_path }
it { is_expected.to redirect_to new_user_session_path }
end
context 'when user is connected' do
context 'when procedure exist' do
let(:procedure_id) { procedure.id }
it { expect(subject).to have_http_status(:success) }
it { is_expected.to have_http_status(:success) }
end
context 'when procedure is published' do
let(:published) { true }
it { is_expected.to redirect_to admin_procedure_path id: procedure_id }
it { is_expected.to have_http_status(:success) }
end
context "when procedure doesn't exist" do
let(:procedure_id) { bad_procedure_id }
it { expect(subject).to have_http_status(404) }
it { is_expected.to have_http_status(404) }
end
end
end
@ -164,7 +167,7 @@ describe Admin::ProceduresController, type: :controller do
it { expect(subject.quartiers_prioritaires).to be_truthy }
end
it { expect(subject).to redirect_to(admin_procedure_types_de_champ_path(procedure_id: Procedure.last.id)) }
it { is_expected.to redirect_to(admin_procedure_types_de_champ_path(procedure_id: Procedure.last.id)) }
it { expect(flash[:notice]).to be_present }
end
@ -204,7 +207,7 @@ describe Admin::ProceduresController, type: :controller do
subject { put :update, params: {id: procedure.id} }
it { expect(subject).to redirect_to new_user_session_path }
it { is_expected.to redirect_to new_user_session_path }
end
context 'when administrateur is connected' do
@ -213,7 +216,7 @@ describe Admin::ProceduresController, type: :controller do
procedure.reload
end
context 'when all attributs are informated' do
context 'when all attributs are present' do
let(:libelle) { 'Blable' }
let(:description) { 'blabla' }
let(:organisation) { 'plop' }
@ -240,7 +243,7 @@ describe Admin::ProceduresController, type: :controller do
it { expect(subject.cadastre).to be_truthy }
end
it { expect(subject).to redirect_to(edit_admin_procedure_path id: procedure.id) }
it { is_expected.to redirect_to(edit_admin_procedure_path id: procedure.id) }
it { expect(flash[:notice]).to be_present }
end
@ -260,6 +263,26 @@ describe Admin::ProceduresController, type: :controller do
it { expect(subject.cadastre).to be_falsey }
end
end
context 'when procedure is published' do
let!(:procedure) { create(:procedure, :with_type_de_champ, :with_two_type_de_piece_justificative, :published, administrateur: admin) }
describe 'only some properties can be updated' do
subject { procedure }
it { expect(subject.libelle).to eq procedure_params[:libelle] }
it { expect(subject.description).to eq procedure_params[:description] }
it { expect(subject.organisation).to eq procedure_params[:organisation] }
it { expect(subject.direction).to eq procedure_params[:direction] }
it { expect(subject.cerfa_flag).not_to eq procedure_params[:cerfa_flag] }
it { expect(subject.lien_demarche).not_to eq procedure_params[:lien_demarche] }
it { expect(subject.for_individual).not_to eq procedure_params[:for_individual] }
it { expect(subject.individual_with_siret).not_to eq procedure_params[:individual_with_siret] }
it { expect(subject.use_api_carto).not_to eq procedure_params[:module_api_carto_attributes][:use_api_carto] }
end
end
end
end

View file

@ -7,6 +7,7 @@ FactoryGirl.define do
organisation "Orga SGMAP"
direction "direction SGMAP"
published false
cerfa_flag false
administrateur { create(:administrateur) }
mail_templates { [create(:mail_template, :dossier_received)]}