Add missing image model spec. Add shared specs to check image validations at any imageable model

This commit is contained in:
Senén Rodero Rodríguez
2017-09-15 19:02:49 +02:00
parent bb57c1a7f5
commit c6dabedb4a
13 changed files with 208 additions and 16 deletions

View File

@@ -0,0 +1,40 @@
class DirectUploadsController < 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
flash.now[:notice] = t "documents.actions.destroy.notice"
else
flash.now[:alert] = t "documents.actions.destroy.alert"
end
render :destroy
end
def upload
@document = Document.new(document_params.merge(user: current_user))
@document.documentable = @documentable
@document.valid?
if @document.valid?
@document.attachment.save
@document.set_cached_attachment_from_attachment(URI(request.url))
else
@document.attachment.destroy
end
end
private
def set_attachment_container_resource
@container_resource = params[:resource_type]
end
def find_attachment_container_resource
@uplo = params[:documentable_type].constantize.find_or_initialize_by(id: params[:documentable_id])
end
end