Attachment_fu and story runner, any updates

I’m trying to write a story for a Rails app which involves using the
attachment_fu plugin to upload images.

After blunting my pick on this for a while, google found me this:
http://www.ruby-forum.com/topic/134743#600831

So it seems that there’s a hole in Rails integration testing and
multipart form posting. David offered to incorporate a patch to story
runner at the end of the reference thread in ruby-talk, although just
which patch confuses me, it would seem to be one from
http://dev.rubyonrails.org/ticket/4635

So what is the current status here?


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

On Jan 21, 2008 2:12 PM, Rick DeNatale [email protected] wrote:

http://dev.rubyonrails.org/ticket/4635

So what is the current status here?

“There are no tests for the rails patch. If you’re willing to add
rspec examples and contribute it to the rspec tracker, I’ll add it to
rspec as a temporary fix until that ticket is resolved.”

I think that’s where we left it.

Probably belongs in a separate plugin though - not as part of rspec. Any
takers?

On Jan 21, 2008 11:36 PM, David C. [email protected] wrote:

which patch confuses me, it would seem to be one from
Probably belongs in a separate plugin though - not as part of rspec. Any takers?
After looking at the patches a bit, I decided to dig in and write a
new rails patch which will work slightly differently.

The current patch explicitly requires the use of a multi_part method.
The problem is that this doesn’t work if you want to use, say
post_via_redirect, and it also doesn’t handle multipart put requests,
which just might be useful in our RESTful world these days.

So instead I’m now debugging a new patch which adds the ability for an
integration controller to detect parameter values which are instances
of TestUploadedFile and automatically generate a multipart request.

In the meantime, I seem to be running into the issue discussed here:
http://www.ruby-forum.com/topic/130975#585329

I find I need to have this:
Test::Unit::TestCase.fixture_path = RAILS_ROOT + ‘/spec/fixtures/’

I thought that this was fixed?

$ svn propget piston:root vendor/plugins/rspec
http://rspec.rubyforge.org/svn/tags/CURRENT/rspec

$ svn propget piston:root vendor/plugins/rspec_on_rails
http://rspec.rubyforge.org/svn/tags/CURRENT/rspec_on_rails

$ svn propget piston:remote-revision vendor/plugins/rspec
3225
$ svn propget piston:remote-revision vendor/plugins/rspec_on_rails/
3223


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

I’ve just submitted a rails patch
http://dev.rubyonrails.org/ticket/11091

This patches actionpack/lib/action_controller/integration.rb so that
post and put requests automatically get turned into multipart form
submission requests if they have a parameter or parameters which are
instances of TestUploadedFile.

This allows file uploading to be tested in integration controllers or
RSpec stories.

Please have a look if interested and verify the patch, looking for +1s
on the Rails Trac

Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

Rick DeNatale wrote:

Please have a look if interested and verify the patch, looking for +1s
on the Rails Trac

Thanks Rick!
I’ll check it out when I get a chance. BTW, would you mind posting some
example code of how you are using the story runner in testing a
multi-part form?

Thanks,
Ben

On 2/12/08, Ben M. [email protected] wrote:

I’ll check it out when I get a chance. BTW, would you mind posting some
example code of how you are using the story runner in testing a
multi-part form?

require File.expand_path(File.dirname(FILE) + “/helper.rb”)

Test::Unit::TestCase.fixture_path = RAILS_ROOT + ‘/spec/fixtures/’

def add_the_rebelz
@image_filename = “therebelz.jpg”
upload_data = fixture_file_upload(@image_filename, “image/jpg”)
post_via_redirect(“/artists”, {:artist => {:name => “The Rebelz”},
:image => {:uploaded_data => upload_data}})
@artist = Artist.find_by_name(“The Rebelz”)
end

Story “Sign up an Artist”, %{
As an administrator
I want to add the Artist to the system
So that the Artist can be accessed
}, :type => RailsStory do
Scenario “New Artist” do
Given “The Artist is not in the system” do
pm = Artist.find_by_name(“The Rebelz”)
pm.destroy if pm
end
When “I add the Artist” do
add_the_rebelz
end
Then “The Artist page should show the Artist’s name” do
response.should have_text(/The Rebelz/)
end
And “The page should show the artist’s picture or logo” do
response.should have_tag(“span.artist_logo”) do
with_tag(“img[src*=?]”, @image_filename)
end
end


Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/