/ Published in: Ruby
fixture_file_upload is another nifty Rails testing feature. It allows you to create "MIME-encoded content that would normally be uploaded by a browser input field." (Part in quotes straight from Agile Web Development with Rails, v2). Put your files to test in test/fixtures/files. You have to create the 'files' directory; rails doesn't do it for you.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# app/models/house_photo.rb class HousePhoto < ActiveRecord::Base belongs_to :house acts_as_list :scope => :house file_column :image, :root_path => ENV["RAILS_ENV"] == "test" ? File.join(RAILS_ROOT, "public", "test") : File.join(RAILS_ROOT, "public"), :magick => {:geometry => "640x480", :versions => {:thumb => "128x96", :medium => "288x288" }} validates_presence_of :image validates_presence_of :house_id end # test/unit/house_photo_test.rb require File.dirname(__FILE__) + '/../test_helper' class HousePhotoTest < Test::Unit::TestCase fixtures :house_photos, :houses def test_should_get_positioned p = create_photo assert p.position end # Other tests go here... protected def create_photo(options = {}, image_filename = 'files/house1_exterior1.gif') photo = fixture_file_upload(image_filename, 'image/jpg') houses(:house1).house_photos.create({ :image => photo }.merge(options)) end end