refactor(attachment): attachments controller to use turbo

This commit is contained in:
Paul Chavard 2022-05-06 12:25:58 +02:00
parent 32bd1b6d9f
commit e9b02642c5
6 changed files with 20 additions and 23 deletions

View file

@ -8,24 +8,24 @@ describe AttachmentsController, type: :controller do
describe '#show' do
render_views
let(:format) { :js }
let(:format) { :turbo_stream }
subject do
request.headers['HTTP_REFERER'] = dossier_url(dossier)
get :show, params: { id: attachment.id, signed_id: signed_id }, format: format, xhr: (format == :js)
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 }
context 'when requesting turbo_stream' do
let(:format) { :turbo_stream }
it { is_expected.to have_http_status(200) }
it 'renders JS that replaces the attachment HTML' do
it 'renders turbo_stream that replaces the attachment HTML' do
subject
expect(response.body).to have_text(".attachment-link[data-attachment-id=\"#{attachment.id}\"]")
expect(response.body).to include(ActionView::RecordIdentifier.dom_id(attachment, :show))
end
end
@ -51,7 +51,7 @@ describe AttachmentsController, type: :controller do
let(:signed_id) { attachment.blob.signed_id }
subject do
delete :destroy, params: { id: attachment.id, signed_id: signed_id }, format: :js
delete :destroy, params: { id: attachment.id, signed_id: signed_id }, format: :turbo_stream
end
context "when authenticated" do