I am down to the last test for my controllers. This one baffles me:
In my DocumentController class I have the following method for
downloading documents:
class DocumentsController < ApplicationController
before_filter :login_required
before_filter :current_practice_and_folder_selection_required
...
def download_document
@document = Document.find(params[:id])
send_file(@document.doc.path(:original))
end
end
Corresponding Shoulda test is shown below:
require 'test_helper'
class DocumentsControllerTest < ActionController::TestCase
context 'on GET to :download a document record' do
setup do
@practice_user = Factory(:practice_user)
@document = Factory(:document)
get :download_document, {:id => @
document.id},
{:user_id => @
practice_user.id,
:practice_id => @document.folder.practice_id,
:folder_id => @document.folder_id}
end
should_assign_to :document
should_respond_with :success
end
end
This, however, does not work, and responds with the following error
messages:
1) Error:
on GET to :download a document record should assign @document
(DocumentsControllerTest):
ActionController::MissingFile: Cannot read file /home/bruparel/work/
ssfilemgr/public/system/docs/1/original/../../public/images/bl.png
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/
action_controller/streaming.rb:78:in `send_file'
/home/bruparel/work/ssfilemgr/app/controllers/documents_controller.rb:
53:in `download_document'
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/
action_controller/base.rb:1322:in `send'
2) Error:
on GET to :download a document record should respond with success
(DocumentsControllerTest):
ActionController::MissingFile: Cannot read file /home/bruparel/work/
ssfilemgr/public/system/docs/2/original/../../public/images/bl.png
/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/
action_controller/streaming.rb:78:in `send_file'
The application works fine. The test does not, it errors at the
following line of code of the method download_document:
def download_document
@document = Document.find(params[:id])
send_file(@document.doc.path(:original)) <---- here
end
I am using PaperClip for document upload/download.
Bharat