{"id":1127,"date":"2011-07-22T09:11:04","date_gmt":"2011-07-22T17:11:04","guid":{"rendered":"http:\/\/www.codebelay.com\/blog\/?p=1127"},"modified":"2011-07-22T09:28:25","modified_gmt":"2011-07-22T17:28:25","slug":"how-to-test-image-uploads-with-minitest-on-padrino","status":"publish","type":"post","link":"https:\/\/www.codebelay.com\/blog\/2011\/07\/22\/how-to-test-image-uploads-with-minitest-on-padrino\/","title":{"rendered":"How To Test Image Uploads With MiniTest On Padrino"},"content":{"rendered":"<p>This week I got to pair program with <a href=\"https:\/\/github.com\/oren\">Oren Golan<\/a> whose last high profile job was at <a href=\"http:\/\/borderstylo.com\">Border Stylo<\/a>. While there, he wrote <a href=\"http:\/\/borderstylo.com\/posts_by\/oren-golan\">a series of excellent blog posts<\/a> that I highly recommend reading. The one that caught my eye was <a href=\"http:\/\/borderstylo.com\/posts\/251-minitest-rubys-new-bff\">his post on MiniTest<\/a>, that&#8217;s a lighter version of RSpec.<\/p>\n<p>We created a <a href=\"http:\/\/www.padrinorb.com\/\">Padrino<\/a> app that uses the <a href=\"http:\/\/sequel.rubyforge.org\/\">Sequel<\/a> gem as an ORM for SQLite.<\/p>\n<p>We tested a raw file upload and the uploading capabilities of <a href=\"https:\/\/github.com\/jnicklas\/carrierwave\">Carrierwave<\/a>.<\/p>\n<p>The working test is on <a href=\"http:\/\/github.com\/barce\/test\">http:\/\/github.com\/barce\/test<\/a>, and to run it just clone the repo and type the following:<\/p>\n<div style=\"background: #000; color: #fff; padding: 5px;\">\ncd test<br \/>\nbundle install<br \/>\npadrino sq:migrate:up<\/p>\n<\/div>\n<p>Here&#8217;s the test:<\/p>\n<div style=\"background: #000; color: #fff; padding: 5px;\">\n<pre style='background: #000; color: #fff'>\r\n# put this into the test\/test.rb file\r\nrequire 'rubygems'\r\ngem 'minitest'\r\nrequire 'minitest\/autorun'\r\nrequire 'rack\/test'\r\nrequire '..\/config\/boot.rb'\r\n\r\nclass TestManualBadgeType < MiniTest::Unit::TestCase\r\n  include Rack::Test::Methods\r\n\r\n  FILE2UPLOAD  = \"\/Users\/jimbarcelona\/pink-pony.jpg\"\r\n  UPLOADEDFILE = \"\/Users\/jimbarcelona\/repos\/oren\/forks\/test\/test\/pink-pony.jpg\"\r\n\r\n  def app() Test end\r\n\r\n  def setup\r\n    if File.exist?(UPLOADEDFILE)\r\n      File.delete(UPLOADEDFILE)\r\n    end\r\n  end\r\n\r\n  def test_opload\r\n    post '\/', 'file' => Rack::Test::UploadedFile.new(FILE2UPLOAD, 'image\/jpeg')\r\n\r\n    assert_equal last_response.status, 201\r\n  end\r\n\r\n  def test_carrierwave_201\r\n    post '\/carrierwave', 'file' => Rack::Test::UploadedFile.new(FILE2UPLOAD, 'image\/jpeg')\r\n\r\n    assert_equal last_response.status, 201\r\n  end\r\n\r\n  def test_carrierwave_file_exist\r\n    post '\/carrierwave', 'file' => Rack::Test::UploadedFile.new(FILE2UPLOAD, 'image\/jpeg')\r\n    assert_equal last_response.status, 201\r\n  end\r\nend\r\n\r\n<\/pre>\n<\/div>\n<p>Now you&#8217;re ready to run the test upload:<\/p>\n<div style=\"background: #000; color: #fff; padding: 5px;\">\ncd test<br \/>\nruby test.rb\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This week I got to pair program with Oren Golan whose last high profile job was at Border Stylo. While there, he wrote a series of excellent blog posts that I highly recommend reading. The one that caught my eye was his post on MiniTest, that&#8217;s a lighter version of RSpec. We created a Padrino [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,108,33],"tags":[],"class_list":["post-1127","post","type-post","status-publish","format-standard","hentry","category-how-to","category-ruby","category-webapps"],"_links":{"self":[{"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/posts\/1127","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/comments?post=1127"}],"version-history":[{"count":0,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/posts\/1127\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/media?parent=1127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/categories?post=1127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/tags?post=1127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}