Attachment-fu + Story Runner

View: New views
15 Messages — Rating Filter:   Alert me  

Attachment-fu + Story Runner

by Daniel Tenner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,

I'm trying to run a Story Runner integration test that uploads a file  
through Attachment-fu.

I've tried various ways of specifying the file data, from custom mocks:
class MockFile < Struct.new
(:original_filename, :read, :content_type); end
fdata = MockFile.new  "test_upload.txt", "Test Upload", "text/plain"

to 'proper' railsy stubs like:

fdata = ActionController::TestUploadedFile.new("../spec/fixtures/
test_upload.txt", "text/plain")

The actual params are specified as:
{ :uploaded_data => fdata,
     :filename => file_reference_name(identifier)
   }

Now, this is being passed successfully into attachment-fu, where it  
is processed. Well, almost successfully. Somehow, along the way, the  
TestUploadedFile, struct, mock, whatever you want, gets turned into a  
String. Then it blows up when attachment-fu tries to retrieve the  
content type:

#<NoMethodError: undefined method `content_type' for  
"#<ActionController::TestUploadedFile:0x34349ac>":String>

Somehow, I can't seem to pass anything but a String down into the  
controller. Even in the action, the TestUploadedFile is already  
transmogrified into a String (which, of course, has no content_type  
property). I put a logging statement in the ActionController too, and  
it seems that the entire params hash is turned into a string  
somewhere in there - which would explain why the object has literally  
no chance of going through.

I'm a bit stumped by this. I guess it makes sense that params are  
turned into strings - but then what sort of string should i specify  
for a file upload?

Thanks for any help.

Daniel
_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: Attachment-fu + Story Runner

by David Chelimsky-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Dec 11, 2007 6:18 AM, Daniel Tenner <daniel.ruby@...> wrote:

> Hi all,
>
> I'm trying to run a Story Runner integration test that uploads a file
> through Attachment-fu.
>
> I've tried various ways of specifying the file data, from custom mocks:
> class MockFile < Struct.new
> (:original_filename, :read, :content_type); end
> fdata = MockFile.new  "test_upload.txt", "Test Upload", "text/plain"
>
> to 'proper' railsy stubs like:
>
> fdata = ActionController::TestUploadedFile.new("../spec/fixtures/
> test_upload.txt", "text/plain")
>
> The actual params are specified as:
> { :uploaded_data => fdata,
>      :filename => file_reference_name(identifier)
>    }
>
> Now, this is being passed successfully into attachment-fu, where it
> is processed. Well, almost successfully. Somehow, along the way, the
> TestUploadedFile, struct, mock, whatever you want, gets turned into a
> String. Then it blows up when attachment-fu tries to retrieve the
> content type:
>
> #<NoMethodError: undefined method `content_type' for
> "#<ActionController::TestUploadedFile:0x34349ac>":String>
>
> Somehow, I can't seem to pass anything but a String down into the
> controller. Even in the action, the TestUploadedFile is already
> transmogrified into a String (which, of course, has no content_type
> property). I put a logging statement in the ActionController too, and
> it seems that the entire params hash is turned into a string
> somewhere in there - which would explain why the object has literally
> no chance of going through.
>
> I'm a bit stumped by this. I guess it makes sense that params are
> turned into strings - but then what sort of string should i specify
> for a file upload?
>
> Thanks for any help.

Code please.
_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: Attachment-fu + Story Runner

by Daniel Tenner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've pasted up the code at:


Since there are quite a few files involved.

Thanks for your time,

Daniel

On 11 Dec 2007, at 13:28 11 Dec 2007, David Chelimsky wrote:

On Dec 11, 2007 6:18 AM, Daniel Tenner <daniel.ruby@...> wrote:
Hi all,

I'm trying to run a Story Runner integration test that uploads a file
through Attachment-fu.

I've tried various ways of specifying the file data, from custom mocks:
class MockFile < Struct.new
(:original_filename, :read, :content_type); end
fdata = MockFile.new  "test_upload.txt", "Test Upload", "text/plain"

to 'proper' railsy stubs like:

fdata = ActionController::TestUploadedFile.new("../spec/fixtures/
test_upload.txt", "text/plain")

The actual params are specified as:
{ :uploaded_data => fdata,
     :filename => file_reference_name(identifier)
   }

Now, this is being passed successfully into attachment-fu, where it
is processed. Well, almost successfully. Somehow, along the way, the
TestUploadedFile, struct, mock, whatever you want, gets turned into a
String. Then it blows up when attachment-fu tries to retrieve the
content type:

#<NoMethodError: undefined method `content_type' for
"#<ActionController::TestUploadedFile:0x34349ac>":String>

Somehow, I can't seem to pass anything but a String down into the
controller. Even in the action, the TestUploadedFile is already
transmogrified into a String (which, of course, has no content_type
property). I put a logging statement in the ActionController too, and
it seems that the entire params hash is turned into a string
somewhere in there - which would explain why the object has literally
no chance of going through.

I'm a bit stumped by this. I guess it makes sense that params are
turned into strings - but then what sort of string should i specify
for a file upload?

Thanks for any help.

Code please.
_______________________________________________
rspec-users mailing list


_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: Attachment-fu + Story Runner

by Luis Lavena :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Dec 11, 2007 10:57 AM, Daniel Tenner <daniel.ruby@...> 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@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: Attachment-fu + Story Runner

by Daniel Tenner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...> wrote:

I've pasted up the code at:


Since there are quite a few files involved.

Thanks for your time,


A similar discussion was raised back in november (about fixture_file_upload):


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 mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: Attachment-fu + Story Runner

by Daniel Tenner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...> wrote:

I've pasted up the code at:


Since there are quite a few files involved.

Thanks for your time,


A similar discussion was raised back in november (about fixture_file_upload):


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 mailing list


_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: Attachment-fu + Story Runner

by Raimond Garcia :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@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@rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> rspec-users@rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users


_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Re: Attachment-fu + Story Runner

by Daniel Tenner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok, a bit more digging and I found this is a Rails issue, that is logged here:


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

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@...>  
wrote:

I've pasted up the code at:


Since there are quite a few files involved.

Thanks for your time,


A similar discussion was raised back in november (about  
fixture_file_upload):


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 mailing list


_______________________________________________
rspec-users mailing list


-- 
Sent from the rspec-users mailing list archive at Nabble.com.

_______________________________________________
rspec-users mailing list


_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: Attachment-fu + Story Runner

by David Chelimsky-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Dec 12, 2007 5:41 AM, Daniel Tenner <daniel.ruby@...> 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@...>
> 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@...
> http://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> rspec-users@...
> http://rubyforge.org/mailman/listinfo/rspec-users
>
>
> _______________________________________________
> rspec-users mailing list
> rspec-users@...
> 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@...
> http://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> rspec-users@...
> http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: Attachment-fu + Story Runner

by Joe Van Dyk-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

What was the resolution on this?  How do you people test uploads with
rspec stories?

On Wed, Dec 12, 2007 at 6:54 AM, David Chelimsky <dchelimsky@...> wrote:

> On Dec 12, 2007 5:41 AM, Daniel Tenner <daniel.ruby@...> 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@...>
>  > 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@...
>  > http://rubyforge.org/mailman/listinfo/rspec-users
>  >
>  > _______________________________________________
>  > rspec-users mailing list
>  > rspec-users@...
>  > http://rubyforge.org/mailman/listinfo/rspec-users
>  >
>  >
>  > _______________________________________________
>  > rspec-users mailing list
>  > rspec-users@...
>  > 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@...
>  > http://rubyforge.org/mailman/listinfo/rspec-users
>  >
>  > _______________________________________________
>  > rspec-users mailing list
>  > rspec-users@...
>  > http://rubyforge.org/mailman/listinfo/rspec-users
>  >
>  _______________________________________________
>  rspec-users mailing list
>  rspec-users@...
>  http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: Attachment-fu + Story Runner

by Rick DeNatale :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 3/20/08, Joe Van Dyk <joe@...> wrote:
> What was the resolution on this?  How do you people test uploads with
>  rspec stories?

I submitted a Rails patch to address the underlying problem
http://dev.rubyonrails.org/ticket/11091

It got in as changeset 8978 and should be in edge rails.

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/
_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: Attachment-fu + Story Runner

by Joe Van Dyk-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Mar 20, 2008 at 3:34 AM, Rick DeNatale <rick.denatale@...> wrote:
> On 3/20/08, Joe Van Dyk <joe@...> wrote:
>  > What was the resolution on this?  How do you people test uploads with
>  >  rspec stories?
>
>  I submitted a Rails patch to address the underlying problem
>  http://dev.rubyonrails.org/ticket/11091
>
>  It got in as changeset 8978 and should be in edge rails.

Would it be worth it to monkeypatch that patch into rspec?
_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: Attachment-fu + Story Runner

by David Chelimsky-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Mar 21, 2008 at 1:35 AM, Joe Van Dyk <joe@...> wrote:

> On Thu, Mar 20, 2008 at 3:34 AM, Rick DeNatale <rick.denatale@...> wrote:
>  > On 3/20/08, Joe Van Dyk <joe@...> wrote:
>  >  > What was the resolution on this?  How do you people test uploads with
>  >  >  rspec stories?
>  >
>  >  I submitted a Rails patch to address the underlying problem
>  >  http://dev.rubyonrails.org/ticket/11091
>  >
>  >  It got in as changeset 8978 and should be in edge rails.
>
>  Would it be worth it to monkeypatch that patch into rspec?

Why would we do that? It's already in edge rails.

>
>
> _______________________________________________
>  rspec-users mailing list
>  rspec-users@...
>  http://rubyforge.org/mailman/listinfo/rspec-users
>
_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: Attachment-fu + Story Runner

by Joe Van Dyk-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Mar 21, 2008 at 5:46 AM, David Chelimsky <dchelimsky@...> wrote:

>
> On Fri, Mar 21, 2008 at 1:35 AM, Joe Van Dyk <joe@...> wrote:
>  > On Thu, Mar 20, 2008 at 3:34 AM, Rick DeNatale <rick.denatale@...> wrote:
>  >  > On 3/20/08, Joe Van Dyk <joe@...> wrote:
>  >  >  > What was the resolution on this?  How do you people test uploads with
>  >  >  >  rspec stories?
>  >  >
>  >  >  I submitted a Rails patch to address the underlying problem
>  >  >  http://dev.rubyonrails.org/ticket/11091
>  >  >
>  >  >  It got in as changeset 8978 and should be in edge rails.
>  >
>  >  Would it be worth it to monkeypatch that patch into rspec?
>
>  Why would we do that? It's already in edge rails.

Because I can't upgrade to edge rails.  And I want to be able to test
file uploads.

I've applied the 8978 changeset to my stable rails -- but I'm still
unsure of how to test file uploads in the context of a rspec story.
Normally, I'd use fixture_file_upload, but that method doesn't seem to
be available in rspec.  Do I need to do anything special?

Is anyone testing file uploads with rspec stories?
_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users

Re: Attachment-fu + Story Runner

by Joe Van Dyk-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Apr 4, 2008 at 4:10 PM, Joe Van Dyk <joe@...> wrote:

> On Fri, Mar 21, 2008 at 5:46 AM, David Chelimsky <dchelimsky@...> wrote:
>  >
>  > On Fri, Mar 21, 2008 at 1:35 AM, Joe Van Dyk <joe@...> wrote:
>  >  > On Thu, Mar 20, 2008 at 3:34 AM, Rick DeNatale <rick.denatale@...> wrote:
>  >  >  > On 3/20/08, Joe Van Dyk <joe@...> wrote:
>  >  >  >  > What was the resolution on this?  How do you people test uploads with
>  >  >  >  >  rspec stories?
>  >  >  >
>  >  >  >  I submitted a Rails patch to address the underlying problem
>  >  >  >  http://dev.rubyonrails.org/ticket/11091
>  >  >  >
>  >  >  >  It got in as changeset 8978 and should be in edge rails.
>  >  >
>  >  >  Would it be worth it to monkeypatch that patch into rspec?
>  >
>  >  Why would we do that? It's already in edge rails.
>
>  Because I can't upgrade to edge rails.  And I want to be able to test
>  file uploads.
>
>  I've applied the 8978 changeset to my stable rails -- but I'm still
>  unsure of how to test file uploads in the context of a rspec story.
>  Normally, I'd use fixture_file_upload, but that method doesn't seem to
>  be available in rspec.  Do I need to do anything special?
>
>  Is anyone testing file uploads with rspec stories?

Think I got it working, here's an example step:

  When("$username uploads a picathon image") do |username|
    params = { :media =>
ActionController::TestUploadedFile.new(RAILS_ROOT +
'/test/fixtures/files/image.jpg') }
    @sessions[username].post user_uploads_path(@users[username]), params
    @sessions[username].visits user_uploads_path(@users[username])
  end
_______________________________________________
rspec-users mailing list
rspec-users@...
http://rubyforge.org/mailman/listinfo/rspec-users