attachments: refactor the controller specs
This commit is contained in:
parent
8ceb555941
commit
0077ff4b75
1 changed files with 37 additions and 3 deletions
|
@ -1,5 +1,39 @@
|
|||
describe AttachmentsController, type: :controller do
|
||||
let(:user) { create(:user) }
|
||||
let(:attachment) { champ.piece_justificative_file.attachment }
|
||||
let(:dossier) { create(:dossier, user: user) }
|
||||
let(:champ) { create(:champ_piece_justificative, dossier_id: dossier.id) }
|
||||
let(:signed_id) { attachment.blob.signed_id }
|
||||
|
||||
describe '#show' do
|
||||
render_views
|
||||
|
||||
let(:format) { :js }
|
||||
|
||||
subject do
|
||||
get :show, params: { id: attachment.id, signed_id: signed_id }, format: format
|
||||
end
|
||||
|
||||
context 'when authenticated' do
|
||||
before { sign_in(user) }
|
||||
|
||||
context 'when requesting Javascript' do
|
||||
let(:format) { :js }
|
||||
|
||||
it { is_expected.to have_http_status(200) }
|
||||
|
||||
it 'renders JS that replaces the attachment HTML' do
|
||||
subject
|
||||
expect(response.body).to have_text(".attachment-link[data-attachment-id=\"#{attachment.id}\"]")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'when not authenticated' do
|
||||
it { is_expected.to have_http_status(401) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#destroy' do
|
||||
render_views
|
||||
|
@ -19,7 +53,7 @@ describe AttachmentsController, type: :controller do
|
|||
context 'and dossier is owned by user' do
|
||||
it { is_expected.to have_http_status(200) }
|
||||
|
||||
it do
|
||||
it 'removes the attachment' do
|
||||
subject
|
||||
expect(champ.reload.piece_justificative_file.attached?).to be(false)
|
||||
end
|
||||
|
@ -30,7 +64,7 @@ describe AttachmentsController, type: :controller do
|
|||
|
||||
it { is_expected.to have_http_status(404) }
|
||||
|
||||
it do
|
||||
it 'doesn’t remove the attachment' do
|
||||
subject
|
||||
expect(champ.reload.piece_justificative_file.attached?).to be(true)
|
||||
end
|
||||
|
@ -40,7 +74,7 @@ describe AttachmentsController, type: :controller do
|
|||
context 'when not authenticated' do
|
||||
it { is_expected.to have_http_status(401) }
|
||||
|
||||
it do
|
||||
it 'doesn’t remove the attachment' do
|
||||
subject
|
||||
expect(champ.reload.piece_justificative_file.attached?).to be(true)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue