Skip to content

Commit

Permalink
Add a method for running the specs on different database adapters
Browse files Browse the repository at this point in the history
  • Loading branch information
jonleighton committed Nov 5, 2010
1 parent 70dacc6 commit 4151ec2
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 16 deletions.
10 changes: 4 additions & 6 deletions seed-fu.gemspec
Expand Up @@ -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'
Expand Down
16 changes: 16 additions & 0 deletions 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).
5 changes: 5 additions & 0 deletions spec/connections/mysql.rb
@@ -0,0 +1,5 @@
ActiveRecord::Base.establish_connection(
:adapter => "mysql2",
:database => "seed_fu_test",
:username => "root"
)
5 changes: 5 additions & 0 deletions spec/connections/postgresql.rb
@@ -0,0 +1,5 @@
ActiveRecord::Base.establish_connection(
:adapter => "postgresql",
:database => "seed_fu_test",
:username => "postgres"
)
4 changes: 4 additions & 0 deletions spec/connections/sqlite3.rb
@@ -0,0 +1,4 @@
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => File.dirname(__FILE__) + "/test.sqlite3"
)
20 changes: 10 additions & 10 deletions spec/spec_helper.rb
Expand Up @@ -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|
Expand All @@ -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

0 comments on commit 4151ec2

Please sign in to comment.