test/mongrations_test.rb in leifcr-mongrations-0.1.6 vs test/mongrations_test.rb in leifcr-mongrations-0.1.7

- old
+ new

@@ -1,8 +1,61 @@ require 'test_helper' class MongrationsTest < ActiveSupport::TestCase - # Replace this with your real tests. - test "the truth" do - assert true + context "A valid MongoMapper connection" do + setup do + @path = File.join("test", "mongrations") + @version = "20101125020919" + end + + context "with a valid database" do + context "with a pending migration" do + should "migrate up to a given version" do + Widget.create(:name => "Sparkling Wizzles", :price => 100) + Widget.first.price.should == 100 + Mongrations::Migrator.run(:up, @path, @version) + Widget.first.price.should == 200 + end + + should "run all pending migrations" do + + Widget.create(:name => "Sparkling Wizzles", :price => 100) + Widget.first.price.should == 100 + Mongrations::Migrator.migrate(@path, nil) + Widget.first.price.should == 200 + end + end + + should "run a migration:down" do + Widget.create(:name => "Sparkling Wizzles", :price => 100) + Widget.first.price.should == 100 + Mongrations::Migrator.migrate(@path, nil) + Widget.first.price.should == 200 + Mongrations::Migrator.run(:down, @path, @version) + Widget.first.price.should == 100 + end + + should "run a migration rollback" do + Widget.create(:name => "Sparkling Wizzles", :price => 100) + Widget.first.price.should == 100 + Mongrations::Migrator.migrate(@path, nil) + Widget.first.price.should == 200 + Mongrations::Migrator.rollback(@path, 1) + Widget.first.price.should == 100 + end + + should "not run a migration more than once" do + Widget.create(:name => "Sparkling Wizzles", :price => 100) + Widget.first.price.should == 100 + Mongrations::Migrator.migrate(@path, nil) + Widget.first.price.should == 200 + Mongrations::Migrator.migrate(@path, nil) + Widget.first.price.should == 200 + end + end + + teardown do + # Not gonna remove it. For now. + # MongoMapper.connection.drop_database "mongrations_test" + end end -end +end \ No newline at end of file