<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
<font size="-1"><font face="Arial">First off, I'm not trying to spec
attachment_fu, I know it's been tested.<br>
<br>
But, I added some code to that model that I do need to test. Basically,
I need to somehow fulfill the "uploaded_data" property so I can
actually run my tests(otherwise they fail because of validations). The
"uploaded_data" field is what would grab the multipart data from form.
Here it is:<br>
<br>
# This method handles the uploaded file object. If you set the
field name to uploaded_data, you don't need<br>
# any special code in your controller.<br>
#<br>
# <% form_for :attachment, :html => { :multipart =>
true } do |f| -%><br>
# <p><%= f.file_field :uploaded_data %></p><br>
# <p><%= submit_tag :Save %><br>
# <% end -%><br>
#<br>
# @attachment = Attachment.create! params[:attachment]<br>
#<br>
# TODO: Allow it to work with Merb tempfiles too.<br>
def uploaded_data=(file_data)<br>
return nil if file_data.nil? || file_data.size == 0 <br>
self.content_type = file_data.content_type<br>
self.filename = file_data.original_filename if
respond_to?(:filename)<br>
if file_data.is_a?(StringIO)<br>
file_data.rewind<br>
self.temp_data = file_data.read<br>
else<br>
self.temp_path = file_data.path<br>
end<br>
end<br>
<br>
While I was digging I found out that "file_data" is a ruby Tempfile
object. So, I tried to create a dummy file and pass it, but it failed.
I found out in the CGI library, it actually extends the Tempfile object
and adds some methods/properties. It started to get messy, so I thought
I'd ask for advice.<br>
<br>
How can I create a valid attachment_fu model spec(so I can start
tweaking it to test my other validations)?<br>
</font></font>
</body>
</html>