I'm trying to use the attach_file webrat function in a cucumber step.
For some reason, when the upload getting to the controller, instead of
the attachment being a TestUploadedFile instance, it looks like an
inspect string:
And I fill in "Add a Comment" with "my vacation pix"
# features/step_definitions/webrat_steps.rb:32
And I add the reply attachment "vacation.txt"
# features/step_definitions/notes_steps.rb:26
And I press "Add Comment"
# features/step_definitions/webrat_steps.rb:20
undefined method `each' for #<String:0x00000107785980> (NoMethodError)
The relevant step is:
When /^I add the reply attachment "([^\"]*)"$/ do |path|
attach_file("attachment[]", File.join(RAILS_ROOT,
'features/upload_files', path))
end
I had the controller print out what it was getting for the attachments
parameter
attachments is "[#<ActionController::TestUploadedFile:0x000001077a5880
@content_type=#<Mime::Type:0x00000100ec6c80 @synonyms=[],
@symbol=:text, @string="text/plain">,
@original_filename="vacation.txt",
@tempfile=#<File:/var/folders/DV/DVi3x+y8HiSSTCLkEYVBpE+++TI/-Tmp-/vacation.txt20091120-58509-2pjvnh-0>>]"
The controller code actually works so this appears to be some problem
with the cucumber/webrat/rails integration test stack.
Any ideas?
--
Rick DeNatale
Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale