# Attachment\_fu functional testing

**URL:** <https://www.ruby-forum.com/t/attachment-fu-functional-testing/91997>\
**Category:** Rails\
**Created:** [April 14, 2007, 4:59am UTC](https://www.ruby-forum.com/t/attachment-fu-functional-testing/91997 "2007-04-14T04:59:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![helzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e19b73/32.png) [@helzer](https://www.ruby-forum.com/u/helzer)\
**Post date:** [April 14, 2007, 4:59am UTC](https://www.ruby-forum.com/t/attachment-fu-functional-testing/91997/1 "2007-04-14T04:59:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![helzer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/e19b73/32.png) [@helzer](https://www.ruby-forum.com/u/helzer)\
**Post date:** [April 14, 2007, 4:55pm UTC](https://www.ruby-forum.com/t/attachment-fu-functional-testing/91997/2 "2007-04-14T16:55:34Z")

</div>

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
