Ryan Sobol wrote:> Mike Clark''s attachment_fu guide is great!
(http://clarkware.com/cgi/
> blosxom/2007/02/24) But what about unit and functional testing? Does
> anyone have some examples they can share? I seem to be getting stuck
> on how to send upload data to my attachment models via a test file.
> Thanks!
>
> -- RYAN
I''ve been having that problem this evening too. I solved it by using
the
fixture_file_upload helper to upload my test data. Put the picture into
test/fixtures and then use something like:
new_photo.uploaded_data =
fixture_file_upload(''test_photo.jpg'',
''image/jpeg''))
assert new_photo.save
I also created a method in test_helper.rb to update my fixtures with an
attachment at the start of every test. I can now call this from setup on
any of my unit tests along with fixtures :photos
def photo_fixtures
photos = Photo.find(:all)
photos.each do |photo|
photo.uploaded_data = fixture_file_upload(photo.filename,
''image/jpeg'')
photo.save!
end
end
I''m new to rails and unit testing so I don''t know if there is
a more
elegant solution for this. Probably.
There are tons of tests written in the test folder of the plugin too but
I couldn''t find any guidance on adapting them for your own use so
decided to start from scratch. As I add more tests I''ll borrow from
there I guess.
Mike
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---