diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index ceb7d191f..7e00a99e5 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -48,6 +48,7 @@ class DocumentsController < ApplicationController def destroy_upload @document = Document.new(cached_attachment: params[:path]) @document.set_attachment_from_cached_attachment + @document.cached_attachment = nil @document.documentable = @documentable if @document.attachment.destroy diff --git a/spec/shared/features/documentable.rb b/spec/shared/features/documentable.rb index b8b5ebe1c..80da9499b 100644 --- a/spec/shared/features/documentable.rb +++ b/spec/shared/features/documentable.rb @@ -251,6 +251,41 @@ shared_examples "documentable" do |documentable_factory_name, documentable_path, expect(find("input[name='document[cached_attachment]']", visible: false).value).to include("empty.pdf") end + scenario "Should not show 'Choose document' button after valid upload", :js do + login_as documentable.author + visit new_document_path(documentable_type: documentable.class.name, + documentable_id: documentable.id) + + attach_file :document_attachment, "spec/fixtures/files/empty.pdf", make_visible: true + sleep 1 + + expect(page).not_to have_content "Choose document" + end + + scenario "Should show 'Remove document' button after valid upload", :js do + login_as documentable.author + visit new_document_path(documentable_type: documentable.class.name, + documentable_id: documentable.id) + + attach_file :document_attachment, "spec/fixtures/files/empty.pdf", make_visible: true + sleep 1 + + expect(page).to have_link("Remove document") + end + + scenario "Should show 'Choose document' button after remove valid upload", :js do + login_as documentable.author + visit new_document_path(documentable_type: documentable.class.name, + documentable_id: documentable.id) + + attach_file :document_attachment, "spec/fixtures/files/empty.pdf", make_visible: true + sleep 1 + click_link "Remove document" + sleep 1 + + expect(page).to have_content "Choose document" + end + scenario "Should not update document cached_attachment field after unvalid file upload", :js do login_as documentable.author visit new_document_path(documentable_type: documentable.class.name,