From 4151ec2ad21baa80a06e916861a4bd73ca1f9ea9 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Fri, 5 Nov 2010 16:48:17 +0000 Subject: [PATCH] Add a method for running the specs on different database adapters --- seed-fu.gemspec | 10 ++++------ spec/README | 16 ++++++++++++++++ spec/connections/mysql.rb | 5 +++++ spec/connections/postgresql.rb | 5 +++++ spec/connections/sqlite3.rb | 4 ++++ spec/spec_helper.rb | 20 ++++++++++---------- 6 files changed, 44 insertions(+), 16 deletions(-) create mode 100644 spec/README create mode 100644 spec/connections/mysql.rb create mode 100644 spec/connections/postgresql.rb create mode 100644 spec/connections/sqlite3.rb diff --git a/seed-fu.gemspec b/seed-fu.gemspec index 4109181..bf75819 100644 --- a/seed-fu.gemspec +++ b/seed-fu.gemspec @@ -15,13 +15,11 @@ Gem::Specification.new do |s| s.description = "Seed Fu is an attempt to once and for all solve the problem of inserting and maintaining seed data in a database. It uses a variety of techniques gathered from various places around the web and combines them to create what is hopefully the most robust seed data system around." s.add_dependency "activerecord", "~> 3.0.0" - s.add_development_dependency "rspec", "~> 2.0.0" - if RUBY_VERSION >= '1.9.1' - s.add_development_dependency "sqlite3" - else - s.add_development_dependency "sqlite3-ruby" - end + s.add_development_dependency "rspec", "~> 2.0.0" + s.add_development_dependency "pg" + s.add_development_dependency "mysql2" + s.add_development_dependency(RUBY_VERSION >= '1.9.1' ? "sqlite3" : "sqlite3-ruby") s.files = Dir.glob("{lib}/**/*") + %w(LICENSE README.md CHANGELOG.md) s.require_path = 'lib' diff --git a/spec/README b/spec/README new file mode 100644 index 0000000..843eeda --- /dev/null +++ b/spec/README @@ -0,0 +1,16 @@ +To run the specs: + + gem install bundler # If not already installed + bundle install # Install the dependencies + rspec spec/ # Run the specs + +By default an sqlite3 database is used. + +To test others: + + DB=mysql rspec spec/ + DB=postgresql rspec spec/ + +In each of these cases, you'll need to create a database named "spec_fu_test". + +The connection paramaters for each of these are specified in spec/connections/, which you can edit if necessary (for example to change the username/password). diff --git a/spec/connections/mysql.rb b/spec/connections/mysql.rb new file mode 100644 index 0000000..a034e5a --- /dev/null +++ b/spec/connections/mysql.rb @@ -0,0 +1,5 @@ +ActiveRecord::Base.establish_connection( + :adapter => "mysql2", + :database => "seed_fu_test", + :username => "root" +) diff --git a/spec/connections/postgresql.rb b/spec/connections/postgresql.rb new file mode 100644 index 0000000..7dd16b0 --- /dev/null +++ b/spec/connections/postgresql.rb @@ -0,0 +1,5 @@ +ActiveRecord::Base.establish_connection( + :adapter => "postgresql", + :database => "seed_fu_test", + :username => "postgres" +) diff --git a/spec/connections/sqlite3.rb b/spec/connections/sqlite3.rb new file mode 100644 index 0000000..6c64843 --- /dev/null +++ b/spec/connections/sqlite3.rb @@ -0,0 +1,4 @@ +ActiveRecord::Base.establish_connection( + :adapter => "sqlite3", + :database => File.dirname(__FILE__) + "/test.sqlite3" +) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cc29c2b..7251d57 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,19 +3,13 @@ require 'seed-fu' require 'logger' -RSpec.configure do |config| - config.before do - SeededModel.delete_all - end -end - SeedFu.quiet = true ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/../debug.log") -ActiveRecord::Base.establish_connection( - :adapter => "sqlite3", - :database => File.dirname(__FILE__) + "/test.sqlite3" -) + +ENV["DB"] ||= 'sqlite3' +puts "Using #{ENV["DB"]} to run the tests." +require File.dirname(__FILE__) + "/connections/#{ENV["DB"]}.rb" ActiveRecord::Schema.define :version => 0 do create_table :seeded_models, :force => true do |t| @@ -30,3 +24,9 @@ class SeededModel < ActiveRecord::Base validates_presence_of :title attr_protected :first_name end + +RSpec.configure do |config| + config.before do + SeededModel.delete_all + end +end