dm-migrations 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -31,6 +31,7 @@ measurements
31
31
  .bundle
32
32
  Gemfile.local
33
33
  Gemfile.lock
34
+ Gemfile.local.lock
34
35
 
35
36
  ## PROJECT::SPECIFIC
36
37
  spec/db/
data/Gemfile CHANGED
@@ -71,14 +71,14 @@
71
71
  source 'http://rubygems.org'
72
72
 
73
73
  DATAMAPPER = 'git://github.com/datamapper'
74
- DM_VERSION = '~> 1.0.0'
74
+ DM_VERSION = '~> 1.0.1'
75
75
 
76
76
  group :runtime do # Runtime dependencies (as in the gemspec)
77
77
 
78
78
  if ENV['EXTLIB']
79
- gem 'extlib', '~> 0.9.15', :git => "#{DATAMAPPER}/extlib.git"
79
+ gem 'extlib', '~> 0.9.15', :git => "#{DATAMAPPER}/extlib.git"
80
80
  else
81
- gem 'activesupport', '~> 3.0.0.beta3', :git => 'git://github.com/rails/rails.git', :require => nil
81
+ gem 'activesupport', '~> 3.0.0', :git => 'git://github.com/rails/rails.git', :branch => '3-0-stable', :require => nil
82
82
  end
83
83
 
84
84
  gem 'dm-core', DM_VERSION, :git => "#{DATAMAPPER}/dm-core.git"
@@ -88,7 +88,7 @@ end
88
88
  group(:development) do # Development dependencies (as in the gemspec)
89
89
 
90
90
  gem 'rake', '~> 0.8.7'
91
- gem 'rspec', '~> 1.3'
91
+ gem 'rspec', '~> 1.3', :git => 'git://github.com/snusnu/rspec', :branch => 'heckle_fix_plus_gemfile'
92
92
  gem 'jeweler', '~> 1.4'
93
93
 
94
94
  end
@@ -107,32 +107,31 @@ end
107
107
  group :datamapper do # We need this because we want to pin these dependencies to their git master sources
108
108
 
109
109
  adapters = ENV['ADAPTER'] || ENV['ADAPTERS']
110
- adapters = adapters.to_s.gsub(',',' ').split(' ') - ['in_memory']
110
+ adapters = adapters.to_s.tr(',', ' ').split.uniq - %w[ in_memory ]
111
111
 
112
- unless adapters.empty?
112
+ DO_VERSION = '~> 0.10.2'
113
+ DM_DO_ADAPTERS = %w[ sqlite postgres mysql oracle sqlserver ]
113
114
 
114
- DO_VERSION = '~> 0.10.3'
115
- DM_DO_ADAPTERS = %w[sqlite postgres mysql oracle sqlserver]
115
+ if (do_adapters = DM_DO_ADAPTERS & adapters).any?
116
+ options = {}
117
+ options[:git] = "#{DATAMAPPER}/do.git" if ENV['DO_GIT'] == 'true'
116
118
 
117
- gem 'data_objects', DO_VERSION, :git => "#{DATAMAPPER}/do.git"
119
+ gem 'data_objects', DO_VERSION, options.dup
118
120
 
119
- adapters.each do |adapter|
120
- if DM_DO_ADAPTERS.any? { |dm_do_adapter| dm_do_adapter =~ /#{adapter}/ }
121
- adapter = 'sqlite3' if adapter == 'sqlite'
122
- gem "do_#{adapter}", DO_VERSION, :git => "#{DATAMAPPER}/do.git"
123
- end
121
+ do_adapters.each do |adapter|
122
+ adapter = 'sqlite3' if adapter == 'sqlite'
123
+ gem "do_#{adapter}", DO_VERSION, options.dup
124
124
  end
125
125
 
126
126
  gem 'dm-do-adapter', DM_VERSION, :git => "#{DATAMAPPER}/dm-do-adapter.git"
127
+ end
127
128
 
128
- adapters.each do |adapter|
129
- gem "dm-#{adapter}-adapter", DM_VERSION, :git => "#{DATAMAPPER}/dm-#{adapter}-adapter.git"
130
- end
131
-
129
+ adapters.each do |adapter|
130
+ gem "dm-#{adapter}-adapter", DM_VERSION, :git => "#{DATAMAPPER}/dm-#{adapter}-adapter.git"
132
131
  end
133
132
 
134
133
  plugins = ENV['PLUGINS'] || ENV['PLUGIN']
135
- plugins = (plugins.to_s.gsub(',',' ').split(' ') + ['dm-migrations']).uniq
134
+ plugins = plugins.to_s.tr(',', ' ').split.uniq
136
135
 
137
136
  plugins.each do |plugin|
138
137
  gem plugin, DM_VERSION, :git => "#{DATAMAPPER}/#{plugin}.git"
data/Rakefile CHANGED
@@ -15,7 +15,7 @@ begin
15
15
 
16
16
  gem.rubyforge_project = 'datamapper'
17
17
 
18
- gem.add_dependency 'dm-core', '~> 1.0.0'
18
+ gem.add_dependency 'dm-core', '~> 1.0.1'
19
19
 
20
20
  gem.add_development_dependency 'rspec', '~> 1.3'
21
21
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dm-migrations}
8
- s.version = "1.0.0"
8
+ s.version = "1.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Paul Sadauskas"]
12
- s.date = %q{2010-06-08}
12
+ s.date = %q{2010-09-07}
13
13
  s.description = %q{DataMapper plugin for writing and speccing migrations}
14
14
  s.email = %q{psadauskas [a] gmail [d] com}
15
15
  s.extra_rdoc_files = [
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
38
38
  "lib/dm-migrations/adapters/dm-sqlserver-adapter.rb",
39
39
  "lib/dm-migrations/adapters/dm-yaml-adapter.rb",
40
40
  "lib/dm-migrations/auto_migration.rb",
41
+ "lib/dm-migrations/exceptions/duplicate_migration.rb",
41
42
  "lib/dm-migrations/migration.rb",
42
43
  "lib/dm-migrations/migration_runner.rb",
43
44
  "lib/dm-migrations/sql.rb",
@@ -107,14 +108,14 @@ Gem::Specification.new do |s|
107
108
  s.specification_version = 3
108
109
 
109
110
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
110
- s.add_runtime_dependency(%q<dm-core>, ["~> 1.0.0"])
111
+ s.add_runtime_dependency(%q<dm-core>, ["~> 1.0.1"])
111
112
  s.add_development_dependency(%q<rspec>, ["~> 1.3"])
112
113
  else
113
- s.add_dependency(%q<dm-core>, ["~> 1.0.0"])
114
+ s.add_dependency(%q<dm-core>, ["~> 1.0.1"])
114
115
  s.add_dependency(%q<rspec>, ["~> 1.3"])
115
116
  end
116
117
  else
117
- s.add_dependency(%q<dm-core>, ["~> 1.0.0"])
118
+ s.add_dependency(%q<dm-core>, ["~> 1.0.1"])
118
119
  s.add_dependency(%q<rspec>, ["~> 1.3"])
119
120
  end
120
121
  end
@@ -126,7 +126,7 @@ module DataMapper
126
126
 
127
127
  # @api private
128
128
  def alter_table_add_column_statement(connection, table_name, schema_hash)
129
- "ALTER TABLE #{quote_name(table_name)} ADD COLUMN #{property_schema_statement(connection, schema_hash)}"
129
+ "ALTER TABLE #{quote_name(table_name)} #{add_column_statement} #{property_schema_statement(connection, schema_hash)}"
130
130
  end
131
131
 
132
132
  # @api private
@@ -204,11 +204,7 @@ module DataMapper
204
204
  # remove the default if the property does not allow nil
205
205
  schema.delete(:default) unless schema[:allow_nil]
206
206
  else
207
- schema[:default] = if type.respond_to?(:dump)
208
- type.dump(default, property)
209
- else
210
- default
211
- end
207
+ schema[:default] = property.dump(default)
212
208
  end
213
209
 
214
210
  schema
@@ -243,6 +239,11 @@ module DataMapper
243
239
  def unique_indexes(model)
244
240
  model.properties(name).unique_indexes
245
241
  end
242
+
243
+ # @api private
244
+ def add_column_statement
245
+ 'ADD COLUMN'
246
+ end
246
247
  end # module SQL
247
248
 
248
249
  include SQL
@@ -256,6 +256,11 @@ module DataMapper
256
256
  "#{table_name[0,self.class::IDENTIFIER_MAX_LENGTH-4]}_pkt"
257
257
  end
258
258
 
259
+ # @api private
260
+ def add_column_statement
261
+ 'ADD'
262
+ end
263
+
259
264
  end # module SQL
260
265
 
261
266
  include SQL
@@ -187,7 +187,7 @@ module DataMapper
187
187
  end
188
188
  DataMapper::Model.append_extensions(Model)
189
189
  Adapters::AbstractAdapter.descendants.each do |adapter_class|
190
- Adapters.include_migration_api(ActiveSupport::Inflector.demodulize(adapter_class.name))
190
+ Adapters.include_migration_api(DataMapper::Inflector.demodulize(adapter_class.name))
191
191
  end
192
192
  end
193
193
 
@@ -0,0 +1,6 @@
1
+ module DataMapper
2
+ module Migrations
3
+ class DuplicateMigration < StandardError
4
+ end
5
+ end
6
+ end
@@ -1,40 +1,84 @@
1
- require 'benchmark'
2
-
1
+ require 'dm-migrations/exceptions/duplicate_migration'
3
2
  require 'dm-migrations/sql'
4
3
 
5
- module DataMapper
6
- class DuplicateMigrationNameError < StandardError
7
- def initialize(migration)
8
- super("Duplicate Migration Name: '#{migration.name}', version: #{migration.position}")
9
- end
10
- end
4
+ require 'benchmark'
11
5
 
6
+ module DataMapper
12
7
  class Migration
13
8
  include SQL
14
9
 
15
- attr_accessor :position, :name, :database, :adapter
16
-
17
- def initialize( position, name, opts = {}, &block )
18
- @position, @name = position, name
19
- @options = opts
20
-
21
- @database = DataMapper.repository(@options[:database] || :default)
22
- @adapter = @database.adapter
23
-
24
- case @adapter.class.to_s
25
- when /Sqlite/ then @adapter.extend(SQL::Sqlite)
26
- when /Mysql/ then @adapter.extend(SQL::Mysql)
27
- when /Postgres/ then @adapter.extend(SQL::Postgres)
10
+ # The position or version the migration belongs to
11
+ attr_reader :position
12
+
13
+ # The name of the migration
14
+ attr_reader :name
15
+
16
+ # The repository the migration operates on
17
+ attr_reader :repository
18
+
19
+ #
20
+ # Creates a new migration.
21
+ #
22
+ # @param [Symbol, String, Integer] position
23
+ # The position or version the migration belongs to.
24
+ #
25
+ # @param [Symbol] name
26
+ # The name of the migration.
27
+ #
28
+ # @param [Hash] options
29
+ # Additional options for the migration.
30
+ #
31
+ # @option options [Boolean] :verbose (true)
32
+ # Enables or disables verbose output.
33
+ #
34
+ # @option options [Symbol] :repository (:default)
35
+ # The DataMapper repository the migration will operate on.
36
+ #
37
+ def initialize(position, name, options = {}, &block)
38
+ @position = position
39
+ @name = name
40
+ @options = options
41
+ @verbose = options.fetch(:verbose, true)
42
+ @up_action = nil
43
+ @down_action = nil
44
+
45
+ @repository = if options.key?(:database)
46
+ warn 'Using the :database option with migrations is deprecated, use :repository instead'
47
+ options[:database]
28
48
  else
29
- raise "Unsupported Migration Adapter #{@adapter.class}"
49
+ options.fetch(:repository, :default)
30
50
  end
31
51
 
32
- @verbose = @options.has_key?(:verbose) ? @options[:verbose] : true
52
+ instance_eval(&block)
53
+ end
33
54
 
34
- @up_action = lambda {}
35
- @down_action = lambda {}
55
+ #
56
+ # The repository the migration will operate on.
57
+ #
58
+ # @return [Symbol, nil]
59
+ # The name of the DataMapper repository the migration will run against.
60
+ #
61
+ # @deprecated Use {#repository} instead.
62
+ #
63
+ # @since 1.0.1.
64
+ #
65
+ def database
66
+ warn "Using the DataMapper::Migration#database method is deprecated, use #repository instead"
67
+ @repository
68
+ end
36
69
 
37
- instance_eval &block
70
+ #
71
+ # The adapter the migration will use.
72
+ #
73
+ # @return [DataMapper::Adapter]
74
+ # The adapter the migration will operate on.
75
+ #
76
+ # @since 1.0.1
77
+ #
78
+ def adapter
79
+ setup! unless setup?
80
+
81
+ @adapter
38
82
  end
39
83
 
40
84
  # define the actions that should be performed on an up migration
@@ -50,50 +94,60 @@ module DataMapper
50
94
  # perform the migration by running the code in the #up block
51
95
  def perform_up
52
96
  result = nil
97
+
53
98
  if needs_up?
54
99
  # TODO: fix this so it only does transactions for databases that support create/drop
55
100
  # database.transaction.commit do
101
+ if @up_action
56
102
  say_with_time "== Performing Up Migration ##{position}: #{name}", 0 do
57
103
  result = @up_action.call
58
104
  end
59
- update_migration_info(:up)
105
+ end
106
+
107
+ update_migration_info(:up)
60
108
  # end
61
109
  end
110
+
62
111
  result
63
112
  end
64
113
 
65
114
  # un-do the migration by running the code in the #down block
66
115
  def perform_down
67
116
  result = nil
117
+
68
118
  if needs_down?
69
119
  # TODO: fix this so it only does transactions for databases that support create/drop
70
120
  # database.transaction.commit do
121
+ if @down_action
71
122
  say_with_time "== Performing Down Migration ##{position}: #{name}", 0 do
72
123
  result = @down_action.call
73
124
  end
74
- update_migration_info(:down)
125
+ end
126
+
127
+ update_migration_info(:down)
75
128
  # end
76
129
  end
130
+
77
131
  result
78
132
  end
79
133
 
80
134
  # execute raw SQL
81
135
  def execute(sql, *bind_values)
82
136
  say_with_time(sql) do
83
- @adapter.execute(sql, *bind_values)
137
+ adapter.execute(sql, *bind_values)
84
138
  end
85
139
  end
86
140
 
87
141
  def create_table(table_name, opts = {}, &block)
88
- execute TableCreator.new(@adapter, table_name, opts, &block).to_sql
142
+ execute TableCreator.new(adapter, table_name, opts, &block).to_sql
89
143
  end
90
144
 
91
145
  def drop_table(table_name, opts = {})
92
- execute "DROP TABLE #{@adapter.send(:quote_name, table_name.to_s)}"
146
+ execute "DROP TABLE #{adapter.send(:quote_name, table_name.to_s)}"
93
147
  end
94
148
 
95
149
  def modify_table(table_name, opts = {}, &block)
96
- TableModifier.new(@adapter, table_name, opts, &block).statements.each do |sql|
150
+ TableModifier.new(adapter, table_name, opts, &block).statements.each do |sql|
97
151
  execute(sql)
98
152
  end
99
153
  end
@@ -177,7 +231,7 @@ module DataMapper
177
231
  # Fetch the record for this migration out of the migration_info table
178
232
  def migration_record
179
233
  return [] unless migration_info_table_exists?
180
- @adapter.select("SELECT #{migration_name_column} FROM #{migration_info_table} WHERE #{migration_name_column} = #{quoted_name}")
234
+ adapter.select("SELECT #{migration_name_column} FROM #{migration_info_table} WHERE #{migration_name_column} = #{quoted_name}")
181
235
  end
182
236
 
183
237
  # True if the migration needs to be run
@@ -204,12 +258,43 @@ module DataMapper
204
258
 
205
259
  def quote_table_name(table_name)
206
260
  # TODO: Fix this for 1.9 - can't use this hack to access a private method
207
- @adapter.send(:quote_name, table_name.to_s)
261
+ adapter.send(:quote_name, table_name.to_s)
208
262
  end
209
263
 
210
264
  def quote_column_name(column_name)
211
265
  # TODO: Fix this for 1.9 - can't use this hack to access a private method
212
- @adapter.send(:quote_name, column_name.to_s)
266
+ adapter.send(:quote_name, column_name.to_s)
267
+ end
268
+
269
+ protected
270
+
271
+ #
272
+ # Determines whether the migration has been setup.
273
+ #
274
+ # @return [Boolean]
275
+ # Specifies whether the migration has been setup.
276
+ #
277
+ # @since 1.0.1
278
+ #
279
+ def setup?
280
+ !(@adapter.nil?)
281
+ end
282
+
283
+ #
284
+ # Sets up the migration.
285
+ #
286
+ # @since 1.0.1
287
+ #
288
+ def setup!
289
+ @adapter = DataMapper.repository(@repository).adapter
290
+
291
+ case @adapter.class.name
292
+ when /Sqlite/ then @adapter.extend(SQL::Sqlite)
293
+ when /Mysql/ then @adapter.extend(SQL::Mysql)
294
+ when /Postgres/ then @adapter.extend(SQL::Postgres)
295
+ else
296
+ raise(RuntimeError,"Unsupported Migration Adapter #{@adapter.class}",caller)
297
+ end
213
298
  end
214
299
  end
215
300
  end
@@ -1,5 +1,10 @@
1
+ require 'dm-core'
2
+
1
3
  module SQL
2
4
  class TableCreator
5
+
6
+ extend DataMapper::Property::Lookup
7
+
3
8
  attr_accessor :table_name, :opts
4
9
 
5
10
  def initialize(adapter, table_name, opts = {}, &block)
@@ -15,6 +15,17 @@ describe DataMapper::Migrations do
15
15
  mod.logger = original
16
16
  end
17
17
 
18
+ before :all do
19
+ class DataMapper::Property::NumericString < DataMapper::Property::String
20
+ default 0
21
+
22
+ def dump(value)
23
+ return if value.nil?
24
+ value.to_s
25
+ end
26
+ end
27
+ end
28
+
18
29
  supported_by :mysql do
19
30
  before :all do
20
31
  module ::Blog
@@ -197,10 +208,12 @@ describe DataMapper::Migrations do
197
208
 
198
209
  options.only(:min, :max).each do |key, value|
199
210
  it "should allow the #{key} value #{value} to be stored" do
200
- lambda {
201
- resource = @model.create(@property => value)
202
- @model.first(@property => value).should eql(resource)
203
- }.should_not raise_error
211
+ pending_if "#{value} causes problem with JRuby 1.5.2 parser", RUBY_ENGINE == 'jruby' && value == -9223372036854775808 do
212
+ lambda {
213
+ resource = @model.create(@property => value)
214
+ @model.first(@property => value).should eql(resource)
215
+ }.should_not raise_error
216
+ end
204
217
  end
205
218
  end
206
219
  end
@@ -230,7 +243,7 @@ describe DataMapper::Migrations do
230
243
 
231
244
  describe "with a length of #{length}" do
232
245
  before :all do
233
- @property = @model.property(:body, DataMapper::Types::Text, options)
246
+ @property = @model.property(:body, DataMapper::Property::Text, options)
234
247
 
235
248
  @response = capture_log(DataObjects::Mysql) { @model.auto_migrate! }
236
249
  end
@@ -277,6 +290,19 @@ describe DataMapper::Migrations do
277
290
  end
278
291
  end
279
292
  end
293
+
294
+ describe 'NumericString property' do
295
+ before :all do
296
+ @model.property(:id, DataMapper::Property::Serial)
297
+ @model.property(:number, DataMapper::Property::NumericString)
298
+
299
+ @response = capture_log(DataObjects::Mysql) { @model.auto_migrate! }
300
+ end
301
+
302
+ it "should create a VARCHAR(50) column with a default of '0'" do
303
+ @output.last.should =~ %r{\ACREATE TABLE `blog_articles` \(`id` INT\(10\) UNSIGNED NOT NULL AUTO_INCREMENT, `number` VARCHAR\(50\) DEFAULT '0', PRIMARY KEY\(`id`\)\) ENGINE = InnoDB CHARACTER SET [a-z\d]+ COLLATE (?:[a-z\d](?:_?[a-z\d]+)*)\z}
304
+ end
305
+ end
280
306
  end
281
307
  end
282
308
 
@@ -340,10 +366,12 @@ describe DataMapper::Migrations do
340
366
 
341
367
  options.only(:min, :max).each do |key, value|
342
368
  it "should allow the #{key} value #{value} to be stored" do
343
- lambda {
344
- resource = @model.create(@property => value)
345
- @model.first(@property => value).should eql(resource)
346
- }.should_not raise_error
369
+ pending_if "#{value} causes problem with JRuby 1.5.2 parser", RUBY_ENGINE == 'jruby' && value == -9223372036854775808 do
370
+ lambda {
371
+ resource = @model.create(@property => value)
372
+ @model.first(@property => value).should eql(resource)
373
+ }.should_not raise_error
374
+ end
347
375
  end
348
376
  end
349
377
  end
@@ -420,6 +448,19 @@ describe DataMapper::Migrations do
420
448
  end
421
449
  end
422
450
  end
451
+
452
+ describe 'NumericString property' do
453
+ before :all do
454
+ @model.property(:id, DataMapper::Property::Serial)
455
+ @model.property(:number, DataMapper::Property::NumericString)
456
+
457
+ @response = capture_log(DataObjects::Postgres) { @model.auto_migrate! }
458
+ end
459
+
460
+ it "should create a VARCHAR(50) column with a default of '0'" do
461
+ @output[-2].should == "CREATE TABLE \"blog_articles\" (\"id\" SERIAL NOT NULL, \"number\" VARCHAR(50) DEFAULT '0', PRIMARY KEY(\"id\"))"
462
+ end
463
+ end
423
464
  end
424
465
  end
425
466
 
@@ -487,10 +528,12 @@ describe DataMapper::Migrations do
487
528
 
488
529
  options.only(:min, :max).each do |key, value|
489
530
  it "should allow the #{key} value #{value} to be stored" do
490
- lambda {
491
- resource = @model.create(@property => value)
492
- @model.first(@property => value).should eql(resource)
493
- }.should_not raise_error
531
+ pending_if "#{value} causes problem with JRuby 1.5.2 parser", RUBY_ENGINE == 'jruby' && value == -9223372036854775808 do
532
+ lambda {
533
+ resource = @model.create(@property => value)
534
+ @model.first(@property => value).should eql(resource)
535
+ }.should_not raise_error
536
+ end
494
537
  end
495
538
  end
496
539
  end
@@ -16,24 +16,30 @@ describe "A Migration" do
16
16
 
17
17
  it "should have a postition attribute" do
18
18
  @migration.should respond_to(:position)
19
- @migration.should respond_to(:position=)
19
+
20
20
  @migration.position.should == 1
21
21
  end
22
22
 
23
23
  it "should have a name attribute" do
24
24
  @migration.should respond_to(:name)
25
- @migration.should respond_to(:name=)
25
+
26
26
  @migration.name.should == :create_people_table
27
27
  end
28
28
 
29
- it "should have a :database option" do
30
- adapter = DataMapper::Spec.adapter(:alternate)
31
- m = DataMapper::Migration.new(2, :create_dogs_table, :database => :alternate) {}
32
- m.instance_variable_get(:@adapter).should == adapter
29
+ it "should have a :repository option" do
30
+ m = DataMapper::Migration.new(2, :create_dogs_table, :repository => :alternate) {}
31
+
32
+ m.instance_variable_get(:@repository).should == :alternate
33
+ end
34
+
35
+ it "should use the default repository by default" do
36
+ @migration.instance_variable_get(:@repository).should == :default
33
37
  end
34
38
 
35
- it "should use the default database by default" do
36
- @migration.instance_variable_get(:@database).name.should == :default
39
+ it "should still support a :database option" do
40
+ m = DataMapper::Migration.new(2, :create_legacy_table, :database => :legacy) {}
41
+
42
+ m.instance_variable_get(:@repository).should == :legacy
37
43
  end
38
44
 
39
45
  it "should have a verbose option" do
data/spec/spec_helper.rb CHANGED
@@ -4,10 +4,12 @@ require 'dm-migrations/migration_runner'
4
4
  require 'dm-core/spec/setup'
5
5
  require 'dm-core/spec/lib/adapter_helpers'
6
6
  require 'dm-core/spec/lib/spec_helper'
7
+ require 'dm-core/spec/lib/pending_helpers'
7
8
 
8
9
  Spec::Runner.configure do |config|
9
10
 
10
11
  config.extend(DataMapper::Spec::Adapters::Helpers)
12
+ config.include(DataMapper::Spec::PendingHelpers)
11
13
 
12
14
  config.after :all do
13
15
  DataMapper::Spec.cleanup_models
@@ -29,31 +29,16 @@ describe 'Migration' do
29
29
  @m.instance_variable_get(:@options).should == {}
30
30
  end
31
31
 
32
- it 'should set @database from the default repository if no :database option is given' do
33
- DataMapper.should_receive(:repository).with(:default).and_return(@repo)
34
- DataMapper::Migration.new(1, :do_nothing, {}) {}
35
- end
32
+ it 'should set @repository from the default repository if no :repository option is given' do
33
+ m = DataMapper::Migration.new(1, :do_nothing, {}) {}
36
34
 
37
- it 'should set @database to the repository specified with the :database option' do
38
- DataMapper.should_receive(:repository).with(:foobar).and_return(@repo)
39
- DataMapper::Migration.new(1, :do_nothing, :database => :foobar) {}
35
+ m.instance_variable_get(:@repository).should == :default
40
36
  end
41
37
 
42
- it 'should determine the class of the adapter to be extended' do
43
- @adapter.should_receive(:class).and_return(DataMapper::Spec.adapter.class)
44
- DataMapper::Migration.new(1, :do_nothing, {}) {}
45
- end
46
-
47
- it 'should extend the adapter with the right module' do
48
- @adapter.should_receive(:extend).with(SQL.const_get(DataMapper::Spec.adapter_name.capitalize))
49
- DataMapper::Migration.new(1, :do_nothing, {}) {}
50
- end
38
+ it 'should set @repository to the specified :repository option' do
39
+ m = DataMapper::Migration.new(1, :do_nothing, :repository => :foobar) {}
51
40
 
52
- it 'should raise "Unsupported adapter" on an unknown adapter' do
53
- @adapter.should_receive(:class).any_number_of_times.and_return("InvalidAdapter")
54
- lambda {
55
- DataMapper::Migration.new(1, :do_nothing, {}) {}
56
- }.should raise_error
41
+ m.instance_variable_get(:@repository).should == :foobar
57
42
  end
58
43
 
59
44
  it 'should set @verbose from the options hash' do
@@ -65,12 +50,12 @@ describe 'Migration' do
65
50
  @m.instance_variable_get(:@verbose).should be(true)
66
51
  end
67
52
 
68
- it 'should set the @up_action to an empty block' do
69
- @m.instance_variable_get(:@up_action).should be_kind_of(Proc)
53
+ it 'should set the @up_action to nil' do
54
+ @m.instance_variable_get(:@up_action).should be_nil
70
55
  end
71
56
 
72
- it 'should set the @down_action to an empty block' do
73
- @m.instance_variable_get(:@down_action).should be_kind_of(Proc)
57
+ it 'should set the @down_action to nil' do
58
+ @m.instance_variable_get(:@down_action).should be_nil
74
59
  end
75
60
 
76
61
  it 'should evaluate the given block'
@@ -89,6 +74,30 @@ describe 'Migration' do
89
74
  @m.instance_variable_get(:@down_action).should == action
90
75
  end
91
76
 
77
+ describe 'adapter' do
78
+ before(:each) do
79
+ @m.instance_variable_set(:@adapter, nil)
80
+ end
81
+
82
+ it 'should determine the class of the adapter to be extended' do
83
+ @adapter.should_receive(:class).and_return(DataMapper::Spec.adapter.class)
84
+
85
+ @m.adapter
86
+ end
87
+
88
+ it 'should extend the adapter with the right module' do
89
+ @adapter.should_receive(:extend).with(SQL.const_get(DataMapper::Spec.adapter_name.capitalize))
90
+
91
+ @m.adapter
92
+ end
93
+
94
+ it 'should raise "Unsupported adapter" on an unknown adapter' do
95
+ @adapter.should_receive(:class).any_number_of_times.and_return("InvalidAdapter")
96
+
97
+ lambda { @m.adapter }.should raise_error
98
+ end
99
+ end
100
+
92
101
  describe 'perform_up' do
93
102
  before do
94
103
  @up_action = mock('proc', :call => true)
@@ -1,16 +1,14 @@
1
1
  desc "Support bundling from local source code (allows BUNDLE_GEMFILE=Gemfile.local bundle foo)"
2
2
  task :local_gemfile do |t|
3
3
 
4
- root = Pathname(__FILE__).dirname.parent
5
- datamapper = root.parent
6
-
7
- source_regex = /DATAMAPPER = 'git:\/\/github.com\/datamapper'/
8
- gem_source_regex = /:git => \"#\{DATAMAPPER\}\/(.+?)(?:\.git)?\"/
4
+ root = Pathname(__FILE__).dirname.parent
5
+ datamapper = root.parent
9
6
 
10
7
  root.join('Gemfile.local').open('w') do |f|
11
8
  root.join('Gemfile').open.each do |line|
12
- line.sub!(source_regex, "DATAMAPPER = '#{datamapper}'")
13
- line.sub!(gem_source_regex, ':path => "#{DATAMAPPER}/\1"')
9
+ line.sub!(/DATAMAPPER = 'git:\/\/github.com\/datamapper'/, "DATAMAPPER = '#{datamapper}'")
10
+ line.sub!(/:git => \"#\{DATAMAPPER\}\/(.+?)(?:\.git)?\"/, ':path => "#{DATAMAPPER}/\1"')
11
+ line.sub!(/do_options\[:git\] = \"#\{DATAMAPPER\}\/(.+?)(?:\.git)?\"/, 'do_options[:path] = "#{DATAMAPPER}/\1"')
14
12
  f.puts line
15
13
  end
16
14
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-migrations
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
4
  prerelease: false
6
5
  segments:
7
6
  - 1
8
7
  - 0
9
- - 0
10
- version: 1.0.0
8
+ - 1
9
+ version: 1.0.1
11
10
  platform: ruby
12
11
  authors:
13
12
  - Paul Sadauskas
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-06-08 00:00:00 -07:00
17
+ date: 2010-09-07 00:00:00 -07:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,12 +25,11 @@ dependencies:
26
25
  requirements:
27
26
  - - ~>
28
27
  - !ruby/object:Gem::Version
29
- hash: 23
30
28
  segments:
31
29
  - 1
32
30
  - 0
33
- - 0
34
- version: 1.0.0
31
+ - 1
32
+ version: 1.0.1
35
33
  type: :runtime
36
34
  version_requirements: *id001
37
35
  - !ruby/object:Gem::Dependency
@@ -42,7 +40,6 @@ dependencies:
42
40
  requirements:
43
41
  - - ~>
44
42
  - !ruby/object:Gem::Version
45
- hash: 9
46
43
  segments:
47
44
  - 1
48
45
  - 3
@@ -80,6 +77,7 @@ files:
80
77
  - lib/dm-migrations/adapters/dm-sqlserver-adapter.rb
81
78
  - lib/dm-migrations/adapters/dm-yaml-adapter.rb
82
79
  - lib/dm-migrations/auto_migration.rb
80
+ - lib/dm-migrations/exceptions/duplicate_migration.rb
83
81
  - lib/dm-migrations/migration.rb
84
82
  - lib/dm-migrations/migration_runner.rb
85
83
  - lib/dm-migrations/sql.rb
@@ -130,7 +128,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
128
  requirements:
131
129
  - - ">="
132
130
  - !ruby/object:Gem::Version
133
- hash: 3
134
131
  segments:
135
132
  - 0
136
133
  version: "0"
@@ -139,7 +136,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
136
  requirements:
140
137
  - - ">="
141
138
  - !ruby/object:Gem::Version
142
- hash: 3
143
139
  segments:
144
140
  - 0
145
141
  version: "0"