require 'test/unit' require 'rubygems' require 'mocha' require 'active_record' require 'active_support' gem 'sqlite3-ruby' gem 'paperclip' require 'paperclip' gem 'delayed_job' require 'delayed_job' FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures") 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['test']) ROOT = File.join(File.dirname(__FILE__), '..') RAILS_ROOT = ROOT RAILS_ENV = "test" $LOAD_PATH << File.join(ROOT, 'lib') $LOAD_PATH << File.join(ROOT, 'lib', 'delayed', 'paperclip') $LOAD_PATH << File.join(ROOT, 'test') module ActiveRecord class Base end end require File.join(ROOT, 'lib', 'delayed_paperclip.rb') def reset_class class_name ActiveRecord::Base.send(:include, Paperclip) Object.send(:remove_const, class_name) rescue nil klass = Object.const_set(class_name, Class.new(ActiveRecord::Base)) klass.class_eval{ include Paperclip } klass end def reset_table table_name, &block block ||= lambda { |table| true } ActiveRecord::Base.connection.create_table :dummies, {:force => true}, &block end def modify_table table_name, &block ActiveRecord::Base.connection.change_table :dummies, &block end def rebuild_model options = {} ActiveRecord::Base.connection.create_table :dummies, :force => true do |table| table.column :other, :string table.column :avatar_file_name, :string table.column :avatar_content_type, :string table.column :avatar_file_size, :integer table.column :avatar_updated_at, :datetime end rebuild_class options end def rebuild_class options = {} ActiveRecord::Base.send(:include, Paperclip) Object.send(:remove_const, "Dummy") rescue nil Object.const_set("Dummy", Class.new(ActiveRecord::Base)) Dummy.class_eval do include Paperclip has_attached_file :avatar, options end end def build_delayed_jobs ActiveRecord::Base.connection.create_table :delayed_jobs, :force => true do |table| table.integer :priority, :default => 0 # Allows some jobs to jump to the front of the queue table.integer :attempts, :default => 0 # Provides for retries, but still fail eventually. table.text :handler # YAML-encoded string of the object that will do work table.string :last_error # reason for last failure (See Note below) table.datetime :run_at # When to run. Could be Time.now for immediately, or sometime in the future. table.datetime :locked_at # Set when a client is working on this object table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead) table.string :locked_by # Who is working on this object (if locked) table.timestamps end end