<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">
 <div><blockquote type="cite"><span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Arial; font-size: 10px; ">      # 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</span></blockquote></div><br><div>Durh... stupid me, didn't see this post! :)</div><div><br></div><div><div>:: Justin Reagor</div><div>:: <a href="mailto:justinwr@gmail.com">justinwr@gmail.com</a></div></div><div> <span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div>:: Justin Reagor</div><div>:: <a href="mailto:justinwr@gmail.com">justinwr@gmail.com</a></div><div><br class="khtml-block-placeholder"></div><br class="Apple-interchange-newline"></span> </div><br><div><div>On Aug 22, 2007, at 12:23 PM, Matt Lins wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"> <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>       #   &lt;% form_for :attachment, :html =&gt; { :multipart =&gt; true } do |f| -%&gt;<br>       #     &lt;p&gt;&lt;%= f.file_field :uploaded_data %&gt;&lt;/p&gt;<br>       #     &lt;p&gt;&lt;%= submit_tag :Save %&gt;<br>       #   &lt;% end -%&gt;<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><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">_______________________________________________</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">rspec-users mailing list</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><a href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a></div> </blockquote></div><br></body></html>