Permalink
Browse files

Updated to pass specs when using Ruby 1.9.1

  • Loading branch information...
1 parent 04e925b commit bbb48ad81cc1fa6b5bbda0d640a6b22e7e1a3751 Dan Kubb committed Jan 20, 2009
View
@@ -2,8 +2,6 @@
module DataMapper
module MigrationRunner
- @@migrations ||= []
-
# Creates a new migration, and adds it to the list of migrations to be run.
# Migrations can be defined in any order, they will be sorted and run in the
# correct order.
@@ -42,10 +40,9 @@ module MigrationRunner
# you write a migration using a model, then later change the model, there's a
# possibility the migration will no longer work. Using SQL will always work.
def migration( number, name, opts = {}, &block )
- @@migrations ||= []
- raise "Migration name conflict: '#{name}'" if @@migrations.map { |m| m.name }.include?(name.to_s)
+ raise "Migration name conflict: '#{name}'" if migrations.map { |m| m.name }.include?(name.to_s)
- @@migrations << DataMapper::Migration.new( number, name.to_s, opts, &block )
+ migrations << DataMapper::Migration.new( number, name.to_s, opts, &block )
end
# Run all migrations that need to be run. In most cases, this would be called by a
@@ -55,7 +52,7 @@ def migration( number, name, opts = {}, &block )
# has an optional argument 'level' which if supplied, only performs the migrations
# with a position less than or equal to the level.
def migrate_up!(level = nil)
- @@migrations.sort.each do |migration|
+ migrations.sort.each do |migration|
if level.nil?
migration.perform_up()
else
@@ -69,7 +66,7 @@ def migrate_up!(level = nil)
# has an optional argument 'level' which, if supplied, only performs the
# down migrations with a postion greater than the level.
def migrate_down!(level = nil)
- @@migrations.sort.reverse.each do |migration|
+ migrations.sort.reverse.each do |migration|
if level.nil?
migration.perform_down()
else
@@ -79,7 +76,7 @@ def migrate_down!(level = nil)
end
def migrations
- @@migrations
+ @migrations ||= []
end
end
@@ -16,22 +16,22 @@
end
after(:each) do
- @@migrations = []
+ migrations.clear
end
describe '#migration' do
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"
+ migrations.should be_kind_of(Array)
+ migrations.should have(1).item
+ migrations.first.name.should == "create_people_table"
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
+ migrations.should have(4).items
end
it 'should raise an error on adding with a duplicated name' do
@@ -49,14 +49,14 @@
it 'calling migrate_up! should migrate up all the migrations' do
# add our expectation that migrate_up should be called
- @@migrations.each do |m|
+ migrations.each do |m|
m.should_receive(:perform_up)
end
migrate_up!
end
it 'calling migrate_up! with an arguement should only migrate to that level' do
- @@migrations.each do |m|
+ migrations.each do |m|
if m.position <= 2
m.should_receive(:perform_up)
else
@@ -68,7 +68,7 @@
it 'calling migrate_down! should migrate down all the migrations' do
# add our expectation that migrate_up should be called
- @@migrations.each do |m|
+ migrations.each do |m|
m.should_receive(:perform_down)
end
migrate_down!
@@ -43,7 +43,8 @@ class PostgresqlExtension
end
it 'should initialize columns by querying the table' do
- SQL::Postgresql::Column.stub!(:new).and_return(@col1, @col2)
+ SQL::Postgresql::Column.should_receive(:new).with(@cs1).and_return(@col1)
+ SQL::Postgresql::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')
end
@@ -55,7 +56,8 @@ class PostgresqlExtension
end
it 'should set the @columns to the looked-up columns' do
- SQL::Postgresql::Column.stub!(:new).and_return(@col1, @col2)
+ 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')
t.columns.should == [@col1, @col2]
end
@@ -53,7 +53,8 @@ class Sqlite3Extension
end
it 'should initialize columns by querying the table' do
- SQL::Sqlite3::Column.stub!(:new).and_return(@col1, @col2)
+ SQL::Sqlite3::Column.should_receive(:new).with(@cs1).and_return(@col1)
+ SQL::Sqlite3::Column.should_receive(:new).with(@cs2).and_return(@col2)
@adapter.should_receive(:query_table).with('users').and_return([@cs1,@cs2])
SQL::Sqlite3::Table.new(@adapter, 'users')
end
@@ -65,9 +66,10 @@ class Sqlite3Extension
end
it 'should set the @columns to the looked-up columns' do
- SQL::Sqlite3::Column.stub!(:new).and_return(@col1, @col2)
+ SQL::Sqlite3::Column.should_receive(:new).with(@cs1).and_return(@col1)
+ SQL::Sqlite3::Column.should_receive(:new).with(@cs2).and_return(@col2)
t = SQL::Sqlite3::Table.new(@adapter, 'users')
- t.columns.should == [@col1, @col2]
+ t.columns.should == [ @col1, @col2 ]
end
end
View
@@ -8,7 +8,7 @@
desc 'Run specifications'
Spec::Rake::SpecTask.new(:spec) do |t|
t.spec_opts << '--options' << 'spec/spec.opts' if File.exists?('spec/spec.opts')
- t.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s)
+ t.spec_files = Pathname.glob((ROOT + 'spec/**/*_spec.rb').to_s).map { |f| f.to_s }
begin
gem 'rcov', '~>0.8'

0 comments on commit bbb48ad

Please sign in to comment.