2015-10-09 17:33:33 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe UsersController, type: :controller do
|
|
|
|
|
2015-11-02 16:36:52 +01:00
|
|
|
describe '#current_user_dossier' do
|
2015-10-09 17:33:33 +02:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:dossier) { create(:dossier, user: user)}
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
end
|
|
|
|
|
2015-11-04 17:27:01 +01:00
|
|
|
context 'when no dossier_id is filled' do
|
2015-10-09 17:33:33 +02:00
|
|
|
it { expect{ subject.current_user_dossier }.to raise_error }
|
|
|
|
end
|
|
|
|
|
2015-11-02 16:36:52 +01:00
|
|
|
context 'when dossier_id is given as a param' do
|
|
|
|
context 'when dossier id is valid' do
|
2015-10-09 17:33:33 +02:00
|
|
|
it 'returns current user dossier' do
|
|
|
|
expect(subject.current_user_dossier dossier.id).to eq(dossier)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-02 16:36:52 +01:00
|
|
|
context 'when dossier id is incorrect' do
|
2015-10-09 17:33:33 +02:00
|
|
|
it { expect{ subject.current_user_dossier 1 }.to raise_error }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-02 16:36:52 +01:00
|
|
|
context 'when no params[] is given' do
|
|
|
|
context 'when dossier id is valid' do
|
2015-10-09 17:33:33 +02:00
|
|
|
before do
|
|
|
|
subject.params[:dossier_id] = dossier.id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns current user dossier' do
|
|
|
|
expect(subject.current_user_dossier).to eq(dossier)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-02 16:36:52 +01:00
|
|
|
context 'when dossier id is incorrect' do
|
2015-10-09 17:33:33 +02:00
|
|
|
it { expect{ subject.current_user_dossier }.to raise_error }
|
|
|
|
end
|
|
|
|
|
2015-11-02 16:36:52 +01:00
|
|
|
context 'when dossier_id is given as a param' do
|
|
|
|
before do
|
|
|
|
subject.params[:dossier_id] = 1
|
|
|
|
end
|
2015-10-09 17:33:33 +02:00
|
|
|
|
2015-11-02 16:36:52 +01:00
|
|
|
it 'returns dossier with the id on params past' do
|
|
|
|
expect(subject.current_user_dossier dossier.id).to eq(dossier)
|
|
|
|
end
|
2015-10-09 17:33:33 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|