Remove document cached_attachment value after destroy_upload action.

This commit is contained in:
Senén Rodero Rodríguez
2017-09-11 14:39:58 +02:00
parent 90a5053ca8
commit 4c225aac62
2 changed files with 36 additions and 0 deletions

View File

@@ -48,6 +48,7 @@ class DocumentsController < ApplicationController
def destroy_upload def destroy_upload
@document = Document.new(cached_attachment: params[:path]) @document = Document.new(cached_attachment: params[:path])
@document.set_attachment_from_cached_attachment @document.set_attachment_from_cached_attachment
@document.cached_attachment = nil
@document.documentable = @documentable @document.documentable = @documentable
if @document.attachment.destroy if @document.attachment.destroy

View File

@@ -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") expect(find("input[name='document[cached_attachment]']", visible: false).value).to include("empty.pdf")
end 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 scenario "Should not update document cached_attachment field after unvalid file upload", :js do
login_as documentable.author login_as documentable.author
visit new_document_path(documentable_type: documentable.class.name, visit new_document_path(documentable_type: documentable.class.name,