Permalink
Browse files

Use DataMapper::Spec.setup for running specs

  • Loading branch information...
1 parent 98fd688 commit 0b75f165bf4c06a75f10dd5ce588f5aa736b60d4 @snusnu snusnu committed Apr 30, 2010
View
@@ -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",
@@ -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,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'
@@ -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
@@ -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
Oops, something went wrong.

0 comments on commit 0b75f16

Please sign in to comment.