[rspec-users] Attachment-fu + Story Runner

David Chelimsky dchelimsky at gmail.com
Wed Dec 12 08:54:12 EST 2007


On Dec 12, 2007 5:41 AM, Daniel Tenner <daniel.ruby at tenner.org> wrote:
>
> Ok, a bit more digging and I found this is a Rails issue, that is logged
> here:
>
> http://dev.rubyonrails.org/ticket/4635
>
> File uploads don't work in Rails integration tests either, only in
> functional tests. This is not specific to Attachment-Fu.
>
> There is, however, a monkey patch that you can download to enable a
> multipart_post method which will not mangle the params anymore.
>
> Hope this helps others too!

Daniel - thanks for doing the research on this. 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.

>
> Daniel
>
>
>
> On 12 Dec 2007, at 09:38 12 Dec 2007, voodoorai2000 wrote:
>
>
> Hi,
>
> I had the same problem, couldn't get it to run with Stories thought...
> Had to test file uploads using controller specs, which works but is not as
> clear as a Story.
>
> I'm guessing the bug where it changes the TempFile to a String will be fixed
> soon by the core team, but if someone has a patch it would be awesome!
>
>
> Rai
>
>
>
> Daniel Tenner wrote:
>
> I've now located where this is going wrong, though I am not yet sure
> how to fix it.
>
> In rails' integration.rb, there is a method called 'process'. around
> line 226. It mangles the parameters by calling:
>            data = requestify(parameters)
>
> doing:
>            puts "\n1----===#{parameters.inspect}"
>            puts "\n2----===#{data.inspect}"
>
> a bit later reveals the problem:
> 1----==={:quick_file=>{:filename=>"file-
> TFile.txt", :uploaded_data=>#<ActionController::TestUploadedFile:
> 0x3434150 @content_type="text/plain", @tempfile=#<File:/tmp/
> test_upload29259-0.txt>,
> @original_filename="test_upload.txt">}, :quick_folder=>
> {:id=>1330}, :request_type=>"xml"}
>
> 2----==="quick_file%5Bfilename%5D=file-TFile.txt&quick_file%
> 5Buploaded_data%5D=%23%3CActionController%3A%3ATestUploadedFile%
> 3A0x3434150%3E&quick_folder%5Bid%5D=1330&request_type=xml"
>
> Obviously that's not going to work. I wonder how Test::Unit does it,
> then, though...
>
> Daniel
>
> On 11 Dec 2007, at 14:54 11 Dec 2007, Daniel Tenner wrote:
>
>
> Hi Luis,
>
> I read through that thread, but unfortunately it wasn't much help.
>
> fixture_file_upload also creates an
> ActionController::TestUploadedFile. It's is just a shortcut to
> ActionController::TestUploadedFile.new.
>
> There's no problem with the path - it creates the fixture and loads
> the file, and has the right values inside if I inspect the params
> directly before posting them:
>
> {:filename=>"file-
> TFile.txt", :uploaded_data=>#<ActionController::TestUploadedFile:
> 0x33f83bc @content_type=#<Mime::Type:0x10e2490 @symbol=:text,
> @synonyms=[], @string="text/plain">, @tempfile=#<File:/tmp/
> test_upload29049-0.txt>, @original_filename="test_upload.txt">}
>
> It's only once this is passed into the controller that it all gets
> to_s'ed.
>
> I like the idea of 'providing a real file upload', but I'm not sure
> how to do that in a Story... if anyone has any suggestions or
> pointers, they would be welcome!
>
> Thanks,
>
> Daniel
>
> On 11 Dec 2007, at 14:39 11 Dec 2007, Luis Lavena wrote:
>
>
> On Dec 11, 2007 10:57 AM, Daniel Tenner <daniel.ruby at tenner.org>
> wrote:
>
> I've pasted up the code at:
>
> http://pastie.caboo.se/126925
>
> Since there are quite a few files involved.
>
> Thanks for your time,
>
>
>
> A similar discussion was raised back in november (about
> fixture_file_upload):
>
> http://rubyforge.org/pipermail/rspec-users/2007-November/004378.html
>
> Instead of mocking the FileUpload, why not provide a real one?
>
> After all, the StoryRunner is aimed to fully exercise your code :-D
>
> Also, adjust the path of your TestFileUpload file location,
> instead of
> a relative one (../spec/fixtures) provide one related to RAILS_ROOT,
> which will work no matter where you put your helper or what is your
> current directory (Dir.chdir).
>
> HTH,
>
> --
> Luis Lavena
> Multimedia systems
> -
> A common mistake that people make when trying to design
> something completely foolproof is to underestimate
> the ingenuity of complete fools.
> Douglas Adams
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
>
>
> --
> View this message in context:
> http://www.nabble.com/Attachment-fu-%2B-Story-Runner-tp14272891p14291797.html
> Sent from the rspec-users mailing list archive at Nabble.com.
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list