demarches-normaliennes/spec/controllers/users/description_controller_spec.rb

53 lines
2.2 KiB
Ruby
Raw Normal View History

2015-08-10 11:05:06 +02:00
require 'spec_helper'
require 'controllers/users/description_controller_shared_example'
describe Users::DescriptionController, type: :controller, vcr: { cassette_name: 'controllers_users_description_controller' } do
let(:owner_user) { create(:user) }
let(:invite_by_user) { create :user, email: 'invite@plop.com' }
2018-05-17 15:43:33 +02:00
let(:archived) { false }
let(:state) { 'en_construction' }
2018-05-17 15:43:33 +02:00
let(:procedure) do
if archived
create(:procedure, :archived, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime, cerfa_flag: true)
else
create(:procedure, :published, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime, cerfa_flag: true)
end
end
let(:dossier) { create(:dossier, procedure: procedure, user: owner_user, state: state) }
2016-02-04 14:08:35 +01:00
2015-08-20 16:25:54 +02:00
let(:dossier_id) { dossier.id }
2016-02-04 14:08:35 +01:00
let(:bad_dossier_id) { Dossier.count + 10000 }
2015-08-10 11:05:06 +02:00
let(:name_piece_justificative) { 'dossierPDF.pdf' }
let(:name_piece_justificative_0) { 'piece_justificative_0.pdf' }
let(:name_piece_justificative_1) { 'piece_justificative_1.pdf' }
let(:cerfa_pdf) { Rack::Test::UploadedFile.new("./spec/support/files/#{name_piece_justificative}", 'application/pdf') }
let(:piece_justificative_0) { Rack::Test::UploadedFile.new("./spec/support/files/#{name_piece_justificative_0}", 'application/pdf') }
let(:piece_justificative_1) { Rack::Test::UploadedFile.new("./spec/support/files/#{name_piece_justificative_1}", 'application/pdf') }
before do
2016-04-15 15:32:15 +02:00
allow(ClamavService).to receive(:safe_file?).and_return(true)
create :invite, dossier: dossier, user: invite_by_user, email: invite_by_user.email, type: 'InviteUser'
sign_in user
2015-08-10 11:05:06 +02:00
end
context 'when sign in user is the owner' do
let(:user) { owner_user }
let(:recapitulatif_path) { users_dossier_recapitulatif_path }
it_should_behave_like "description_controller_spec"
it_should_behave_like "description_controller_spec_POST_piece_justificatives_for_owner"
2015-08-10 11:05:06 +02:00
end
context 'when sign in user is an invite by owner' do
let(:user) { invite_by_user }
let(:recapitulatif_path) { users_dossiers_invite_path(id: dossier_id) }
it_should_behave_like "description_controller_spec"
end
2015-08-10 11:05:06 +02:00
end