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
“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?
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.
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
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?
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?
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
…