Hi all,
I’m trying to run a Story Runner integration test that uploads a file
through Attachment-fu.
I’ve tried various ways of specifying the file data, from custom mocks:
class MockFile < Struct.new
(:original_filename, :read, :content_type); end
fdata = MockFile.new “test_upload.txt”, “Test Upload”, “text/plain”
to ‘proper’ railsy stubs like:
fdata = ActionController::TestUploadedFile.new("…/spec/fixtures/
test_upload.txt", “text/plain”)
The actual params are specified as:
{ :uploaded_data => fdata,
:filename => file_reference_name(identifier)
}
Now, this is being passed successfully into attachment-fu, where it
is processed. Well, almost successfully. Somehow, along the way, the
TestUploadedFile, struct, mock, whatever you want, gets turned into a
String. Then it blows up when attachment-fu tries to retrieve the
content type:
#<NoMethodError: undefined method `content_type’ for
“#ActionController::TestUploadedFile:0x34349ac”:String>
Somehow, I can’t seem to pass anything but a String down into the
controller. Even in the action, the TestUploadedFile is already
transmogrified into a String (which, of course, has no content_type
property). I put a logging statement in the ActionController too, and
it seems that the entire params hash is turned into a string
somewhere in there - which would explain why the object has literally
no chance of going through.
I’m a bit stumped by this. I guess it makes sense that params are
turned into strings - but then what sort of string should i specify
for a file upload?
Thanks for any help.
Daniel