Permalink
Browse files

Added support for db:seed

  • Loading branch information...
1 parent 065f305 commit 27bde082309f398ddedf02948b1e9e101dec3558 @thuss thuss committed Feb 16, 2012
Showing with 26 additions and 3 deletions.
  1. +2 −1 README.markdown
  2. +5 −2 lib/tasks/standalone_migrations.rb
  3. +19 −0 spec/standalone_migrations_spec.rb
View
@@ -2,7 +2,7 @@ Rails migrations in non-Rails (and non Ruby) projects.
WHAT'S NEW
==========
-In the 1.0 release we have moved to using Rails 3 migrations instead of maintaining our own migration related code. Just about anything you can do with Rails 3 migrations you can now do with [Standalone Migrations](https://github.com/thuss/standalone-migrations) too! This removed 95% of the code we have to maintain. Big thanks to [Michael Grosser](http://pragmatig.wordpress.com) for undertaking this major rewrite!
+In the 1.0.x release we have moved to using Rails 3 migrations instead of maintaining our own migration related code. Just about anything you can do with Rails 3 migrations you can now do with [Standalone Migrations](https://github.com/thuss/standalone-migrations) too! This removed 95% of the code we have to maintain. Big thanks to [Michael Grosser](http://pragmatig.wordpress.com) for undertaking this major rewrite!
CONTRIBUTE
==========
@@ -213,5 +213,6 @@ Contributors
- [Robert J. Berger](http://blog.ibd.com/)
- [Federico Builes](http://mheroin.com/)
- [Ricardo Valeriano](http://ricardovaleriano.com/)
+ - [Gazler](http://blog.gazler.com/)
This work is originally based on [Lincoln Stoll's blog post](http://lstoll.net/2008/04/stand-alone-activerecord-migrations/) and [David Welton's post](http://journal.dedasys.com/2007/01/28/using-migrations-outside-of-rails).
@@ -41,8 +41,11 @@ def s.database_configuration
end
s
end
-
- def s.load_seed; end # no-op, needed for db:reset
+
+ def s.load_seed
+ seed_file = paths["db/seeds.rb"].select{ |f| File.exists?(f) }.first
+ load(seed_file) if seed_file
+ end
s
end
@@ -253,6 +253,25 @@ def self.down
run('rake db:test:purge')
end
end
+
+ describe "db:seed" do
+ it "loads" do
+ write("db/seeds.rb", "puts 'LOADEDDD'")
+ run("rake db:seed").should =~ /LOADEDDD/
+ end
+
+ it "does nothing without seeds" do
+ run("rake db:seed").length.should == 0
+ end
+ end
+
+ describe "db:reset" do
+ it "should not error when a seeds file does not exist" do
+ make_migration('yyy')
+ run('rake db:migrate DB=test')
+ run("rake db:reset").should_not raise_error(/rake aborted/)
+ end
+ end
describe 'db:migrate when environment is specified' do
it "runs when using the DB environment variable" do

0 comments on commit 27bde08

Please sign in to comment.