A previously working test, that posted a file object no longer works in the latest 3.1. The test looks like this: params[:media][:new_attachment] = File.open("#{Rails.root}/test/data/ less_than_100.png") post :create, params In the controller, I obviously expect params[:media][:new_attachment] to be a File object - and it used to be. Now it looks like #inspect has been called on the file. Debugging out in the test: (rdb:1) params[:media].try(:[], :new_attachment) "#<File:0x007fcd0a950658>" (rdb:1) params[:media].try(:[], :new_attachment).class String Yep, what''s up with that? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> In the controller, I obviously expect params[:media][:new_attachment] > to be a File objectWhy would you expect that? Data that is posted (or sent in a get request) is a string. You aren''t going to get a ruby File object in a real post request, so it makes sense to me that a test wouldn''t give you a File object. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Aug-31 06:57 UTC
Re: 3.1rc8 - posting files in a test no longer works
On Aug 31, 2:22 am, Josh <josh.m.sha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> A previously working test, that posted a file object no longer works > in the latest 3.1. The test looks like this: > > params[:media][:new_attachment] = File.open("#{Rails.root}/test/data/ > less_than_100.png") > post :create, params > > In the controller, I obviously expect params[:media][:new_attachment] > to be a File object - and it used to be. Now it looks like #inspect > has been called on the file. Debugging out in the test: >Rails 3.1 enforces that parameters should look like what you''ll actually get in a test - you used to be able to stick arbitrary objects in there which of course doesn''t reflect what happens in the real world. fixture_file_upload should still work Fred> (rdb:1) params[:media].try(:[], :new_attachment) > "#<File:0x007fcd0a950658>" > (rdb:1) params[:media].try(:[], :new_attachment).class > String > > Yep, what''s up with that?-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Alexander Gitter
2011-Aug-31 11:51 UTC
Re: 3.1rc8 - posting files in a test no longer works
> Rails 3.1 enforces that parameters should look like what you''ll > actually get in a test - you used to be able to stick arbitrary > objects in there which of course doesn''t reflect what happens in the > real world. > fixture_file_upload should still workI have a similar problem. Until now I used to assign a ActionDispatch::Http::UploadedFile to my parameter, which now doesn''t work anymore in rails 3.1. Unfortunately I cannot use fixture_file_upload because it creates a Rack::Test::UploadedFile, which doesn''t provide #tempfile: irb> params[:file].class => Rack::Test::UploadedFile irb> params[:file].tempfile NoMethodError: undefined method `tempfile'' for #<Tempfile:0xb6591b70> There already is a bug report about this problem with fixture_file_upload: https://github.com/rails/rails/issues/799 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> fixture_file_upload should still workWorked for me. Thanks. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Aug-31 15:35 UTC
Re: 3.1rc8 - posting files in a test no longer works
On Aug 31, 12:51 pm, Alexander Gitter <qwertz1...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> I have a similar problem. Until now I used to assign a > ActionDispatch::Http::UploadedFile to my parameter, which now doesn''t > work anymore in rails 3.1. > > Unfortunately I cannot use fixture_file_upload because it creates a > Rack::Test::UploadedFile, which doesn''t provide #tempfile: > > irb> params[:file].class > => Rack::Test::UploadedFile > irb> params[:file].tempfile > NoMethodError: undefined method `tempfile'' for #<Tempfile:0xb6591b70> >It doesn''t have a tempfile method but it does actually wrap a Tempfile and has a @tempfile instance variable. In the past I''ve reopened Rack::Test::UploadedFile to add a tempfile method Fred> There already is a bug report about this problem with > fixture_file_upload:https://github.com/rails/rails/issues/799-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Apparently Analagous Threads
- [Rails 3.2.5] Rails: unit test fixture_path : fixture_file_upload cannot find the file ...
- Cannot get multipart => true , running well in my form when using remote => true
- A file-upload suddenly seems to be nil
- Attachment-fu + Story Runner
- ActiveRecord::Base.transaction - SystemStackError - stack level too deep: