Nicholas Wieland
2008-Jun-09 12:05 UTC
[rspec-users] Testing file attachment with Paperclip
Does someone have an example on faking a file upload for just ensuring it gets called, without actually uploading the file to s3. I thought that stubbing Model.has_attached_file would be enough, but it doesn''t seem so ... This is what I did: Video.stub!( :has_attached_file ).with( :name ).and_return( true ) has_attached_file is from paperclip, it gets mixed to the model. 1) RightAws::AwsError in ''VideosController should create a valid Video'' AWS access keys are required to operate on S3 /Users/ngw/zooppa-4/app/controllers/videos_controller.rb:6:in `create'' /Users/ngw/zooppa-4/spec/controllers/videos_controller_spec.rb:17: Maybe I missed something ? TIA, ngw -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2435 bytes Desc: not available URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080609/97e7ad34/attachment.bin>
David Chelimsky
2008-Jun-09 12:11 UTC
[rspec-users] Testing file attachment with Paperclip
On Jun 9, 2008, at 7:05 AM, Nicholas Wieland wrote:> Does someone have an example on faking a file upload for just > ensuring it gets calledhttp://talklikeaduck.denhaven2.com/articles/2008/04/18/rails-integration-test-file-upload-plugin Cheers, David
Nicholas Wieland
2008-Jun-09 12:18 UTC
[rspec-users] Testing file attachment with Paperclip
Il giorno 09/giu/08, alle ore 14:11, David Chelimsky ha scritto:> On Jun 9, 2008, at 7:05 AM, Nicholas Wieland wrote: > >> Does someone have an example on faking a file upload for just >> ensuring it gets called > > http://talklikeaduck.denhaven2.com/articles/2008/04/18/rails-integration-test-file-upload-pluginI haven''t been clear enough, my point is not to fake the file upload (there''s also fixture_file_upload for that) but to fake the receiver, making it dumb enough to avoid performing every operation on the file (in my case, uploading to s3). ngw -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2435 bytes Desc: not available URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080609/d1fc57bd/attachment-0001.bin>
On Mon, Jun 9, 2008 at 8:18 AM, Nicholas Wieland <nicholas.wieland at gmail.com> wrote:> Il giorno 09/giu/08, alle ore 14:11, David Chelimsky ha scritto: > > On Jun 9, 2008, at 7:05 AM, Nicholas Wieland wrote: >> >> Does someone have an example on faking a file upload for just ensuring it >>> gets called >>> >> >> >> http://talklikeaduck.denhaven2.com/articles/2008/04/18/rails-integration-test-file-upload-plugin >> > > I haven''t been clear enough, my point is not to fake the file upload > (there''s also fixture_file_upload for that) but to fake the receiver, making > it dumb enough to avoid performing every operation on the file (in my case, > uploading to s3). >I''m pretty sure the problem is that by the time you stub has_attached file, which is a class method run when the class is loaded, it''s too late. Based on a quick look at the paperclip project site, it looks like what you want to stub is the save_attached_files method on the model INSTANCE, which the has_attached_file registers as an after_save callback. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080609/ed0d6909/attachment.html>
Rick Denatale wrote:> On Mon, Jun 9, 2008 at 8:18 AM, Nicholas Wieland > <nicholas.wieland at gmail.com> > wrote: > >>> >> >> I haven''t been clear enough, my point is not to fake the file upload >> (there''s also fixture_file_upload for that) but to fake the receiver, making >> it dumb enough to avoid performing every operation on the file (in my case, >> uploading to s3). >> > > I''m pretty sure the problem is that by the time you stub has_attached > file, > which is a class method run when the class is loaded, it''s too late. > Based > on a quick look at the paperclip project site, it looks like what you > want > to stub is the save_attached_files method on the model INSTANCE, which > the > has_attached_file registers as an after_save callback. > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/Rick, I''m interested finding out how to do this, too (Rspec newbie and really terrible with mocking & stubbing). Are you suggesting we do something like this (?); Paperclip.saved_attached_file.stub!(:avatar).and_return(true) It''s nice to be able to spec the app actually working with S3 but, my specs are taking over 3 minutes now and commenting out all the S3 involved specs kinda makes me nervous! -- Posted via http://www.ruby-forum.com/.
Nicholas Wieland wrote:> Does someone have an example on faking a file upload for just ensuring > it gets called, without actually uploading the file to s3. > I thought that stubbing Model.has_attached_file would be enough, but > it doesn''t seem so ... > > This is what I did: > > Video.stub!( :has_attached_file ).with( :name ).and_return( true ) > > has_attached_file is from paperclip, it gets mixed to the model. > > 1) > RightAws::AwsError in ''VideosController should create a valid Video'' > AWS access keys are required to operate on S3 > /Users/ngw/zooppa-4/app/controllers/videos_controller.rb:6:in `create'' > /Users/ngw/zooppa-4/spec/controllers/videos_controller_spec.rb:17: > > Maybe I missed something ? > > TIA, > ngwI am struggling with Webrat and Paperclip. If I specify: validates_attachment_presence :image, then AR complains because there is no image set. Therefore I decide to remove this validation, and instead use: validates_presence_of :image_file_name, to trick him. But it still doesn''t work. When I create a new object, even if I put: Product.create!(..., :image_file_name => ''thumb1.png''), AR still complains and it says that Image file name is missing. There must be some Paperclip magic which I can''t get around. The only solution I have found is to remove the validation of the attachment for passing the tests, but I''d like to keep it. Anyone ran into this previously? -- Posted via http://www.ruby-forum.com/.
On 2009-01-16, at 17:42, Fernando Perez wrote:> Nicholas Wieland wrote: >> Does someone have an example on faking a file upload for just >> ensuring >> it gets called, without actually uploading the file to s3. >> I thought that stubbing Model.has_attached_file would be enough, but >> it doesn''t seem so ... >> >> This is what I did: >> >> Video.stub!( :has_attached_file ).with( :name ).and_return( true ) >> >> has_attached_file is from paperclip, it gets mixed to the model. >> >> 1) >> RightAws::AwsError in ''VideosController should create a valid Video'' >> AWS access keys are required to operate on S3 >> /Users/ngw/zooppa-4/app/controllers/videos_controller.rb:6:in >> `create'' >> /Users/ngw/zooppa-4/spec/controllers/videos_controller_spec.rb:17: >> >> Maybe I missed something ? >> >> TIA, >> ngw > > I am struggling with Webrat and Paperclip. If I specify: > validates_attachment_presence :image, then AR complains because > there is no image set. > > Therefore I decide to remove this validation, and instead use: > validates_presence_of :image_file_name, to trick him. But it still > doesn''t work. When I create a new object, even if I put: > Product.create!(..., :image_file_name => ''thumb1.png''), AR still > complains and it says that Image file name is missing. There must be > some Paperclip magic which I can''t get around. > > The only solution I have found is to remove the validation of the > attachment for passing the tests, but I''d like to keep it. > > Anyone ran into this previously?G''day again Fernando. IIRC, Paperclip''s #save_attached_files is what takes care of saving the attachment to disk, uploading it to S3, etc. Here''s a small gist that tests the allowance of JPG files, and ensures that the file isn''t saved [to disk, for me]: http://gist.github.com/48264 I hope that helps! Nick
> G''day again Fernando. IIRC, Paperclip''s #save_attached_files is what > takes care of saving the attachment to disk, uploading it to S3, etc. > Here''s a small gist that tests the allowance of JPG files, and ensures > that the file isn''t saved [to disk, for me]: > http://gist.github.com/48264 > > I hope that helps! > NickHi Nick, Don''t ask me why, but this morning I tried once again to simply do: product.image = File.new(''path_to_image.png''), and it worked perfectly as expected and passed validations and whatever. -- Posted via http://www.ruby-forum.com/.
On 2009-01-17, at 05:10, Fernando Perez wrote:>> G''day again Fernando. IIRC, Paperclip''s #save_attached_files is what >> takes care of saving the attachment to disk, uploading it to S3, etc. >> Here''s a small gist that tests the allowance of JPG files, and >> ensures >> that the file isn''t saved [to disk, for me]: >> http://gist.github.com/48264 >> >> I hope that helps! >> Nick > > Hi Nick, > > Don''t ask me why, but this morning I tried once again to simply do: > product.image = File.new(''path_to_image.png''), and it worked perfectly > as expected and passed validations and whatever.I''m glad you got it sorted out =)
Nicholas Wieland wrote:> Does someone have an example on faking a file upload for just ensuring > it gets called, without actually uploading the file to s3. > I thought that stubbing Model.has_attached_file would be enough, but > it doesn''t seem so ... > > This is what I did: > > Video.stub!( :has_attached_file ).with( :name ).and_return( true ) > > has_attached_file is from paperclip, it gets mixed to the model. > > 1) > RightAws::AwsError in ''VideosController should create a valid Video'' > AWS access keys are required to operate on S3 > /Users/ngw/zooppa-4/app/controllers/videos_controller.rb:6:in `create'' > /Users/ngw/zooppa-4/spec/controllers/videos_controller_spec.rb:17: > > Maybe I missed something ? > > TIA, > ngwhello dear..... have u got the solution 4 that...then please tell me... and second one is, from where u get S3 aws_access_key and aws_secret_access_key and bucket_base_name .. or from wher to set this......... thanks replay me on deven.patel at trinitywebtech.com -- Posted via http://www.ruby-forum.com/.
Nicholas Wieland wrote:> Does someone have an example on faking a file upload for just ensuring > it gets called, without actually uploading the file to s3. > I thought that stubbing Model.has_attached_file would be enough, but > it doesn''t seem so ... > > This is what I did: > > Video.stub!( :has_attached_file ).with( :name ).and_return( true ) > > has_attached_file is from paperclip, it gets mixed to the model. > > 1) > RightAws::AwsError in ''VideosController should create a valid Video'' > AWS access keys are required to operate on S3 > /Users/ngw/zooppa-4/app/controllers/videos_controller.rb:6:in `create'' > /Users/ngw/zooppa-4/spec/controllers/videos_controller_spec.rb:17: > > Maybe I missed something ? > > TIA, > ngwhello dear..... have u got the solution 4 that...then please tell me... and second one is, from where u get S3 aws_access_key and aws_secret_access_key and bucket_base_name .. or from wher to set this......... thanks replay me on deven.patel at trinitywebtech.com -- Posted via http://www.ruby-forum.com/.