attachment_fu functional testing

Hi,

I'm trying to write a functional test to a model that has
attachment_fu:

{{{
  fdata = fixture_file_upload(fname,'application/octet-stream')
  post url_for(:controller=>:support_files, :action=>:create),
    :session=>session, :project_id=>project_id, :support_file=>{'uploaded_data'=>fdata}, :format=>'xml'
}}}

The log file shows:
{{{
NoMethodError (undefined method `content_type' for
"#<ActionController::TestUploadedFile:0x4376938>":String):
    /vendor/plugins/attachment_fu/lib/technoweenie/attachment_fu.rb:
255:in `uploaded_data='
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/base.rb:1672:in `send'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/base.rb:1672:in `attributes='
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/base.rb:1671:in `each'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/base.rb:1671:in `attributes='
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/base.rb:1505:in `initialize_without_callbacks'
    c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/
active_record/callbacks.rb:225:in `initialize'
}}}

The strange this is, when it runs with file updates from a browser,
this all works just fine.

Any ideas?

Thanks,
Helzer

Your fdata needs to be an object which acts like an uploaded file.

IE:
  MockFile = Struct.new( :original_filename, :read, :content_type )
  fdata =
MockFile.new :original_filename=>"filename", :read=>"data", :content_type=>"text/
html"

If you use Mocha or another mocking library you can do:

  fdata = mock()
  fdata.expects( :original_filename ).returns( "somefilename" )
  fdata.expects( :read ).returns( "file contents" )
  fdata.expects( :content_type ).returns( "text/html" )

HTH,

Zach