demarches-normaliennes/spec/controllers/users/description_controller_spec.rb
2017-03-06 14:29:01 +01:00

65 lines
2.3 KiB
Ruby

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' }
let(:archived) { false }
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_datetime, cerfa_flag: true, archived: archived) }
let(:dossier) { create(:dossier, procedure: procedure, user: owner_user, state: 'initiated') }
let(:dossier_id) { dossier.id }
let(:bad_dossier_id) { Dossier.count + 10000 }
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
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
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"
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
#
# context 'POST #update' do
# let(:user) { owner_user }
#
# subject { post :update, params: { dossier_id: dossier.id } }
#
# before do
# subject
# end
#
# it { expect(response.status).to eq(302) }
#
# context 'when procedure is archived' do
# let(:archived) { true }
#
# it { expect(response.status).to eq(403) }
# end
#
# end
end