Initial work for re-packaging as gem.

This commit is contained in:
Victor Costan 2010-07-06 12:40:02 -04:00 committed by Zach Dennis
parent 3820a5cdb6
commit 42175ca94a
6 changed files with 109 additions and 26 deletions

21
.gitignore vendored
View file

@ -1,2 +1,23 @@
## MAC OS
.DS_Store
## TEXTMATE
*.tmproj
tmtags
## EMACS
*~
\#*
.\#*
## VIM
*.swp
## PROJECT::GENERAL
coverage
rdoc
pkg
## PROJECT::SPECIFIC
log/*.log log/*.log
test.db test.db

18
Gemfile
View file

@ -1,5 +1,17 @@
source :gemcutter source :gemcutter
gem "rails", "= 3.0.0rc" gem "rails", ">= 3.0.0.rc"
gem "factory_girl", "= 1.3.2"
gem "delorean", :version => "= 0.2.0" group :test do
# Database Adapters
gem "mysql", ">= 2.8.1"
gem "pg", ">= 0.9.0"
gem "sqlite3-ruby", ">= 1.3.1"
# Support libs
gem "factory_girl", ">= 1.3.2"
gem "delorean", ">= 0.2.0"
# Debugging
gem "ruby-debug", ">= 0.9.3"
end

View file

@ -1,8 +1,26 @@
require 'rubygems'
require 'rake'
require 'rake/testtask' require 'rake/testtask'
task :default => ["display:notice"] begin
require 'jeweler'
require 'bundler'
Jeweler::Tasks.new do |gem|
gem.name = "activerecord-import"
gem.summary = %Q{Bulk-loading extension for ActiveRecord}
gem.description = %Q{Extraction of the ActiveRecord::Base#import functionality from ar-extensions for Rails 3 and beyond}
gem.email = "zach.dennis@gmail.com"
gem.homepage = "http://github.com/zdennis/activerecord-import"
gem.authors = ["Zach Dennis"]
gem.files = FileList["VERSION", "Rakefile", "README*", "lib/**/*"]
gem.add_bundler_dependencies
ADAPTERS = %w(mysql postgresql sqlite3) # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
end
namespace :display do namespace :display do
task :notice do task :notice do
@ -11,12 +29,38 @@ namespace :display do
puts puts
end end
end end
task :default => ["display:notice"]
ADAPTERS = %w(mysql postgresql sqlite3)
ADAPTERS.each do |adapter| ADAPTERS.each do |adapter|
namespace :test do namespace :test do
desc "Runs #{adapter} database tests." desc "Runs #{adapter} database tests."
Rake::TestTask.new(adapter) do |t| Rake::TestTask.new(adapter) do |t|
t.test_files = FileList["test/adapters/#{adapter}.rb", "test/*_test.rb", "test/#{adapter}/**/*_test.rb"] t.test_files = FileList["test/adapters/#{adapter}.rb", "test/*_test.rb", "test/#{adapter}/**/*_test.rb"]
end end
task adapter => :check_dependencies
end end
end end
begin
require 'rcov/rcovtask'
Rcov::RcovTask.new do |test|
test.libs << 'test'
test.pattern = "test/*_test.rb"
test.verbose = true
end
rescue LoadError
task :rcov do
abort "RCov is not available. In order to run rcov, you must: sudo gem install rcov"
end
end
require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "activerecord-import #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end

View file

@ -1,4 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/test_helper') require File.expand_path('../test_helper', __FILE__)
describe "#import" do describe "#import" do
it "should return the number of inserts performed" do it "should return the number of inserts performed" do

View file

@ -5,7 +5,7 @@ class ActiveSupport::TestCase
factory_girl_args = args.shift || {} factory_girl_args = args.shift || {}
if n if n
returning Array.new do |collection| Array.new.tap do |collection|
n.times.each { collection << Factory.build(factory.to_s.singularize.to_sym, factory_girl_args) } n.times.each { collection << Factory.build(factory.to_s.singularize.to_sym, factory_girl_args) }
end end
else else
@ -19,7 +19,7 @@ class ActiveSupport::TestCase
factory_girl_args = args.shift || {} factory_girl_args = args.shift || {}
if n if n
returning Array.new do |collection| Array.new.tap do |collection|
n.times.each { collection << Factory.create(factory.to_s.singularize.to_sym, factory_girl_args) } n.times.each { collection << Factory.create(factory.to_s.singularize.to_sym, factory_girl_args) }
end end
else else

View file

@ -1,14 +1,20 @@
ENV["RAILS_ENV"] = "test"
require 'pathname' require 'pathname'
this_dir = Pathname.new File.dirname(__FILE__) test_dir = Pathname.new File.dirname(__FILE__)
$LOAD_PATH << this_dir.join("../lib") $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require "fileutils"
require "rubygems"
ENV["RAILS_ENV"] = "test"
require "bundler"
Bundler.setup
gem "rails", "3.0.0.beta"
require "rails" require "rails"
require "rails/test_help" require "rails/test_help"
require "active_record/fixtures" require "active_record/fixtures"
require "active_support/test_case" require "active_support/test_case"
require 'active_support/core_ext/object/returning'
require "delorean" require "delorean"
@ -17,6 +23,13 @@ require "logger"
require "ruby-debug" require "ruby-debug"
# load test helpers
class MyApplication < Rails::Application ; end
adapter = ENV["ARE_DB"] || "sqlite3"
# load the library
require "activerecord-import/#{adapter}"
class ActiveSupport::TestCase class ActiveSupport::TestCase
include ActiveRecord::TestFixtures include ActiveRecord::TestFixtures
self.use_transactional_fixtures = true self.use_transactional_fixtures = true
@ -84,17 +97,10 @@ def describe(description, &blk)
ActiveSupport::TestCase.describe(description, true, &blk) ActiveSupport::TestCase.describe(description, true, &blk)
end end
# load test helpers FileUtils.mkdir_p'log'
require "rails"
class MyApplication < Rails::Application ; end
adapter = ENV["ARE_DB"] || "sqlite3"
# load the library
require "activerecord-import/#{adapter}"
ActiveRecord::Base.logger = Logger.new("log/test.log") ActiveRecord::Base.logger = Logger.new("log/test.log")
ActiveRecord::Base.logger.level = Logger::DEBUG ActiveRecord::Base.logger.level = Logger::DEBUG
ActiveRecord::Base.configurations["test"] = YAML.load(this_dir.join("database.yml").open)[adapter] ActiveRecord::Base.configurations["test"] = YAML.load(test_dir.join("database.yml").open)[adapter]
ActiveRecord::Base.establish_connection "test" ActiveRecord::Base.establish_connection "test"
ActiveSupport::Notifications.subscribe(/active_record.sql/) do |event, _, _, _, hsh| ActiveSupport::Notifications.subscribe(/active_record.sql/) do |event, _, _, _, hsh|
@ -105,9 +111,9 @@ require "factory_girl"
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each{ |file| require file } Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each{ |file| require file }
# Load base/generic schema # Load base/generic schema
require this_dir.join("schema/version") require test_dir.join("schema/version")
require this_dir.join("schema/generic_schema") require test_dir.join("schema/generic_schema")
adapter_schema = this_dir.join("schema/#{adapter}_schema.rb") adapter_schema = test_dir.join("schema/#{adapter}_schema.rb")
require adapter_schema if File.exists?(adapter_schema) require adapter_schema if File.exists?(adapter_schema)
Dir[File.dirname(__FILE__) + "/models/*.rb"].each{ |file| require file } Dir[File.dirname(__FILE__) + "/models/*.rb"].each{ |file| require file }