Permalink
Browse files

Added guard clauses for in_memory and yaml adapters

* While yaml has some limited support for migrations, it is not complete
  and in_memory has none. Future updates may include methods for
  these adapters, but for now migrations should be considered
  unsupported for these adapters.
  • Loading branch information...
dkubb committed May 18, 2010
1 parent 3226862 commit 0a74902d0ddf2ef898366f271d258340a9cda917
@@ -2,87 +2,88 @@
describe 'The migration runner' do
- before(:all) do
- @adapter = DataMapper::Spec.adapter
- @repository = DataMapper.repository(@adapter.name)
- end
-
- describe 'empty migration runner' do
- it "should return an empty array if no migrations have been defined" do
- migrations.should be_kind_of(Array)
- migrations.should have(0).item
- end
- end
+ supported_by :postgres, :mysql, :sqlite, :oracle, :sqlserver do
- describe 'migration runnner' do
- # set up some 'global' setup and teardown tasks
- before(:each) do
- # FIXME workaround because dm-migrations can only handle the :default repo
- #DataMapper::Repository.adapters[:default] = DataMapper::Repository.adapters[adapter.to_sym]
- migration( 1, :create_people_table) { }
+ before(:all) do
+ @adapter = DataMapper::Spec.adapter
+ @repository = DataMapper.repository(@adapter.name)
end
- after(:each) do
- migrations.clear
- end
-
- describe '#migration' do
-
- it 'should create a new migration object, and add it to the list of migrations' do
+ describe 'empty migration runner' do
+ it "should return an empty array if no migrations have been defined" do
migrations.should be_kind_of(Array)
- migrations.should have(1).item
- migrations.first.name.should == "create_people_table"
+ migrations.should have(0).item
end
+ end
- it 'should allow multiple migrations to be added' do
- migration( 2, :add_dob_to_people) { }
- migration( 2, :add_favorite_pet_to_people) { }
- migration( 3, :add_something_else_to_people) { }
- migrations.should have(4).items
+ describe 'migration runnner' do
+ # set up some 'global' setup and teardown tasks
+ before(:each) do
+ # FIXME workaround because dm-migrations can only handle the :default repo
+ #DataMapper::Repository.adapters[:default] = DataMapper::Repository.adapters[adapter.to_sym]
+ migration( 1, :create_people_table) { }
end
- it 'should raise an error on adding with a duplicated name' do
- lambda { migration( 1, :create_people_table) { } }.should raise_error(RuntimeError, /Migration name conflict/)
+ after(:each) do
+ migrations.clear
end
- end
+ describe '#migration' do
- describe '#migrate_up! and #migrate_down!' do
- before(:each) do
- migration( 2, :add_dob_to_people) { }
- migration( 2, :add_favorite_pet_to_people) { }
- migration( 3, :add_something_else_to_people) { }
- end
+ it 'should create a new migration object, and add it to the list of migrations' do
+ migrations.should be_kind_of(Array)
+ migrations.should have(1).item
+ migrations.first.name.should == "create_people_table"
+ end
- it 'calling migrate_up! should migrate up all the migrations' do
- # add our expectation that migrate_up should be called
- migrations.each do |m|
- m.should_receive(:perform_up)
+ it 'should allow multiple migrations to be added' do
+ migration( 2, :add_dob_to_people) { }
+ migration( 2, :add_favorite_pet_to_people) { }
+ migration( 3, :add_something_else_to_people) { }
+ migrations.should have(4).items
end
- migrate_up!
+
+ it 'should raise an error on adding with a duplicated name' do
+ lambda { migration( 1, :create_people_table) { } }.should raise_error(RuntimeError, /Migration name conflict/)
+ end
+
end
- it 'calling migrate_up! with an arguement should only migrate to that level' do
- migrations.each do |m|
- if m.position <= 2
+ describe '#migrate_up! and #migrate_down!' do
+ before(:each) do
+ migration( 2, :add_dob_to_people) { }
+ migration( 2, :add_favorite_pet_to_people) { }
+ migration( 3, :add_something_else_to_people) { }
+ end
+
+ it 'calling migrate_up! should migrate up all the migrations' do
+ # add our expectation that migrate_up should be called
+ migrations.each do |m|
m.should_receive(:perform_up)
- else
- m.should_not_receive(:perform_up)
end
+ migrate_up!
end
- migrate_up!(2)
- end
- it 'calling migrate_down! should migrate down all the migrations' do
- # add our expectation that migrate_up should be called
- migrations.each do |m|
- m.should_receive(:perform_down)
+ it 'calling migrate_up! with an arguement should only migrate to that level' do
+ migrations.each do |m|
+ if m.position <= 2
+ m.should_receive(:perform_up)
+ else
+ m.should_not_receive(:perform_up)
+ end
+ end
+ migrate_up!(2)
end
- migrate_down!
- end
+ it 'calling migrate_down! should migrate down all the migrations' do
+ # add our expectation that migrate_up should be called
+ migrations.each do |m|
+ m.should_receive(:perform_down)
+ end
+ migrate_down!
+ end
+
+ end
end
end
-
-
end
@@ -1,133 +1,138 @@
require 'spec_helper'
-
describe "A Migration" do
- describe DataMapper::Migration, 'interface' do
- before(:all) do
- @adapter = DataMapper::Spec.adapter
- end
+ supported_by :postgres, :mysql, :sqlite, :oracle, :sqlserver do
- before do
- @migration = DataMapper::Migration.new(1, :create_people_table, :verbose => false) { }
- end
+ describe DataMapper::Migration, 'interface' do
- it "should have a postition attribute" do
- @migration.should respond_to(:position)
- @migration.should respond_to(:position=)
- @migration.position.should == 1
- end
+ before(:all) do
+ @adapter = DataMapper::Spec.adapter
+ end
- it "should have a name attribute" do
- @migration.should respond_to(:name)
- @migration.should respond_to(:name=)
- @migration.name.should == :create_people_table
- end
+ before do
+ @migration = DataMapper::Migration.new(1, :create_people_table, :verbose => false) { }
+ end
- it "should have a :database option" do
- adapter = DataMapper::Spec.adapter(:alternate)
- m = DataMapper::Migration.new(2, :create_dogs_table, :database => :alternate) {}
- m.instance_variable_get(:@adapter).should == adapter
- end
+ it "should have a postition attribute" do
+ @migration.should respond_to(:position)
+ @migration.should respond_to(:position=)
+ @migration.position.should == 1
+ end
- it "should use the default database by default" do
- @migration.instance_variable_get(:@database).name.should == :default
- end
+ it "should have a name attribute" do
+ @migration.should respond_to(:name)
+ @migration.should respond_to(:name=)
+ @migration.name.should == :create_people_table
+ end
- it "should have a verbose option" do
- m = DataMapper::Migration.new(2, :create_dogs_table, :verbose => false) {}
- m.instance_variable_get(:@verbose).should == false
- end
+ it "should have a :database option" do
+ adapter = DataMapper::Spec.adapter(:alternate)
+ m = DataMapper::Migration.new(2, :create_dogs_table, :database => :alternate) {}
+ m.instance_variable_get(:@adapter).should == adapter
+ end
- it "should be verbose by default" do
- m = DataMapper::Migration.new(2, :create_dogs_table) {}
- m.instance_variable_get(:@verbose).should == true
- end
+ it "should use the default database by default" do
+ @migration.instance_variable_get(:@database).name.should == :default
+ end
- it "should be sortable, first by position, then name" do
- m1 = DataMapper::Migration.new(1, :create_people_table) {}
- m2 = DataMapper::Migration.new(2, :create_dogs_table) {}
- m3 = DataMapper::Migration.new(2, :create_cats_table) {}
- m4 = DataMapper::Migration.new(4, :create_birds_table) {}
+ it "should have a verbose option" do
+ m = DataMapper::Migration.new(2, :create_dogs_table, :verbose => false) {}
+ m.instance_variable_get(:@verbose).should == false
+ end
- [m1, m2, m3, m4].sort.should == [m1, m3, m2, m4]
- end
+ it "should be verbose by default" do
+ m = DataMapper::Migration.new(2, :create_dogs_table) {}
+ m.instance_variable_get(:@verbose).should == true
+ end
+
+ it "should be sortable, first by position, then name" do
+ m1 = DataMapper::Migration.new(1, :create_people_table) {}
+ m2 = DataMapper::Migration.new(2, :create_dogs_table) {}
+ m3 = DataMapper::Migration.new(2, :create_cats_table) {}
+ m4 = DataMapper::Migration.new(4, :create_birds_table) {}
- adapter = DataMapper::Spec.adapter_name
+ [m1, m2, m3, m4].sort.should == [m1, m3, m2, m4]
+ end
- expected_module_lambda = {
- :sqlite => lambda { SQL::Sqlite },
- :mysql => lambda { SQL::Mysql },
- :postgres => lambda { SQL::Postgres }
- }[adapter.to_sym]
+ adapter = DataMapper::Spec.adapter_name
- expected_module = expected_module_lambda ? expected_module_lambda.call : nil
+ expected_module_lambda = {
+ :sqlite => lambda { SQL::Sqlite },
+ :mysql => lambda { SQL::Mysql },
+ :postgres => lambda { SQL::Postgres }
+ }[adapter.to_sym]
- if expected_module
- it "should extend with #{expected_module} when adapter is #{adapter}" do
- migration = DataMapper::Migration.new(1, :"#{adapter}_adapter_test") { }
- (class << migration.adapter; self; end).included_modules.should include(expected_module)
+ expected_module = expected_module_lambda ? expected_module_lambda.call : nil
+
+ if expected_module
+ it "should extend with #{expected_module} when adapter is #{adapter}" do
+ migration = DataMapper::Migration.new(1, :"#{adapter}_adapter_test") { }
+ (class << migration.adapter; self; end).included_modules.should include(expected_module)
+ end
end
end
- end
- describe DataMapper::Migration, 'defining actions' do
- before do
- @migration = DataMapper::Migration.new(1, :create_people_table, :verbose => false) { }
- end
+ describe DataMapper::Migration, 'defining actions' do
+ before do
+ @migration = DataMapper::Migration.new(1, :create_people_table, :verbose => false) { }
+ end
- it "should have an #up method" do
- @migration.should respond_to(:up)
- end
+ it "should have an #up method" do
+ @migration.should respond_to(:up)
+ end
- it "should save the block passed into the #up method in @up_action" do
- action = lambda {}
- @migration.up(&action)
+ it "should save the block passed into the #up method in @up_action" do
+ action = lambda {}
+ @migration.up(&action)
- @migration.instance_variable_get(:@up_action).should == action
- end
+ @migration.instance_variable_get(:@up_action).should == action
+ end
- it "should have a #down method" do
- @migration.should respond_to(:down)
- end
+ it "should have a #down method" do
+ @migration.should respond_to(:down)
+ end
- it "should save the block passed into the #down method in @down_action" do
- action = lambda {}
- @migration.down(&action)
+ it "should save the block passed into the #down method in @down_action" do
+ action = lambda {}
+ @migration.down(&action)
- @migration.instance_variable_get(:@down_action).should == action
- end
+ @migration.instance_variable_get(:@down_action).should == action
+ end
- it "should make available an #execute method" do
- @migration.should respond_to(:execute)
+ it "should make available an #execute method" do
+ @migration.should respond_to(:execute)
+ end
+
+ it "should run the sql passed into the #execute method"
+ # TODO: Find out how to stub the DataMapper::database.execute method
end
- it "should run the sql passed into the #execute method"
- # TODO: Find out how to stub the DataMapper::database.execute method
- end
+ describe DataMapper::Migration, "output" do
+ before do
+ @migration = DataMapper::Migration.new(1, :create_people_table) { }
+ @migration.stub!(:write) # so that we don't actually write anything to the console!
+ end
- describe DataMapper::Migration, "output" do
- before do
- @migration = DataMapper::Migration.new(1, :create_people_table) { }
- @migration.stub!(:write) # so that we don't actually write anything to the console!
- end
+ it "should #say a string with an indent" do
+ @migration.should_receive(:write).with(" Foobar")
+ @migration.say("Foobar", 2)
+ end
- it "should #say a string with an indent" do
- @migration.should_receive(:write).with(" Foobar")
- @migration.say("Foobar", 2)
- end
+ it "should #say with a default indent of 4" do
+ @migration.should_receive(:write).with(" Foobar")
+ @migration.say("Foobar")
+ end
- it "should #say with a default indent of 4" do
- @migration.should_receive(:write).with(" Foobar")
- @migration.say("Foobar")
- end
+ it "should #say_with_time the running time of a block" do
+ @migration.should_receive(:write).with(/Block/)
+ @migration.should_receive(:write).with(/-> [\d]+/)
- it "should #say_with_time the running time of a block" do
- @migration.should_receive(:write).with(/Block/)
- @migration.should_receive(:write).with(/-> [\d]+/)
+ @migration.say_with_time("Block"){ }
+ end
- @migration.say_with_time("Block"){ }
end
end
+
end
Oops, something went wrong.

0 comments on commit 0a74902

Please sign in to comment.