Permalink
Browse files

Initial version

git-svn-id: https://svn.thoughtbot.com/plugins/paperclip/trunk@160 7bbfaf0e-4d1d-0410-9690-a8bb5f8ef2aa
  • Loading branch information...
0 parents commit 13318e61a4953dfc3d2b76e0491b1651f26062fe jyurek committed Aug 5, 2007
27 README
@@ -0,0 +1,27 @@
+Paperclip
+=========
+
+Paperclip is a lightweight attachment manager for ActiveRecord. It saves and manages your attachments be they images or Word Doc with one line of code. You can automatically thumbnail images as they're uploaded, and you don't have to worry about installing any ruby-specific libraries. You don't have to worry about compiling headaches with RMagick, concurrency issues and race conditions with MiniMagick, or unsupported image types with ImageScience. All you need is a working Image- or GraphicsMagick installation.
+
+Paperclip uses the filesystem to save your files. You specify a root that the files will be saved to, and, if you're attaching images, any other formats they need to be converted to, and they'll all be saved to the right place when your object saves. They can even validate beforehand, so you'll know if your user tries to upload an HTML doc as an image.
+
+Usage
+-----
+
+In your model:
+
+class Photo < ActiveRecord::Base
+ has_attached_file :image, :thumbnails => { :medium => "300x300>", :thumb => "100x100>" }
+end
+
+In your view:
+
+<% form_for :photo, @photo, :url => photo_path do |form| %>
+ <%= form.file_field :image %>
+<% end %>
+
+In your controller:
+
+def create
+ @photo = Photo.create( params[:photo] )
+end
22 Rakefile
@@ -0,0 +1,22 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the paperclip plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the paperclip plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'Paperclip'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
2 init.rb
@@ -0,0 +1,2 @@
+require File.join(File.dirname(__FILE__), "lib", "paperclip")
+ActiveRecord::Base.extend( Thoughtbot::Paperclip::ClassMethods )
1 install.rb
@@ -0,0 +1 @@
+# Install hook code here
162 lib/paperclip.rb
@@ -0,0 +1,162 @@
+module Thoughtbot
+ module Paperclip
+
+ DEFAULT_OPTIONS = {
+ :path_prefix => ":rails_root/public/",
+ :url_prefix => "/",
+ :path => ":class/:style/:id",
+ :attachment_type => :image,
+ :thumbnails => {}
+ }
+
+ module ClassMethods
+ def has_attached_file *file_attribute_names
+ options = file_attribute_names.last.is_a?(Hash) ? file_attribute_names.pop : {}
+ options = DEFAULT_OPTIONS.merge(options)
+
+ include InstanceMethods
+ attachments ||= {}
+
+ file_attribute_names.each do |attr|
+ attachments[attr] = (attachments[attr] || {:name => attr}).merge(options)
+
+ define_method "#{attr}=" do |uploaded_file|
+ attachments[attr].merge!({
+ :dirty => true,
+ :files => {:original => uploaded_file},
+ :content_type => uploaded_file.content_type,
+ :filename => sanitize_filename(uploaded_file.original_filename)
+ })
+ write_attribute(:"#{attr}_file_name", attachments[attr][:filename])
+ write_attribute(:"#{attr}_content_type", attachments[attr][:content_type])
+
+ if attachments[attr][:attachment_type] == :image
+ attachments[attr][:thumbnails].each do |style, geometry|
+ attachments[attr][:files][style] = make_thumbnail(attachments[attr][:files][:original], geometry)
+ end
+ end
+
+ uploaded_file
+ end
+
+ define_method "#{attr}_attachment" do
+ attachments[attr]
+ end
+
+ define_method "#{attr}_filename" do |*args|
+ style = args.shift || :original # This prevents arity warnings
+ path_for attachments[attr], style
+ end
+
+ define_method "#{attr}_url" do |*args|
+ style = args.shift || :original # This prevents arity warnings
+ url_for attachments[attr], style
+ end
+
+ define_method "#{attr}_valid?" do
+ attachments[attr][:thumbnails].all? do |style, geometry|
+ attachments[attr][:dirty] ?
+ !attachments[attr][:files][style].blank? :
+ File.file?( path_for(attachments[attr], style))
+ end
+ end
+
+ define_method "#{attr}_after_save" do
+ if attachments[attr].keys.any?
+ write_attachment attachments[attr]
+ attachments[attr][:dirty] = false
+ attachments[attr][:files] = nil
+ end
+ end
+ private :"#{attr}_after_save"
+ after_save :"#{attr}_after_save"
+
+ define_method "#{attr}_before_destroy" do
+ if attachments[attr].keys.any?
+ delete_attachment attachments[attr]
+ end
+ end
+ private :"#{attr}_before_destroy"
+ before_destroy :"#{attr}_before_destroy"
+ end
+ end
+ end
+
+ module InstanceMethods
+
+ def path_for attachment, style
+ prefix = File.join(attachment[:path_prefix], attachment[:path])
+ prefix.gsub!(/:rails_root/, RAILS_ROOT)
+ prefix.gsub!(/:id/, self.id.to_s) if self.id
+ prefix.gsub!(/:class/, self.class.to_s.underscore)
+ prefix.gsub!(/:style/, style.to_s)
+ File.join( prefix.split("/"), read_attribute("#{attachment[:name]}_file_name") )
+ end
+
+ def url_for attachment, style
+ prefix = File.join(attachment[:url_prefix], attachment[:path])
+ prefix.gsub!(/:rails_root/, RAILS_ROOT)
+ prefix.gsub!(/:id/, self.id.to_s) if self.id
+ prefix.gsub!(/:class/, self.class.to_s.underscore)
+ prefix.gsub!(/:style/, style.to_s)
+ File.join( prefix.split("/"), read_attribute("#{attachment[:name]}_file_name") )
+ end
+
+ def ensure_directories_for attachment
+ attachment[:files].keys.each do |style|
+ dirname = File.dirname(path_for(attachment, style))
+ FileUtils.mkdir_p dirname
+ end
+ end
+
+ def write_attachment attachment
+ ensure_directories_for attachment
+ attachment[:files].each do |style, atch|
+ File.open( path_for(attachment, style), "w" ) do |file|
+ atch.rewind
+ file.write(atch.read)
+ end
+ end
+ end
+
+ def delete_attachment attachment
+ (attachment[:thumbnails].keys + [:original]).each do |style|
+ FileUtils.rm path_for(attachment, style)
+ end
+ end
+
+ def make_thumbnail orig_io, geometry
+ thumb = IO.popen("convert - -scale '#{geometry}' - > /dev/stdout", "w+") do |io|
+ orig_io.rewind
+ io.write(orig_io.read)
+ io.close_write
+ io.read
+ end
+ raise "Convert returned with result code #{$?.exitstatus}." unless $?.success?
+ StringIO.new(thumb)
+ end
+
+ def sanitize_filename filename
+ File.basename(filename).gsub(/[^\w\.\_]/,'_')
+ end
+ protected :sanitize_filename
+ end
+
+ module Upfile
+ def content_type
+ type = self.path.match(/\.(\w+)$/)[1]
+ case type
+ when "jpg", "png", "gif" then "image/#{type}"
+ when "txt", "csv", "xml", "html", "htm" then "text/#{type}"
+ else "application/#{type}"
+ end
+ end
+
+ def original_filename
+ self.path
+ end
+ end
+ end
+end
+
+File.send :include, Thoughtbot::Paperclip::Upfile
4 tasks/paperclip_tasks.rake
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :paperclip do
+# # Task goes here
+# end
4 test/database.yml
@@ -0,0 +1,4 @@
+test:
+ adapter: sqlite3
+ dbfile: paperclip.db
+ #database: ":memory:"
306 test/debug.log
@@ -0,0 +1,306 @@
+# Logfile created on Sat Aug 04 20:42:44 -0400 2007 by logger.rb/1.5.2.9
+ SQL (0.004173) CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.002037) CREATE TABLE bars ("id" INTEGER PRIMARY KEY NOT NULL, "document_file_name" varchar(255) DEFAULT NULL, "document_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000588) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000491) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000494) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000351) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000581) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000470) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000505) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000364) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000587) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000574) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000485) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000359) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000597) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000605) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000443) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000496) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000646) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000463) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000473) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000459) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.062484) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000505) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000499) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000485) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000594) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000481) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000506) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000477) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000602) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000608) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000495) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000477) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000588) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000483) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000403) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000394) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000618) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000560) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000397) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000629) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000589) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000476) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000511) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000523) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000669) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000473) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000487) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000415) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000582) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000470) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000469) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000465) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000627) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000539) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000489) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000457) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000611) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000500) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000490) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000515) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000608) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000549) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000554) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000523) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000678) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000479) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000570) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000462) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000577) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000489) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000544) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000438) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000619) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000511) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000508) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000469) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.002361) CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.002155) CREATE TABLE bars ("id" INTEGER PRIMARY KEY NOT NULL, "document_file_name" varchar(255) DEFAULT NULL, "document_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000407) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000420) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000517) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000501) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000737) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000458) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000489) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000689) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000813) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000473) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000498) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000435) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000590) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000474) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000558) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000408) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000605) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000470) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000509) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000568) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000615) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000484) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000446) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000436) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000593) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000470) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000553) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000427) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000598) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000476) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000498) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000381) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000596) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000520) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000550) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000454) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000602) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000473) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000607) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000410) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000624) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000512) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000501) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.001001) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000645) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000492) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000604) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000516) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000736) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000514) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000613) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000456) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000610) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000471) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000563) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ Bar Destroy (0.000414)  DELETE FROM bars
+ WHERE id = 19
+
+ SQL (0.000397) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000565) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000633) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ Foo Destroy (0.000514)  DELETE FROM foos
+ WHERE id = 19
+
+ SQL (0.000553) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000527) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000546) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ Bar Destroy (0.000413)  DELETE FROM bars
+ WHERE id = 21
+
+ SQL (0.000414) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000445) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000673) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ Foo Destroy (0.000450)  DELETE FROM foos
+ WHERE id = 21
+
+ SQL (0.000495) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000521) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000573) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ Bar Destroy (0.000444)  DELETE FROM bars
+ WHERE id = 23
+
+ SQL (0.000404) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000486) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000614) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ Foo Destroy (0.000418)  DELETE FROM foos
+ WHERE id = 23
+
+ SQL (0.000557) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000508) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000526) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ Bar Destroy (0.000408)  DELETE FROM bars
+ WHERE id = 25
+
+ SQL (0.000373) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000411) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000601) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ Foo Destroy (0.000447)  DELETE FROM foos
+ WHERE id = 25
+
+ SQL (0.000534) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000484) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000977) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ Bar Destroy (0.000510)  DELETE FROM bars
+ WHERE id = 27
+
+ SQL (0.000392) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.001124) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000614) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ Foo Destroy (0.000433)  DELETE FROM foos
+ WHERE id = 27
+
+ SQL (0.000609) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000505) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000554) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ Bar Destroy (0.000640)  DELETE FROM bars
+ WHERE id = 29
+
+ SQL (0.000635) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000510) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000669) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ Foo Destroy (0.000551)  DELETE FROM foos
+ WHERE id = 29
+
+ SQL (0.000490) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000503) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000534) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ Bar Destroy (0.000436)  DELETE FROM bars
+ WHERE id = 31
+
+ SQL (0.000460) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000495) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000000) SQLite3::SQLException: table foos already exists: CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000601) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ Foo Destroy (0.000463)  DELETE FROM foos
+ WHERE id = 31
+
+ SQL (0.000474) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000480) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000617) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ Bar Destroy (0.000485)  DELETE FROM bars
+ WHERE id = 33
+
+ SQL (0.000474) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000450) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.246580) CREATE TABLE foos ("id" INTEGER PRIMARY KEY NOT NULL, "image_file_name" varchar(255) DEFAULT NULL, "image_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.002094) CREATE TABLE bars ("id" INTEGER PRIMARY KEY NOT NULL, "document_file_name" varchar(255) DEFAULT NULL, "document_content_type" varchar(255) DEFAULT NULL) 
+ SQL (0.000496) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ Foo Destroy (0.000487)  DELETE FROM foos
+ WHERE id = 1
+
+ SQL (0.000480) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000534) INSERT INTO foos ("image_content_type", "image_file_name") VALUES('image/jpg', 'test_image.jpg')
+ SQL (0.000625) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ Bar Destroy (0.000498)  DELETE FROM bars
+ WHERE id = 1
+
+ SQL (0.000451) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
+ SQL (0.000495) INSERT INTO bars ("document_file_name", "document_content_type") VALUES('test_document.doc', 'application/doc')
BIN test/fixtures/test_document.doc
Binary file not shown.
BIN test/fixtures/test_image.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 test/models.rb
@@ -0,0 +1,22 @@
+begin
+ ActiveRecord::Base.connection.create_table :foos do |table|
+ table.column :image_file_name, :string
+ table.column :image_content_type, :string
+ end
+ ActiveRecord::Base.connection.create_table :bars do |table|
+ table.column :document_file_name, :string
+ table.column :document_content_type, :string
+ end
+rescue Exception
+end
+
+class Foo < ActiveRecord::Base
+ has_attached_file :image, :attachment_type => :image,
+ :thumbnails => { :thumb => "100x100>", :medium => "300x300>" },
+ :path_prefix => "."
+end
+
+class Bar < ActiveRecord::Base
+ has_attached_file :document, :attachment_type => :document,
+ :path_prefix => "."
+end
45 test/paperclip_images_test.rb
@@ -0,0 +1,45 @@
+require 'test/unit'
+require File.dirname(__FILE__) + "/test_helper.rb"
+require File.dirname(__FILE__) + "/../init.rb"
+require File.join(File.dirname(__FILE__), "models.rb")
+
+class PaperclipImagesTest < Test::Unit::TestCase
+ def setup
+ assert @foo = Foo.new
+ assert @file = File.new(File.join(File.dirname(__FILE__), 'fixtures', 'test_image.jpg'))
+ assert @foo.image = @file
+ end
+
+ def test_should_validate_before_save
+ assert @foo.image_valid?
+ assert @foo.valid?
+ end
+
+ def test_should_save_the_file_and_its_thumbnails
+ assert @foo.save
+ assert File.exists?( @foo.image_filename(:original) )
+ assert File.exists?( @foo.image_filename(:medium) )
+ assert File.exists?( @foo.image_filename(:thumb) )
+ assert File.size?( @foo.image_filename(:original) )
+ assert File.size?( @foo.image_filename(:medium) )
+ assert File.size?( @foo.image_filename(:thumb) )
+ `identify '#{@foo.image_filename(:original)}'`; assert $?.exitstatus == 0
+ `identify '#{@foo.image_filename(:medium)}'`; assert $?.exitstatus == 0
+ `identify '#{@foo.image_filename(:thumb)}'`; assert $?.exitstatus == 0
+ end
+
+ def test_should_validate_to_make_sure_the_thumbnails_exist
+ assert @foo.save
+ assert @foo.image_valid?
+ assert @foo.valid?
+ end
+
+ def test_should_delete_all_thumbnails_on_destroy
+ assert @foo.save
+ assert @foo.destroy
+ assert !File.exists?( @foo.image_filename(:original) )
+ assert !File.exists?( @foo.image_filename(:medium) )
+ assert !File.exists?( @foo.image_filename(:thumb) )
+ end
+
+end
37 test/paperclip_test.rb
@@ -0,0 +1,37 @@
+require 'test/unit'
+require File.dirname(__FILE__) + "/test_helper.rb"
+require File.dirname(__FILE__) + "/../init.rb"
+require File.join(File.dirname(__FILE__), "models.rb")
+
+class PaperclipTest < Test::Unit::TestCase
+ def setup
+ assert @bar = Bar.new
+ assert @file = File.new(File.join(File.dirname(__FILE__), 'fixtures', 'test_document.doc'))
+ assert @bar.document = @file
+ end
+
+ def test_should_validate_before_save
+ assert @bar.document_valid?
+ assert @bar.valid?
+ end
+
+ def test_should_save_the_created_file_to_the_final_asset_directory
+ assert @bar.save
+ assert File.exists?( @bar.document_filename )
+ end
+
+ def test_should_validate
+ assert @bar.save
+ assert @bar.document_valid?
+ assert @bar.valid?
+ end
+
+ def test_should_delete_files_on_destroy
+ assert @bar.save
+ assert File.exists?( @bar.document_filename )
+
+ assert @bar.destroy
+ assert !File.exists?( @bar.document_filename )
+ end
+
+end
41 test/test_helper.rb
@@ -0,0 +1,41 @@
+require 'rubygems'
+require 'test/unit'
+require 'active_record'
+require 'active_record/fixtures'
+require 'fileutils'
+require 'pp'
+
+config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
+ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
+ActiveRecord::Base.establish_connection(config[ENV['RAILS_ENV'] || 'test'])
+
+Test::Unit::TestCase.fixture_path = File.dirname(__FILE__) + "/fixtures/"
+$LOAD_PATH.unshift(Test::Unit::TestCase.fixture_path)
+
+RAILS_ROOT = "test" unless Object.const_defined? "RAILS_ROOT"
+
+class Test::Unit::TestCase #:nodoc:
+ def create_fixtures(*table_names)
+ if block_given?
+ Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names) { yield }
+ else
+ Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, table_names)
+ end
+ end
+
+ def self.load_all_fixtures
+ all_fixtures = Dir.glob("#{File.dirname(__FILE__)}/fixtures/*.yml").collect do |f|
+ puts "Loading fixture '#{f}'"
+ File.basename(f).gsub(/\.yml$/, "").to_sym
+ end
+ Fixtures.create_fixtures(Test::Unit::TestCase.fixture_path, all_fixtures)
+ end
+
+ # Turn off transactional fixtures if you're working with MyISAM tables in MySQL
+ self.use_transactional_fixtures = true
+
+ # Instantiated fixtures are slow, but give you @david where you otherwise would need people(:david)
+ self.use_instantiated_fixtures = false
+
+ # Add more helper methods to be used by all tests here...
+end
1 uninstall.rb
@@ -0,0 +1 @@
+# Uninstall hook code here

0 comments on commit 13318e6

Please sign in to comment.