Permalink
Browse files

Adding high level specs for common rake db tasks

  • Loading branch information...
1 parent dadec7d commit 417b810cea22e57a3c5249df8c86f260f3b40eee @anthonyalberto committed Feb 15, 2014
View
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- mysql_online_migrations (1.0.1)
+ mysql_online_migrations (1.0.2)
activerecord (>= 3.2.15)
activesupport (>= 3.2.15)
mysql2
@@ -0,0 +1,5 @@
+class CreateTestRake < ActiveRecord::Migration
+ def change
+ create_table :test_rake
+ end
+end
@@ -0,0 +1,38 @@
+require "spec_helper"
+
+describe "Migration Tasks" do
+ after(:each) do
+ @adapter_without_lock.drop_table :test_rake rescue nil
+ clear_version
+ end
+
+ context 'db:migrate' do
+ it "creates the expected column" do
+ @adapter_without_lock.tables.should_not include("test_rake")
+ ActiveRecord::Migrator.migrate("spec/fixtures/db/migrate")
+ @adapter_without_lock.tables.should include("test_rake")
+ end
+ end
+
+ context 'when rolling back' do
+ before(:each) do
+ @adapter_without_lock.create_table :test_rake
+ @adapter_without_lock.tables.should include("test_rake")
+ insert_version(20140108194650)
+ end
+
+ context 'db:rollback' do
+ it "drops the expected table" do
+ ActiveRecord::Migrator.rollback("spec/fixtures/db/migrate", 1)
+ @adapter_without_lock.tables.should_not include("test_rake")
+ end
+ end
+
+ context 'db:migrate:down' do
+ it "drops the expected table" do
+ ActiveRecord::Migrator.run(:down, "spec/fixtures/db/migrate", 20140108194650)
+ @adapter_without_lock.tables.should_not include("test_rake")
+ end
+ end
+ end
+end
View
@@ -101,6 +101,15 @@ def set_ar_setting(value)
def teardown
@adapter.drop_table :testing rescue nil
+ @adapter.drop_table :test_rake rescue nil
ActiveRecord::Base.primary_key_prefix_type = nil
end
+
+ def insert_version(version)
+ @adapter_without_lock.execute("INSERT into schema_migrations VALUES('#{version}')")
+ end
+
+ def clear_version
+ @adapter_without_lock.execute("TRUNCATE schema_migrations")
+ end
end

0 comments on commit 417b810

Please sign in to comment.