<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I just got finished working with attachment_fu, and ended up modeling a plugin for my company since attachment_fu was slight over kill for our needs.<div><br class="webkit-block-placeholder"></div><div>Have you opened up attachment_fu's source? upload_data is just a method (so is upload_data=) which is inserted into a model that calls has_attachment. I have yet to spec my plugin so I'm interested to see what your results are.</div><div><br class="webkit-block-placeholder"></div><div>Thanks,<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:46 PM, Matt Lins wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"> <font size="-1"><font face="Arial">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.<br> <br> The previous code is from the attachment_fu plugin(no, I didn't modify it). This property 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:<br> <br> class Picture < ActiveRecord::Base<br> <br> has_and_belongs_to_many :products<br> <br> has_attachment :content_type => 'image/jpeg',<br> :storage => :file_system,<br> :max_size => 3.megabytes,<br> :resize_to => '400x400>',<br> :thumbnails => {:medium => '200x200>', :small => '100x100>'},<br> :path_prefix => 'images/products'<br> <br> validates_as_attachment<br> <br> validates_uniqueness_of :filename<br> validates_presence_of :filename <br> <br> def before_update<br> self.thumbnails.each do |t|<br> t.filename= thumbnail_name_for(t.thumbnail)<br> t.save<br> end<br> end<br> <br> def full_filename(thumbnail = nil)<br> file_system_path = (thumbnail ? thumbnail_class : self).attachment_options[:path_prefix].to_s<br> File.join(RAILS_ROOT, 'public/external', file_system_path, thumbnail_name_for(thumbnail) + '.jpg')<br> end<br> <br> def public_image<br> self.public_filename<br> end<br> <br> end<br> </font></font><br> aslak hellesoy wrote: <blockquote cite="mid:8d961d900708220941ice5f7a5k4de1bb01a0f2ee1f@mail.gmail.com" type="cite"> <pre wrap="">On 8/22/07, Matt Lins <a class="moz-txt-link-rfc2396E" href="mailto:mlins@webinforem.com"><mlins@webinforem.com></a> wrote:
</pre> <blockquote type="cite"> <pre wrap=""> 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.
#
# <% form_for :attachment, :html => { :multipart => true } do |f|
-%>
# <p><%= f.file_field :uploaded_data %></p>
# <p><%= submit_tag :Save %>
# <% end -%>
#
# @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
</pre> </blockquote> <pre wrap=""><!---->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
</pre> <blockquote type="cite"> <pre wrap=""> 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>
</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><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></div></div></body></html>