Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use DataMapper::Spec.setup for running specs

  • Loading branch information...
commit 0b75f165bf4c06a75f10dd5ce588f5aa736b60d4 1 parent 98fd688
@snusnu snusnu authored
View
5 dm-migrations.gemspec
@@ -42,6 +42,7 @@ Gem::Specification.new do |s|
"lib/dm-migrations/sql.rb",
"lib/dm-migrations/sql/column.rb",
"lib/dm-migrations/sql/mysql.rb",
+ "lib/dm-migrations/sql/postgres.rb",
"lib/dm-migrations/sql/sqlite.rb",
"lib/dm-migrations/sql/table.rb",
"lib/dm-migrations/sql/table_creator.rb",
@@ -57,7 +58,7 @@ Gem::Specification.new do |s|
"spec/spec_helper.rb",
"spec/unit/migration_spec.rb",
"spec/unit/sql/column_spec.rb",
- "spec/unit/sql/postgresql_spec.rb",
+ "spec/unit/sql/postgres_spec.rb",
"spec/unit/sql/sqlite_extensions_spec.rb",
"spec/unit/sql/table_creator_spec.rb",
"spec/unit/sql/table_modifier_spec.rb",
@@ -84,7 +85,7 @@ Gem::Specification.new do |s|
"spec/spec_helper.rb",
"spec/unit/migration_spec.rb",
"spec/unit/sql/column_spec.rb",
- "spec/unit/sql/postgresql_spec.rb",
+ "spec/unit/sql/postgres_spec.rb",
"spec/unit/sql/sqlite_extensions_spec.rb",
"spec/unit/sql/table_creator_spec.rb",
"spec/unit/sql/table_modifier_spec.rb",
View
4 lib/dm-migrations/migration.rb
@@ -24,7 +24,7 @@ def initialize( position, name, opts = {}, &block )
case @adapter.class.to_s
when /Sqlite/ then @adapter.extend(SQL::Sqlite)
when /Mysql/ then @adapter.extend(SQL::Mysql)
- when /Postgres/ then @adapter.extend(SQL::Postgresql)
+ when /Postgres/ then @adapter.extend(SQL::Postgres)
else
raise "Unsupported Migration Adapter #{@adapter.class}"
end
@@ -115,7 +115,7 @@ def create_index(table_name, *columns_and_options)
end
# Orders migrations by position, so we know what order to run them in.
- # First order by postition, then by name, so at least the order is predictable.
+ # First order by position, then by name, so at least the order is predictable.
def <=> other
if self.position == other.position
self.name.to_s <=> other.name.to_s
View
2  lib/dm-migrations/sql.rb
@@ -2,4 +2,4 @@
require 'dm-migrations/sql/table_modifier'
require 'dm-migrations/sql/sqlite'
require 'dm-migrations/sql/mysql'
-require 'dm-migrations/sql/postgresql'
+require 'dm-migrations/sql/postgres'
View
6 lib/dm-migrations/sql/postgresql.rb → lib/dm-migrations/sql/postgres.rb
@@ -1,12 +1,12 @@
module SQL
- module Postgresql
+ module Postgres
def supports_schema_transactions?
true
end
def table(table_name)
- SQL::Postgresql::Table.new(self, table_name)
+ SQL::Postgres::Table.new(self, table_name)
end
def recreate_database
@@ -41,7 +41,7 @@ def initialize(adapter, table_name)
@adapter, @name = adapter, table_name
@columns = []
adapter.query_table(table_name).each do |col_struct|
- @columns << SQL::Postgresql::Column.new(col_struct)
+ @columns << SQL::Postgres::Column.new(col_struct)
end
query_column_constraints
View
125 spec/integration/migration_runner_spec.rb
@@ -1,81 +1,88 @@
require 'spec_helper'
-DataMapper::Spec::AdapterHelpers.available_adapters.each do |adapter|
- describe "Using Adapter #{adapter}, " 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(0).item
- end
+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
- 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
+ end
- after(:each) do
- migrations.clear
- end
+ 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
- describe '#migration' do
+ after(:each) do
+ migrations.clear
+ 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
+ describe '#migration' do
- 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
+ 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 '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
+ 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
+ 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
- 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
+ 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)
- end
- migrate_up!
- end
+ 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! 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)
+ 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)
end
+ migrate_up!
+ 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
- migrate_down!
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)
+ end
+ migrate_down!
end
+
end
end
+
+
end
View
232 spec/integration/migration_spec.rb
@@ -1,124 +1,128 @@
require 'spec_helper'
-DataMapper::Spec::AdapterHelpers.available_adapters.each do |adapter|
- describe "Using Adapter #{adapter}, " do
- describe DataMapper::Migration, 'interface' do
- before do
- @migration = DataMapper::Migration.new(1, :create_people_table, :verbose => false) { }
- 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 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 :database option" do
- DataMapper.setup(:other, "sqlite3://#{Dir.pwd}/migration_other.db")
-
- m = DataMapper::Migration.new(2, :create_dogs_table, :database => :other) {}
- m.instance_variable_get(:@database).name.should == :other
- end
-
- it "should use the default database by default" do
- @migration.instance_variable_get(:@database).name.should == :default
- 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 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) {}
-
- [m1, m2, m3, m4].sort.should == [m1, m3, m2, m4]
- end
-
- expected_module = {
- :sqlite3 => lambda { SQL::Sqlite },
- :mysql => lambda { SQL::Mysql },
- :postgres => lambda { SQL::Postgresql }
- }[adapter.to_sym][]
-
- it "should extend with #{expected_module} when adapter is #{adapter}" do
- migration = DataMapper::Migration.new(1, :"#{adapter}_adapter_test", :database => adapter) { }
- (class << migration.adapter; self; end).included_modules.should include(expected_module)
- end
- 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 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
-
- 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)
-
- @migration.instance_variable_get(:@down_action).should == action
- end
-
- 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
-
- 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
+describe "A Migration" do
+ describe DataMapper::Migration, 'interface' do
- it "should #say with a default indent of 4" do
- @migration.should_receive(:write).with(" Foobar")
- @migration.say("Foobar")
- end
+ before(:all) do
+ @adapter = DataMapper::Spec.adapter
+ end
+
+ before do
+ @migration = DataMapper::Migration.new(1, :create_people_table, :verbose => false) { }
+ 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 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 :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 use the default database by default" do
+ @migration.instance_variable_get(:@database).name.should == :default
+ 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 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) {}
+
+ [m1, m2, m3, m4].sort.should == [m1, m3, m2, m4]
+ end
+
+ adapter = DataMapper::Spec.adapter_name
+ expected_module = {
+ :sqlite => lambda { SQL::Sqlite },
+ :mysql => lambda { SQL::Mysql },
+ :postgres => lambda { SQL::Postgres }
+ }[adapter.to_sym][]
+
+ 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
- it "should #say_with_time the running time of a block" do
- @migration.should_receive(:write).with(/Block/)
- @migration.should_receive(:write).with(/-> [\d]+/)
+ 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 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
+
+ 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)
+
+ @migration.instance_variable_get(:@down_action).should == action
+ end
- @migration.say_with_time("Block"){ }
- end
+ 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
+ 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 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]+/)
+
+ @migration.say_with_time("Block"){ }
+ end
+
end
end
View
282 spec/integration/sql_spec.rb
@@ -1,189 +1,187 @@
require 'spec_helper'
-DataMapper::Spec::AdapterHelpers.available_adapters.each do |adapter|
- describe "Using Adapter #{adapter}," do
+describe "SQL generation" do
- def repository(*args)
- DataMapper.repository(*args)
- end
+ describe DataMapper::Migration, "#create_table helper" do
+ before :all do
- describe DataMapper::Migration, "#create_table helper" do
- before :all do
- case adapter
- when :sqlite3 then repository(adapter).adapter.extend(SQL::Sqlite3)
- when :mysql then repository(adapter).adapter.extend(SQL::Mysql)
- when :postgres then repository(adapter).adapter.extend(SQL::Postgresql)
- end
- end
+ @adapter = DataMapper::Spec.adapter
+ @repository = DataMapper.repository(@adapter.name)
- before do
- @creator = DataMapper::Migration::TableCreator.new(repository(adapter).adapter, :people) do
- column :id, DataMapper::Types::Serial
- column :name, 'VARCHAR(50)', :allow_nil => false
- column :long_string, String, :size => 200
- 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
- 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
+ end
- it "should have a table_name" do
- @creator.table_name.should == "people"
+ before do
+ @creator = DataMapper::Migration::TableCreator.new(@adapter, :people) do
+ column :id, DataMapper::Types::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 == repository(adapter).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 == (adapter == :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 adapter
- 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
+ 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
- describe DataMapper::Migration, "#modify_table helper" do
- before do
- @migration = DataMapper::Migration.new(1, :create_people_table, :verbose => false) { }
- 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 have a #modify_table helper" do
- @migration.should respond_to(:modify_table)
+ 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
+ describe DataMapper::Migration, "#modify_table helper" 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 #modify_table helper" do
+ @migration.should respond_to(:modify_table)
+ end
- it "should have a #drop_table helper" do
- @migration.should respond_to(:drop_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, "version tracking" do
- before do
- @migration = DataMapper::Migration.new(1, :create_people_table, :verbose => false) do
- up { :ran_up }
- down { :ran_down }
- end
+ it "should have a #drop_table helper" do
+ @migration.should respond_to(:drop_table)
+ end
- @migration.send(:create_migration_info_table_if_needed)
- end
+ end
- def insert_migration_record
- DataMapper.repository.adapter.execute("INSERT INTO migration_info (migration_name) VALUES ('create_people_table')")
+ 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
- it "should know if the migration_info table exists" do
- @migration.send(:migration_info_table_exists?).should be_true
- end
+ @migration.send(:create_migration_info_table_if_needed)
+ end
- it "should know if the migration_info table does not exist" do
- repository.adapter.execute("DROP TABLE migration_info") rescue nil
- @migration.send(:migration_info_table_exists?).should be_false
- end
+ after(:each) { DataMapper::Spec.adapter.execute("DROP TABLE migration_info") rescue nil }
- 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
+ def insert_migration_record
+ DataMapper::Spec.adapter.execute("INSERT INTO migration_info (migration_name) VALUES ('create_people_table')")
+ 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 the migration_info table exists" do
+ @migration.send(:migration_info_table_exists?).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 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 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 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 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 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 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_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 create the migration_info table if it doesn't exist" do
- repository.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 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 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 properly quote the migration's name for use in queries"
+ # TODO how to i call the adapter's #escape_sql method?
- 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 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 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 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 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 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
- after do
- repository.adapter.execute("DELETE FROM migration_info") if @migration.send(:migration_info_table_exists?)
- 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
+
end
end
View
18 spec/spec_helper.rb
@@ -1,25 +1,15 @@
require 'dm-migrations'
require 'dm-migrations/migration_runner'
-require 'dm-core/spec/lib/spec_helper'
+require 'dm-core/spec/setup'
require 'dm-core/spec/lib/adapter_helpers'
+require 'dm-core/spec/lib/spec_helper'
-ENV['ADAPTERS'] ||= 'sqlite3'
-
-# create sqlite3_fs directory if it doesn't exist
-temp_db_dir = Pathname(File.expand_path('../db', __FILE__))
-temp_db_dir.mkpath
-
-DataMapper::Spec::AdapterHelpers.temp_db_dir = temp_db_dir
-
-adapters = ENV['ADAPTERS'].split(' ').map { |adapter_name| adapter_name.strip.downcase }.uniq
-adapters = DataMapper::Spec::AdapterHelpers.primary_adapters.keys if adapters.include?('all')
-
-DataMapper::Spec::AdapterHelpers.setup_adapters(adapters)
+DataMapper::Spec.setup
Spec::Runner.configure do |config|
- config.extend(DataMapper::Spec::AdapterHelpers)
+ config.extend(DataMapper::Spec::Adapters::Helpers)
config.after :all do
DataMapper::Spec.cleanup_models
View
6 spec/unit/migration_spec.rb
@@ -3,7 +3,7 @@
describe 'Migration' do
before do
- @adapter = mock('adapter', :class => DataMapper::Adapters::SqliteAdapter)
+ @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, {}) {}
@@ -40,12 +40,12 @@
end
it 'should determine the class of the adapter to be extended' do
- @adapter.should_receive(:class).and_return(DataMapper::Adapters::SqliteAdapter)
+ @adapter.should_receive(:class).and_return(DataMapper::Spec.adapter.class)
DataMapper::Migration.new(1, :do_nothing, {}) {}
end
it 'should extend the adapter with the right module' do
- @adapter.should_receive(:extend).with(SQL::Sqlite)
+ @adapter.should_receive(:extend).with(SQL.const_get(DataMapper::Spec.adapter_name.capitalize))
DataMapper::Migration.new(1, :do_nothing, {}) {}
end
View
34 spec/unit/sql/postgresql_spec.rb → spec/unit/sql/postgres_spec.rb
@@ -1,13 +1,13 @@
require 'spec_helper'
# a dummy class to include the module into
-class PostgresqlExtension
- include SQL::Postgresql
+class PostgresExtension
+ include SQL::Postgres
end
-describe "SQLite3 Extensions" do
+describe "Postgres Extensions" do
before do
- @pe = PostgresqlExtension.new
+ @pe = PostgresExtension.new
end
it 'should support schema-level transactions' do
@@ -20,7 +20,7 @@ class PostgresqlExtension
it 'should create a table object from the name' do
table = mock('SQLite3 Table')
- SQL::Postgresql::Table.should_receive(:new).with(@pe, 'users').and_return(table)
+ SQL::Postgres::Table.should_receive(:new).with(@pe, 'users').and_return(table)
@pe.table('users').should == table
end
@@ -35,27 +35,27 @@ class PostgresqlExtension
@adapter = mock('adapter', :select => [])
@adapter.stub!(:query_table).with('users').and_return([@cs1, @cs2])
- @col1 = mock('SQLite3 Column')
- @col2 = mock('SQLite3 Column')
+ @col1 = mock('Postgres Column')
+ @col2 = mock('Postgres Column')
end
it 'should initialize columns by querying the table' do
- SQL::Postgresql::Column.should_receive(:new).with(@cs1).and_return(@col1)
- SQL::Postgresql::Column.should_receive(:new).with(@cs2).and_return(@col2)
+ SQL::Postgres::Column.should_receive(:new).with(@cs1).and_return(@col1)
+ SQL::Postgres::Column.should_receive(:new).with(@cs2).and_return(@col2)
@adapter.should_receive(:query_table).with('users').and_return([@cs1,@cs2])
- SQL::Postgresql::Table.new(@adapter, 'users')
+ SQL::Postgres::Table.new(@adapter, 'users')
end
it 'should create SQLite3 Column objects from the returned column structs' do
- SQL::Postgresql::Column.should_receive(:new).with(@cs1).and_return(@col1)
- SQL::Postgresql::Column.should_receive(:new).with(@cs2).and_return(@col2)
- SQL::Postgresql::Table.new(@adapter, 'users')
+ SQL::Postgres::Column.should_receive(:new).with(@cs1).and_return(@col1)
+ SQL::Postgres::Column.should_receive(:new).with(@cs2).and_return(@col2)
+ SQL::Postgres::Table.new(@adapter, 'users')
end
it 'should set the @columns to the looked-up columns' do
- SQL::Postgresql::Column.should_receive(:new).with(@cs1).and_return(@col1)
- SQL::Postgresql::Column.should_receive(:new).with(@cs2).and_return(@col2)
- t = SQL::Postgresql::Table.new(@adapter, 'users')
+ SQL::Postgres::Column.should_receive(:new).with(@cs1).and_return(@col1)
+ SQL::Postgres::Column.should_receive(:new).with(@cs2).and_return(@col2)
+ t = SQL::Postgres::Table.new(@adapter, 'users')
t.columns.should == [@col1, @col2]
end
@@ -72,7 +72,7 @@ class PostgresqlExtension
:data_type => 'integer',
:column_default => 123,
:is_nullable => 'NO')
- @c = SQL::Postgresql::Column.new(@cs)
+ @c = SQL::Postgres::Column.new(@cs)
end
it 'should set the name from the column_name value' do
Please sign in to comment.
Something went wrong with that request. Please try again.