<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<font size="-1"><font face="Arial">No, as mentioned in my first post,
the property that needs to be fulfilled is uploaded_data.&nbsp; I posted the
accessor in my first post as well.</font></font><br>
<br>
aslak hellesoy wrote:
<blockquote
 cite="mid:8d961d900708220952p5073a5d0l7b088e71f98f243a@mail.gmail.com"
 type="cite">
  <pre wrap="">On 8/22/07, Matt Lins <a class="moz-txt-link-rfc2396E" href="mailto:mlins@webinforem.com">&lt;mlins@webinforem.com&gt;</a> wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap=""> Sorry, attachment_fu is a plugin for handling binary data. It handles
storing the file in the file system and storing some helpful data in the
database about the file.

 The previous code is from the attachment_fu  plugin(no, I didn't modify
it). This property
    </pre>
  </blockquote>
  <pre wrap=""><!---->
What property? The :filename property?

  </pre>
  <blockquote type="cite">
    <pre wrap="">needs to be satisfied in order for the model to validate.
So I need to get my model to validate in the spec so I can actually test
other parts of my model. Here is my model:

    </pre>
  </blockquote>
  <pre wrap=""><!---->
Can't you just set the filename property directly from your spec
without going through attachment kung fu?

Aslak

  </pre>
  <blockquote type="cite">
    <pre wrap=""> class Picture &lt; ActiveRecord::Base

   has_and_belongs_to_many :products

   has_attachment :content_type =&gt; 'image/jpeg',
                  :storage =&gt; :file_system,
                  :max_size =&gt; 3.megabytes,
                  :resize_to =&gt; '400x400&gt;',
                  :thumbnails =&gt; {:medium =&gt; '200x200&gt;', :small =&gt;
'100x100&gt;'},
                  :path_prefix =&gt; 'images/products'

   validates_as_attachment

   validates_uniqueness_of :filename
   validates_presence_of :filename

   def before_update
     self.thumbnails.each do |t|
       t.filename= thumbnail_name_for(t.thumbnail)
       t.save
     end
   end

   def full_filename(thumbnail = nil)
     file_system_path = (thumbnail ? thumbnail_class :
self).attachment_options[:path_prefix].to_s
     File.join(RAILS_ROOT, 'public/external', file_system_path,
thumbnail_name_for(thumbnail) + '.jpg')
   end

   def public_image
     self.public_filename
   end

 end


 aslak hellesoy wrote:
 On 8/22/07, Matt Lins <a class="moz-txt-link-rfc2396E" href="mailto:mlins@webinforem.com">&lt;mlins@webinforem.com&gt;</a> wrote:


 First off, I'm not trying to spec attachment_fu, I know it's been tested.

 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:

 # This method handles the uploaded file object. If you set the field
name to uploaded_data, you don't need
 # any special code in your controller.
 #
 # &lt;% form_for :attachment, :html =&gt; { :multipart =&gt; true } do |f|
-%&gt;
 # &lt;p&gt;&lt;%= f.file_field :uploaded_data %&gt;&lt;/p&gt;
 # &lt;p&gt;&lt;%= submit_tag :Save %&gt;
 # &lt;% end -%&gt;
 #
 # @attachment = Attachment.create! params[:attachment]
 #
 # TODO: Allow it to work with Merb tempfiles too.
 def uploaded_data=(file_data)
 return nil if file_data.nil? || file_data.size == 0
 self.content_type = file_data.content_type
 self.filename = file_data.original_filename if
respond_to?(:filename)
 if file_data.is_a?(StringIO)
 file_data.rewind
 self.temp_data = file_data.read
 else
 self.temp_path = file_data.path
 end
 end


 I'm not familiar with attachment_fu - is this code from attachment_fu
that you have modified? Or is it your code entirely? Attachment_fu's
entirely? Where does this code come from?

Aslak



 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.

 How can I create a valid attachment_fu model spec(so I can start tweaking
it to test my other validations)?

_______________________________________________
rspec-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a>
<a class="moz-txt-link-freetext" href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a>


 _______________________________________________
rspec-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a>
<a class="moz-txt-link-freetext" href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a>


_______________________________________________
rspec-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a>
<a class="moz-txt-link-freetext" href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a>

    </pre>
  </blockquote>
  <pre wrap=""><!---->_______________________________________________
rspec-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rspec-users@rubyforge.org">rspec-users@rubyforge.org</a>
<a class="moz-txt-link-freetext" href="http://rubyforge.org/mailman/listinfo/rspec-users">http://rubyforge.org/mailman/listinfo/rspec-users</a>
  </pre>
</blockquote>
</body>
</html>