Skip to content
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...
1 parent 3226862 commit 0a74902d0ddf2ef898366f271d258340a9cda917 @dkubb dkubb committed May 18, 2010
View
121 spec/integration/migration_runner_spec.rb
@@ -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
View
195 spec/integration/migration_spec.rb
@@ -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
View
277 spec/integration/sql_spec.rb
@@ -2,186 +2,189 @@
describe "SQL generation" do
- describe DataMapper::Migration, "#create_table helper" do
- before :all do
+ supported_by :postgres, :mysql, :sqlite, :oracle, :sqlserver do
- @adapter = DataMapper::Spec.adapter
- @repository = DataMapper.repository(@adapter.name)
+ describe DataMapper::Migration, "#create_table helper" do
+ before :all do
- case DataMapper::Spec.adapter_name.to_sym
- when :sqlite then @adapter.extend(SQL::Sqlite)
- when :mysql then @adapter.extend(SQL::Mysql)
- when :postgres then @adapter.extend(SQL::Postgres)
- end
+ @adapter = DataMapper::Spec.adapter
+ @repository = DataMapper.repository(@adapter.name)
- end
+ case DataMapper::Spec.adapter_name.to_sym
+ when :sqlite then @adapter.extend(SQL::Sqlite)
+ when :mysql then @adapter.extend(SQL::Mysql)
+ when :postgres then @adapter.extend(SQL::Postgres)
+ end
- before do
- @creator = DataMapper::Migration::TableCreator.new(@adapter, :people) do
- column :id, DataMapper::Property::Serial
- column :name, 'VARCHAR(50)', :allow_nil => false
- column :long_string, String, :size => 200
end
- end
- it "should have a #create_table helper" do
- @migration = DataMapper::Migration.new(1, :create_people_table, :verbose => false) { }
- @migration.should respond_to(:create_table)
- end
-
- it "should have a table_name" do
- @creator.table_name.should == "people"
- end
+ before do
+ @creator = DataMapper::Migration::TableCreator.new(@adapter, :people) do
+ column :id, DataMapper::Property::Serial
+ column :name, 'VARCHAR(50)', :allow_nil => false
+ column :long_string, String, :size => 200
+ end
+ end
- it "should have an adapter" do
- @creator.instance_eval("@adapter").should == @adapter
- end
+ it "should have a #create_table helper" do
+ @migration = DataMapper::Migration.new(1, :create_people_table, :verbose => false) { }
+ @migration.should respond_to(:create_table)
+ end
- it "should have an options hash" do
- @creator.opts.should be_kind_of(Hash)
- @creator.opts.should == {}
- end
+ it "should have a table_name" do
+ @creator.table_name.should == "people"
+ end
- it "should have an array of columns" do
- @creator.instance_eval("@columns").should be_kind_of(Array)
- @creator.instance_eval("@columns").should have(3).items
- @creator.instance_eval("@columns").first.should be_kind_of(DataMapper::Migration::TableCreator::Column)
- end
+ it "should have an adapter" do
+ @creator.instance_eval("@adapter").should == @adapter
+ end
- it "should quote the table name for the adapter" do
- @creator.quoted_table_name.should == (DataMapper::Spec.adapter_name.to_sym == :mysql ? '`people`' : '"people"')
- end
+ it "should have an options hash" do
+ @creator.opts.should be_kind_of(Hash)
+ @creator.opts.should == {}
+ end
- it "should allow for custom options" do
- columns = @creator.instance_eval("@columns")
- col = columns.detect{|c| c.name == "long_string"}
- col.instance_eval("@type").should include("200")
- end
+ it "should have an array of columns" do
+ @creator.instance_eval("@columns").should be_kind_of(Array)
+ @creator.instance_eval("@columns").should have(3).items
+ @creator.instance_eval("@columns").first.should be_kind_of(DataMapper::Migration::TableCreator::Column)
+ end
- it "should generate a NOT NULL column when :allow_nil is false" do
- @creator.instance_eval("@columns")[1].type.should match(/NOT NULL/)
- end
+ it "should quote the table name for the adapter" do
+ @creator.quoted_table_name.should == (DataMapper::Spec.adapter_name.to_sym == :mysql ? '`people`' : '"people"')
+ end
- case DataMapper::Spec.adapter_name.to_sym
- when :mysql
- it "should create an InnoDB database for MySQL" do
- #can't get an exact == comparison here because character set and collation may differ per connection
- @creator.to_sql.should match(/^CREATE TABLE `people` \(`id` SERIAL PRIMARY KEY, `name` VARCHAR\(50\) NOT NULL, `long_string` VARCHAR\(200\)\) ENGINE = InnoDB CHARACTER SET \w+ COLLATE \w+\z/)
+ it "should allow for custom options" do
+ columns = @creator.instance_eval("@columns")
+ col = columns.detect{|c| c.name == "long_string"}
+ col.instance_eval("@type").should include("200")
end
- when :postgres
- it "should output a CREATE TABLE statement when sent #to_sql" do
- @creator.to_sql.should == %q{CREATE TABLE "people" ("id" SERIAL PRIMARY KEY, "name" VARCHAR(50) NOT NULL, "long_string" VARCHAR(200))}
+
+ it "should generate a NOT NULL column when :allow_nil is false" do
+ @creator.instance_eval("@columns")[1].type.should match(/NOT NULL/)
end
- when :sqlite3
- it "should output a CREATE TABLE statement when sent #to_sql" do
- @creator.to_sql.should == %q{CREATE TABLE "people" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" VARCHAR(50) NOT NULL, "long_string" VARCHAR(200))}
+
+ case DataMapper::Spec.adapter_name.to_sym
+ when :mysql
+ it "should create an InnoDB database for MySQL" do
+ #can't get an exact == comparison here because character set and collation may differ per connection
+ @creator.to_sql.should match(/^CREATE TABLE `people` \(`id` SERIAL PRIMARY KEY, `name` VARCHAR\(50\) NOT NULL, `long_string` VARCHAR\(200\)\) ENGINE = InnoDB CHARACTER SET \w+ COLLATE \w+\z/)
+ end
+ when :postgres
+ it "should output a CREATE TABLE statement when sent #to_sql" do
+ @creator.to_sql.should == %q{CREATE TABLE "people" ("id" SERIAL PRIMARY KEY, "name" VARCHAR(50) NOT NULL, "long_string" VARCHAR(200))}
+ end
+ when :sqlite3
+ it "should output a CREATE TABLE statement when sent #to_sql" do
+ @creator.to_sql.should == %q{CREATE TABLE "people" ("id" INTEGER PRIMARY KEY AUTOINCREMENT, "name" VARCHAR(50) NOT NULL, "long_string" VARCHAR(200))}
+ end
end
end
- end
- describe DataMapper::Migration, "#modify_table helper" do
- before do
- @migration = DataMapper::Migration.new(1, :create_people_table, :verbose => false) { }
- end
+ describe DataMapper::Migration, "#modify_table helper" do
+ before do
+ @migration = DataMapper::Migration.new(1, :create_people_table, :verbose => false) { }
+ end
+
+ it "should have a #modify_table helper" do
+ @migration.should respond_to(:modify_table)
+ end
- it "should have a #modify_table helper" do
- @migration.should respond_to(:modify_table)
end
- end
+ describe DataMapper::Migration, "other helpers" do
+ before do
+ @migration = DataMapper::Migration.new(1, :create_people_table, :verbose => false) { }
+ end
- describe DataMapper::Migration, "other helpers" do
- before do
- @migration = DataMapper::Migration.new(1, :create_people_table, :verbose => false) { }
- end
+ it "should have a #drop_table helper" do
+ @migration.should respond_to(:drop_table)
+ end
- it "should have a #drop_table helper" do
- @migration.should respond_to(:drop_table)
end
- end
+ describe DataMapper::Migration, "version tracking" do
+ before(:each) do
+ @migration = DataMapper::Migration.new(1, :create_people_table, :verbose => false) do
+ up { :ran_up }
+ down { :ran_down }
+ end
- describe DataMapper::Migration, "version tracking" do
- before(:each) do
- @migration = DataMapper::Migration.new(1, :create_people_table, :verbose => false) do
- up { :ran_up }
- down { :ran_down }
+ @migration.send(:create_migration_info_table_if_needed)
end
- @migration.send(:create_migration_info_table_if_needed)
- end
+ after(:each) { DataMapper::Spec.adapter.execute("DROP TABLE migration_info") rescue nil }
- after(:each) { DataMapper::Spec.adapter.execute("DROP TABLE migration_info") rescue nil }
+ def insert_migration_record
+ DataMapper::Spec.adapter.execute("INSERT INTO migration_info (migration_name) VALUES ('create_people_table')")
+ end
- def insert_migration_record
- DataMapper::Spec.adapter.execute("INSERT INTO migration_info (migration_name) VALUES ('create_people_table')")
- end
+ it "should know if the migration_info table exists" do
+ @migration.send(:migration_info_table_exists?).should be_true
+ end
- it "should know if the migration_info table exists" do
- @migration.send(:migration_info_table_exists?).should be_true
- end
+ it "should know if the migration_info table does not exist" do
+ DataMapper::Spec.adapter.execute("DROP TABLE migration_info") rescue nil
+ @migration.send(:migration_info_table_exists?).should be_false
+ end
- it "should know if the migration_info table does not exist" do
- DataMapper::Spec.adapter.execute("DROP TABLE migration_info") rescue nil
- @migration.send(:migration_info_table_exists?).should be_false
- end
+ it "should be able to find the migration_info record for itself" do
+ insert_migration_record
+ @migration.send(:migration_record).should_not be_empty
+ end
- it "should be able to find the migration_info record for itself" do
- insert_migration_record
- @migration.send(:migration_record).should_not be_empty
- end
+ it "should know if a migration needs_up?" do
+ @migration.send(:needs_up?).should be_true
+ insert_migration_record
+ @migration.send(:needs_up?).should be_false
+ end
- it "should know if a migration needs_up?" do
- @migration.send(:needs_up?).should be_true
- insert_migration_record
- @migration.send(:needs_up?).should be_false
- end
+ it "should know if a migration needs_down?" do
+ @migration.send(:needs_down?).should be_false
+ insert_migration_record
+ @migration.send(:needs_down?).should be_true
+ end
- it "should know if a migration needs_down?" do
- @migration.send(:needs_down?).should be_false
- insert_migration_record
- @migration.send(:needs_down?).should be_true
- end
+ it "should properly quote the migration_info table via the adapter for use in queries" do
+ @migration.send(:migration_info_table).should == @migration.quote_table_name("migration_info")
+ end
- it "should properly quote the migration_info table via the adapter for use in queries" do
- @migration.send(:migration_info_table).should == @migration.quote_table_name("migration_info")
- end
+ it "should properly quote the migration_info.migration_name column via the adapter for use in queries" do
+ @migration.send(:migration_name_column).should == @migration.quote_column_name("migration_name")
+ end
- it "should properly quote the migration_info.migration_name column via the adapter for use in queries" do
- @migration.send(:migration_name_column).should == @migration.quote_column_name("migration_name")
- end
+ it "should properly quote the migration's name for use in queries"
+ # TODO how to i call the adapter's #escape_sql method?
- it "should properly quote the migration's name for use in queries"
- # TODO how to i call the adapter's #escape_sql method?
+ it "should create the migration_info table if it doesn't exist" do
+ DataMapper::Spec.adapter.execute("DROP TABLE migration_info")
+ @migration.send(:migration_info_table_exists?).should be_false
+ @migration.send(:create_migration_info_table_if_needed)
+ @migration.send(:migration_info_table_exists?).should be_true
+ end
- it "should create the migration_info table if it doesn't exist" do
- DataMapper::Spec.adapter.execute("DROP TABLE migration_info")
- @migration.send(:migration_info_table_exists?).should be_false
- @migration.send(:create_migration_info_table_if_needed)
- @migration.send(:migration_info_table_exists?).should be_true
- end
+ it "should insert a record into the migration_info table on up" do
+ @migration.send(:migration_record).should be_empty
+ @migration.perform_up.should == :ran_up
+ @migration.send(:migration_record).should_not be_empty
+ end
- it "should insert a record into the migration_info table on up" do
- @migration.send(:migration_record).should be_empty
- @migration.perform_up.should == :ran_up
- @migration.send(:migration_record).should_not be_empty
- end
+ it "should remove a record from the migration_info table on down" do
+ insert_migration_record
+ @migration.send(:migration_record).should_not be_empty
+ @migration.perform_down.should == :ran_down
+ @migration.send(:migration_record).should be_empty
+ end
- it "should remove a record from the migration_info table on down" do
- insert_migration_record
- @migration.send(:migration_record).should_not be_empty
- @migration.perform_down.should == :ran_down
- @migration.send(:migration_record).should be_empty
- end
+ it "should not run the up action if the record exists in the table" do
+ insert_migration_record
+ @migration.perform_up.should_not == :ran_up
+ end
- it "should not run the up action if the record exists in the table" do
- insert_migration_record
- @migration.perform_up.should_not == :ran_up
- end
+ it "should not run the down action if the record does not exist in the table" do
+ @migration.perform_down.should_not == :ran_down
+ end
- it "should not run the down action if the record does not exist in the table" do
- @migration.perform_down.should_not == :ran_down
end
-
end
end
View
6 spec/isolated/require_after_setup_spec.rb
@@ -1,11 +1,13 @@
require 'spec'
require 'isolated/require_spec'
require 'dm-core/spec/setup'
+require 'dm-core/spec/lib/adapter_helpers'
# To really test this behavior, this spec needs to be run in isolation and not
# as part of the typical rake spec run, which requires dm-transactions upfront
describe "require 'dm-migrations' after calling DataMapper.setup" do
+ extend DataMapper::Spec::Adapters::Helpers
before(:all) do
@@ -21,6 +23,8 @@ class ::Person
end
- it_should_behave_like "require 'dm-migrations'"
+ supported_by :postgres, :mysql, :sqlite, :oracle, :sqlserver do
+ it_should_behave_like "require 'dm-migrations'"
+ end
end
View
6 spec/isolated/require_before_setup_spec.rb
@@ -1,11 +1,13 @@
require 'spec'
require 'isolated/require_spec'
require 'dm-core/spec/setup'
+require 'dm-core/spec/lib/adapter_helpers'
# To really test this behavior, this spec needs to be run in isolation and not
# as part of the typical rake spec run, which requires dm-transactions upfront
describe "require 'dm-migrations' before calling DataMapper.setup" do
+ extend DataMapper::Spec::Adapters::Helpers
before(:all) do
@@ -21,6 +23,8 @@ class ::Person
end
- it_should_behave_like "require 'dm-migrations'"
+ supported_by :postgres, :mysql, :sqlite, :oracle, :sqlserver do
+ it_should_behave_like "require 'dm-migrations'"
+ end
end
View
639 spec/unit/migration_spec.rb
@@ -1,443 +1,444 @@
require 'spec_helper'
describe 'Migration' do
-
- before do
- @adapter = mock('adapter', :class => DataMapper::Spec.adapter.class)
- @repo = mock('DataMapper.repository', :adapter => @adapter)
- DataMapper.stub!(:repository).and_return(@repo)
- @m = DataMapper::Migration.new(1, :do_nothing, {}) {}
- @m.stub!(:write) # silence any output
- end
-
- [:position, :name, :database, :adapter].each do |meth|
- it "should respond to ##{meth}" do
- @m.should respond_to(meth)
- end
- end
-
- describe 'initialization' do
- it 'should set @position from the given position' do
- @m.instance_variable_get(:@position).should == 1
- end
-
- it 'should set @name from the given name' do
- @m.instance_variable_get(:@name).should == :do_nothing
- end
-
- it 'should set @options from the options hash' do
- @m.instance_variable_get(:@options).should == {}
+ supported_by :postgres, :mysql, :sqlite do
+ before do
+ @adapter = mock('adapter', :class => DataMapper::Spec.adapter.class)
+ @repo = mock('DataMapper.repository', :adapter => @adapter)
+ DataMapper.stub!(:repository).and_return(@repo)
+ @m = DataMapper::Migration.new(1, :do_nothing, {}) {}
+ @m.stub!(:write) # silence any output
end
- it 'should set @database from the default repository if no :database option is given' do
- DataMapper.should_receive(:repository).with(:default).and_return(@repo)
- DataMapper::Migration.new(1, :do_nothing, {}) {}
+ [:position, :name, :database, :adapter].each do |meth|
+ it "should respond to ##{meth}" do
+ @m.should respond_to(meth)
+ end
end
- it 'should set @database to the repository specified with the :database option' do
- DataMapper.should_receive(:repository).with(:foobar).and_return(@repo)
- DataMapper::Migration.new(1, :do_nothing, :database => :foobar) {}
- end
+ describe 'initialization' do
+ it 'should set @position from the given position' do
+ @m.instance_variable_get(:@position).should == 1
+ end
- it 'should determine the class of the adapter to be extended' do
- @adapter.should_receive(:class).and_return(DataMapper::Spec.adapter.class)
- DataMapper::Migration.new(1, :do_nothing, {}) {}
- end
+ it 'should set @name from the given name' do
+ @m.instance_variable_get(:@name).should == :do_nothing
+ end
- it 'should extend the adapter with the right module' do
- @adapter.should_receive(:extend).with(SQL.const_get(DataMapper::Spec.adapter_name.capitalize))
- DataMapper::Migration.new(1, :do_nothing, {}) {}
- end
+ it 'should set @options from the options hash' do
+ @m.instance_variable_get(:@options).should == {}
+ end
- it 'should raise "Unsupported adapter" on an unknown adapter' do
- @adapter.should_receive(:class).any_number_of_times.and_return("InvalidAdapter")
- lambda {
+ it 'should set @database from the default repository if no :database option is given' do
+ DataMapper.should_receive(:repository).with(:default).and_return(@repo)
DataMapper::Migration.new(1, :do_nothing, {}) {}
- }.should raise_error
- end
-
- it 'should set @verbose from the options hash' do
- m = DataMapper::Migration.new(1, :do_nothing, :verbose => false) {}
- m.instance_variable_get(:@verbose).should be_false
- end
+ end
- it 'should set @verbose to true by default' do
- @m.instance_variable_get(:@verbose).should be_true
- end
+ it 'should set @database to the repository specified with the :database option' do
+ DataMapper.should_receive(:repository).with(:foobar).and_return(@repo)
+ DataMapper::Migration.new(1, :do_nothing, :database => :foobar) {}
+ end
- it 'should set the @up_action to an empty block' do
- @m.instance_variable_get(:@up_action).should be_kind_of(Proc)
- end
+ it 'should determine the class of the adapter to be extended' do
+ @adapter.should_receive(:class).and_return(DataMapper::Spec.adapter.class)
+ DataMapper::Migration.new(1, :do_nothing, {}) {}
+ end
- it 'should set the @down_action to an empty block' do
- @m.instance_variable_get(:@down_action).should be_kind_of(Proc)
- end
+ it 'should extend the adapter with the right module' do
+ @adapter.should_receive(:extend).with(SQL.const_get(DataMapper::Spec.adapter_name.capitalize))
+ DataMapper::Migration.new(1, :do_nothing, {}) {}
+ end
- it 'should evaluate the given block'
+ it 'should raise "Unsupported adapter" on an unknown adapter' do
+ @adapter.should_receive(:class).any_number_of_times.and_return("InvalidAdapter")
+ lambda {
+ DataMapper::Migration.new(1, :do_nothing, {}) {}
+ }.should raise_error
+ end
- end
+ it 'should set @verbose from the options hash' do
+ m = DataMapper::Migration.new(1, :do_nothing, :verbose => false) {}
+ m.instance_variable_get(:@verbose).should be_false
+ end
- it 'should set the @up_action when #up is called with a block' do
- action = lambda {}
- @m.up(&action)
- @m.instance_variable_get(:@up_action).should == action
- end
+ it 'should set @verbose to true by default' do
+ @m.instance_variable_get(:@verbose).should be_true
+ end
- it 'should set the @up_action when #up is called with a block' do
- action = lambda {}
- @m.down(&action)
- @m.instance_variable_get(:@down_action).should == action
- end
+ it 'should set the @up_action to an empty block' do
+ @m.instance_variable_get(:@up_action).should be_kind_of(Proc)
+ end
- describe 'perform_up' do
- before do
- @up_action = mock('proc', :call => true)
- @m.instance_variable_set(:@up_action, @up_action)
- @m.stub!(:needs_up?).and_return(true)
- @m.stub!(:update_migration_info)
- end
+ it 'should set the @down_action to an empty block' do
+ @m.instance_variable_get(:@down_action).should be_kind_of(Proc)
+ end
- it 'should call the action assigned to @up_action and return the result' do
- @up_action.should_receive(:call).and_return(:result)
- @m.perform_up.should == :result
- end
+ it 'should evaluate the given block'
- it 'should output a status message with the position and name of the migration' do
- @m.should_receive(:write).with(/Performing Up Migration #1: do_nothing/)
- @m.perform_up
end
- it 'should not run if it doesnt need to be' do
- @m.should_receive(:needs_up?).and_return(false)
- @up_action.should_not_receive(:call)
- @m.perform_up
+ it 'should set the @up_action when #up is called with a block' do
+ action = lambda {}
+ @m.up(&action)
+ @m.instance_variable_get(:@up_action).should == action
end
- it 'should update the migration info table' do
- @m.should_receive(:update_migration_info).with(:up)
- @m.perform_up
+ it 'should set the @up_action when #up is called with a block' do
+ action = lambda {}
+ @m.down(&action)
+ @m.instance_variable_get(:@down_action).should == action
end
- it 'should not update the migration info table if the migration does not need run' do
- @m.should_receive(:needs_up?).and_return(false)
- @m.should_not_receive(:update_migration_info)
- @m.perform_up
- end
+ describe 'perform_up' do
+ before do
+ @up_action = mock('proc', :call => true)
+ @m.instance_variable_set(:@up_action, @up_action)
+ @m.stub!(:needs_up?).and_return(true)
+ @m.stub!(:update_migration_info)
+ end
- end
+ it 'should call the action assigned to @up_action and return the result' do
+ @up_action.should_receive(:call).and_return(:result)
+ @m.perform_up.should == :result
+ end
- describe 'perform_down' do
- before do
- @down_action = mock('proc', :call => true)
- @m.instance_variable_set(:@down_action, @down_action)
- @m.stub!(:needs_down?).and_return(true)
- @m.stub!(:update_migration_info)
- end
+ it 'should output a status message with the position and name of the migration' do
+ @m.should_receive(:write).with(/Performing Up Migration #1: do_nothing/)
+ @m.perform_up
+ end
- it 'should call the action assigned to @down_action and return the result' do
- @down_action.should_receive(:call).and_return(:result)
- @m.perform_down.should == :result
- end
+ it 'should not run if it doesnt need to be' do
+ @m.should_receive(:needs_up?).and_return(false)
+ @up_action.should_not_receive(:call)
+ @m.perform_up
+ end
- it 'should output a status message with the position and name of the migration' do
- @m.should_receive(:write).with(/Performing Down Migration #1: do_nothing/)
- @m.perform_down
- end
+ it 'should update the migration info table' do
+ @m.should_receive(:update_migration_info).with(:up)
+ @m.perform_up
+ end
- it 'should not run if it doesnt need to be' do
- @m.should_receive(:needs_down?).and_return(false)
- @down_action.should_not_receive(:call)
- @m.perform_down
- end
+ it 'should not update the migration info table if the migration does not need run' do
+ @m.should_receive(:needs_up?).and_return(false)
+ @m.should_not_receive(:update_migration_info)
+ @m.perform_up
+ end
- it 'should update the migration info table' do
- @m.should_receive(:update_migration_info).with(:down)
- @m.perform_down
end
- it 'should not update the migration info table if the migration does not need run' do
- @m.should_receive(:needs_down?).and_return(false)
- @m.should_not_receive(:update_migration_info)
- @m.perform_down
- end
+ describe 'perform_down' do
+ before do
+ @down_action = mock('proc', :call => true)
+ @m.instance_variable_set(:@down_action, @down_action)
+ @m.stub!(:needs_down?).and_return(true)
+ @m.stub!(:update_migration_info)
+ end
- end
+ it 'should call the action assigned to @down_action and return the result' do
+ @down_action.should_receive(:call).and_return(:result)
+ @m.perform_down.should == :result
+ end
- describe 'methods used in the action blocks' do
+ it 'should output a status message with the position and name of the migration' do
+ @m.should_receive(:write).with(/Performing Down Migration #1: do_nothing/)
+ @m.perform_down
+ end
- describe '#execute' do
- before do
- @adapter.stub!(:execute)
+ it 'should not run if it doesnt need to be' do
+ @m.should_receive(:needs_down?).and_return(false)
+ @down_action.should_not_receive(:call)
+ @m.perform_down
end
- it 'should send the SQL it its executing to the adapter execute method' do
- @adapter.should_receive(:execute).with('SELECT SOME SQL')
- @m.execute('SELECT SOME SQL')
+ it 'should update the migration info table' do
+ @m.should_receive(:update_migration_info).with(:down)
+ @m.perform_down
end
- it 'should output the SQL it is executing' do
- @m.should_receive(:write).with(/SELECT SOME SQL/)
- @m.execute('SELECT SOME SQL')
+ it 'should not update the migration info table if the migration does not need run' do
+ @m.should_receive(:needs_down?).and_return(false)
+ @m.should_not_receive(:update_migration_info)
+ @m.perform_down
end
+
end
- describe 'helpers' do
- before do
- @m.stub!(:execute) # don't actually run anything
- end
+ describe 'methods used in the action blocks' do
- describe '#create_table' do
+ describe '#execute' do
before do
- @tc = mock('TableCreator', :to_sql => 'CREATE TABLE')
- SQL::TableCreator.stub!(:new).and_return(@tc)
+ @adapter.stub!(:execute)
end
- it 'should create a new TableCreator object' do
- SQL::TableCreator.should_receive(:new).with(@adapter, :users, {}).and_return(@tc)
- @m.create_table(:users) { }
+ it 'should send the SQL it its executing to the adapter execute method' do
+ @adapter.should_receive(:execute).with('SELECT SOME SQL')
+ @m.execute('SELECT SOME SQL')
end
- it 'should convert the TableCreator object to an sql statement' do
- @tc.should_receive(:to_sql).and_return('CREATE TABLE')
- @m.create_table(:users) { }
+ it 'should output the SQL it is executing' do
+ @m.should_receive(:write).with(/SELECT SOME SQL/)
+ @m.execute('SELECT SOME SQL')
end
+ end
- it 'should execute the create table sql' do
- @m.should_receive(:execute).with('CREATE TABLE')
- @m.create_table(:users) { }
+ describe 'helpers' do
+ before do
+ @m.stub!(:execute) # don't actually run anything
end
- end
+ describe '#create_table' do
+ before do
+ @tc = mock('TableCreator', :to_sql => 'CREATE TABLE')
+ SQL::TableCreator.stub!(:new).and_return(@tc)
+ end
- describe '#drop_table' do
- it 'should quote the table name' do
- @adapter.should_receive(:quote_name).with('users')
- @m.drop_table :users
- end
+ it 'should create a new TableCreator object' do
+ SQL::TableCreator.should_receive(:new).with(@adapter, :users, {}).and_return(@tc)
+ @m.create_table(:users) { }
+ end
- it 'should execute the DROP TABLE sql for the table' do
- @adapter.stub!(:quote_name).and_return("'users'")
- @m.should_receive(:execute).with(%{DROP TABLE 'users'})
- @m.drop_table :users
- end
+ it 'should convert the TableCreator object to an sql statement' do
+ @tc.should_receive(:to_sql).and_return('CREATE TABLE')
+ @m.create_table(:users) { }
+ end
- end
+ it 'should execute the create table sql' do
+ @m.should_receive(:execute).with('CREATE TABLE')
+ @m.create_table(:users) { }
+ end
- describe '#modify_table' do
- before do
- @tm = mock('TableModifier', :statements => [])
- SQL::TableModifier.stub!(:new).and_return(@tm)
end
- it 'should create a new TableModifier object' do
- SQL::TableModifier.should_receive(:new).with(@adapter, :users, {}).and_return(@tm)
- @m.modify_table(:users){ }
- end
+ describe '#drop_table' do
+ it 'should quote the table name' do
+ @adapter.should_receive(:quote_name).with('users')
+ @m.drop_table :users
+ end
- it 'should get the statements from the TableModifier object' do
- @tm.should_receive(:statements).and_return([])
- @m.modify_table(:users){ }
- end
+ it 'should execute the DROP TABLE sql for the table' do
+ @adapter.stub!(:quote_name).and_return("'users'")
+ @m.should_receive(:execute).with(%{DROP TABLE 'users'})
+ @m.drop_table :users
+ end
- it 'should iterate over the statements and execute each one' do
- @tm.should_receive(:statements).and_return(['SELECT 1', 'SELECT 2'])
- @m.should_receive(:execute).with('SELECT 1')
- @m.should_receive(:execute).with('SELECT 2')
- @m.modify_table(:users){ }
end
- end
+ describe '#modify_table' do
+ before do
+ @tm = mock('TableModifier', :statements => [])
+ SQL::TableModifier.stub!(:new).and_return(@tm)
+ end
- describe 'sorting' do
- it 'should order things by position' do
- m1 = DataMapper::Migration.new(1, :do_nothing){}
- m2 = DataMapper::Migration.new(2, :do_nothing_else){}
+ it 'should create a new TableModifier object' do
+ SQL::TableModifier.should_receive(:new).with(@adapter, :users, {}).and_return(@tm)
+ @m.modify_table(:users){ }
+ end
- (m1 <=> m2).should == -1
- end
+ it 'should get the statements from the TableModifier object' do
+ @tm.should_receive(:statements).and_return([])
+ @m.modify_table(:users){ }
+ end
- it 'should order things by name when they have the same position' do
- m1 = DataMapper::Migration.new(1, :do_nothing_a){}
- m2 = DataMapper::Migration.new(1, :do_nothing_b){}
+ it 'should iterate over the statements and execute each one' do
+ @tm.should_receive(:statements).and_return(['SELECT 1', 'SELECT 2'])
+ @m.should_receive(:execute).with('SELECT 1')
+ @m.should_receive(:execute).with('SELECT 2')
+ @m.modify_table(:users){ }
+ end
- (m1 <=> m2).should == -1
end
- end
+ describe 'sorting' do
+ it 'should order things by position' do
+ m1 = DataMapper::Migration.new(1, :do_nothing){}
+ m2 = DataMapper::Migration.new(2, :do_nothing_else){}
- describe 'formatting output' do
- describe '#say' do
- it 'should output the message' do
- @m.should_receive(:write).with(/Paul/)
- @m.say("Paul")
+ (m1 <=> m2).should == -1
end
- it 'should indent the message with 4 spaces by default' do
- @m.should_receive(:write).with(/^\s{4}/)
- @m.say("Paul")
- end
+ it 'should order things by name when they have the same position' do
+ m1 = DataMapper::Migration.new(1, :do_nothing_a){}
+ m2 = DataMapper::Migration.new(1, :do_nothing_b){}
- it 'should indext the message with a given number of spaces' do
- @m.should_receive(:write).with(/^\s{3}/)
- @m.say("Paul", 3)
+ (m1 <=> m2).should == -1
end
+
end
- describe '#say_with_time' do
- before do
- @m.stub!(:say)
+ describe 'formatting output' do
+ describe '#say' do
+ it 'should output the message' do
+ @m.should_receive(:write).with(/Paul/)
+ @m.say("Paul")
+ end
+
+ it 'should indent the message with 4 spaces by default' do
+ @m.should_receive(:write).with(/^\s{4}/)
+ @m.say("Paul")
+ end
+
+ it 'should indext the message with a given number of spaces' do
+ @m.should_receive(:write).with(/^\s{3}/)
+ @m.say("Paul", 3)
+ end
end
- it 'should say the message with an indent of 2' do
- @m.should_receive(:say).with("Paul", 2)
- @m.say_with_time("Paul"){}
- end
+ describe '#say_with_time' do
+ before do
+ @m.stub!(:say)
+ end
- it 'should output the time it took' do
- @m.should_receive(:say).with(/\d+/, 2)
- @m.say_with_time("Paul"){}
- end
- end
+ it 'should say the message with an indent of 2' do
+ @m.should_receive(:say).with("Paul", 2)
+ @m.say_with_time("Paul"){}
+ end
- describe '#write' do
- before do
- # need a new migration object, because the main one had #write stubbed to silence output
- @m = DataMapper::Migration.new(1, :do_nothing) {}
+ it 'should output the time it took' do
+ @m.should_receive(:say).with(/\d+/, 2)
+ @m.say_with_time("Paul"){}
+ end
end
- it 'should puts the message' do
- @m.should_receive(:puts).with("Paul")
- @m.write("Paul")
- end
+ describe '#write' do
+ before do
+ # need a new migration object, because the main one had #write stubbed to silence output
+ @m = DataMapper::Migration.new(1, :do_nothing) {}
+ end
- it 'should not puts the message if @verbose is false' do
- @m.instance_variable_set(:@verbose, false)
- @m.should_not_receive(:puts)
- @m.write("Paul")
- end
+ it 'should puts the message' do
+ @m.should_receive(:puts).with("Paul")
+ @m.write("Paul")
+ end
- end
+ it 'should not puts the message if @verbose is false' do
+ @m.instance_variable_set(:@verbose, false)
+ @m.should_not_receive(:puts)
+ @m.write("Paul")
+ end
- end
+ end
- describe 'working with the migration_info table' do
- before do
- @adapter.stub!(:storage_exists?).and_return(true)
- # --- Please remove stubs ---
- @adapter.stub!(:quote_name).and_return { |name| "'#{name}'" }
end
- describe '#update_migration_info' do
- it 'should add a record of the migration' do
- @m.should_receive(:execute).with(
- %Q{INSERT INTO 'migration_info' ('migration_name') VALUES ('do_nothing')}
- )
- @m.update_migration_info(:up)
+ describe 'working with the migration_info table' do
+ before do
+ @adapter.stub!(:storage_exists?).and_return(true)
+ # --- Please remove stubs ---
+ @adapter.stub!(:quote_name).and_return { |name| "'#{name}'" }
end
- it 'should remove the record of the migration' do
- @m.should_receive(:execute).with(
- %Q{DELETE FROM 'migration_info' WHERE 'migration_name' = 'do_nothing'}
- )
- @m.update_migration_info(:down)
+ describe '#update_migration_info' do
+ it 'should add a record of the migration' do
+ @m.should_receive(:execute).with(
+ %Q{INSERT INTO 'migration_info' ('migration_name') VALUES ('do_nothing')}
+ )
+ @m.update_migration_info(:up)
+ end
+
+ it 'should remove the record of the migration' do
+ @m.should_receive(:execute).with(
+ %Q{DELETE FROM 'migration_info' WHERE 'migration_name' = 'do_nothing'}
+ )
+ @m.update_migration_info(:down)
+ end
+
+ it 'should try to create the migration_info table' do
+ @m.should_receive(:create_migration_info_table_if_needed)
+ @m.update_migration_info(:up)
+ end
end
- it 'should try to create the migration_info table' do
- @m.should_receive(:create_migration_info_table_if_needed)
- @m.update_migration_info(:up)
+ describe '#create_migration_info_table_if_needed' do
+ it 'should create the migration info table' do
+ @m.should_receive(:migration_info_table_exists?).and_return(false)
+ @m.should_receive(:execute).with(
+ %Q{CREATE TABLE 'migration_info' ('migration_name' VARCHAR(255) UNIQUE)}
+ )
+ @m.create_migration_info_table_if_needed
+ end
+
+ it 'should not try to create the migration info table if it already exists' do
+ @m.should_receive(:migration_info_table_exists?).and_return(true)
+ @m.should_not_receive(:execute)
+ @m.create_migration_info_table_if_needed
+ end
end
- end
- describe '#create_migration_info_table_if_needed' do
- it 'should create the migration info table' do
- @m.should_receive(:migration_info_table_exists?).and_return(false)
- @m.should_receive(:execute).with(
- %Q{CREATE TABLE 'migration_info' ('migration_name' VARCHAR(255) UNIQUE)}
- )
- @m.create_migration_info_table_if_needed
+ it 'should quote the name of the migration for use in sql' do
+ @m.quoted_name.should == %{'do_nothing'}
end
- it 'should not try to create the migration info table if it already exists' do
- @m.should_receive(:migration_info_table_exists?).and_return(true)
- @m.should_not_receive(:execute)
- @m.create_migration_info_table_if_needed
+ it 'should query the adapter to see if the migration_info table exists' do
+ @adapter.should_receive(:storage_exists?).with('migration_info').and_return(true)
+ @m.migration_info_table_exists?.should == true
end
- end
- it 'should quote the name of the migration for use in sql' do
- @m.quoted_name.should == %{'do_nothing'}
- end
+ describe '#migration_record' do
+ it 'should query for the migration' do
+ @adapter.should_receive(:select).with(
+ %Q{SELECT 'migration_name' FROM 'migration_info' WHERE 'migration_name' = 'do_nothing'}
+ )
+ @m.migration_record
+ end
- it 'should query the adapter to see if the migration_info table exists' do
- @adapter.should_receive(:storage_exists?).with('migration_info').and_return(true)
- @m.migration_info_table_exists?.should == true
- end
+ it 'should not try to query if the table does not exist' do
+ @m.stub!(:migration_info_table_exists?).and_return(false)
+ @adapter.should_not_receive(:select)
+ @m.migration_record
+ end
- describe '#migration_record' do
- it 'should query for the migration' do
- @adapter.should_receive(:select).with(
- %Q{SELECT 'migration_name' FROM 'migration_info' WHERE 'migration_name' = 'do_nothing'}
- )
- @m.migration_record
end
- it 'should not try to query if the table does not exist' do
- @m.stub!(:migration_info_table_exists?).and_return(false)
- @adapter.should_not_receive(:select)
- @m.migration_record
- end
+ describe '#needs_up?' do
+ it 'should be true if there is no record' do
+ @m.should_receive(:migration_record).and_return([])
+ @m.needs_up?.should == true
+ end
- end
+ it 'should be false if the record exists' do
+ @m.should_receive(:migration_record).and_return([:not_empty])
+ @m.needs_up?.should == false
+ end
- describe '#needs_up?' do
- it 'should be true if there is no record' do
- @m.should_receive(:migration_record).and_return([])
- @m.needs_up?.should == true
- end
+ it 'should be true if there is no migration_info table' do
+ @m.should_receive(:migration_info_table_exists?).and_return(false)
+ @m.needs_up?.should == true
+ end
- it 'should be false if the record exists' do
- @m.should_receive(:migration_record).and_return([:not_empty])
- @m.needs_up?.should == false
end
- it 'should be true if there is no migration_info table' do
- @m.should_receive(:migration_info_table_exists?).and_return(false)
- @m.needs_up?.should == true
- end
+ describe '#needs_down?' do
+ it 'should be false if there is no record' do
+ @m.should_receive(:migration_record).and_return([])
+ @m.needs_down?.should == false
+ end
- end
+ it 'should be true if the record exists' do
+ @m.should_receive(:migration_record).and_return([:not_empty])
+ @m.needs_down?.should == true
+ end
- describe '#needs_down?' do
- it 'should be false if there is no record' do
- @m.should_receive(:migration_record).and_return([])
- @m.needs_down?.should == false
- end
+ it 'should be false if there is no migration_info table' do
+ @m.should_receive(:migration_info_table_exists?).and_return(false)
+ @m.needs_down?.should == false
+ end
- it 'should be true if the record exists' do
- @m.should_receive(:migration_record).and_return([:not_empty])
- @m.needs_down?.should == true
end
- it 'should be false if there is no migration_info table' do
- @m.should_receive(:migration_info_table_exists?).and_return(false)
- @m.needs_down?.should == false
+ it 'should have the adapter quote the migration_info table' do
+ @adapter.should_receive(:quote_name).with('migration_info').and_return("'migration_info'")
+ @m.migration_info_table.should == "'migration_info'"
end
- end
-
- it 'should have the adapter quote the migration_info table' do
- @adapter.should_receive(:quote_name).with('migration_info').and_return("'migration_info'")
- @m.migration_info_table.should == "'migration_info'"
- end
+ it 'should have a quoted migration_name_column' do
+ @adapter.should_receive(:quote_name).with('migration_name').and_return("'migration_name'")
+ @m.migration_name_column.should == "'migration_name'"
+ end
- it 'should have a quoted migration_name_column' do
- @adapter.should_receive(:quote_name).with('migration_name').and_return("'migration_name'")
- @m.migration_name_column.should == "'migration_name'"
end
end
end
-
end
end

0 comments on commit 0a74902

Please sign in to comment.
Something went wrong with that request. Please try again.