ibm_db 2.5.9 → 2.5.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,6 @@
1
1
  require "cases/helper"
2
2
  require 'models/company'
3
+ require "models/contract"
3
4
  require 'models/topic'
4
5
  require 'models/edge'
5
6
  require 'models/club'
@@ -172,7 +173,7 @@ class CalculationsTest < ActiveRecord::TestCase
172
173
  end
173
174
 
174
175
  def test_should_group_by_summed_field_having_condition_from_select
175
- c = Account.select("MIN(credit_limit) AS min_credit_limit").group(:firm_id).having("min_credit_limit > 50").sum(:credit_limit)
176
+ c = Account.select("MIN(credit_limit) AS min_credit_limit").group(:firm_id).having("MIN(credit_limit) > 50").sum(:credit_limit)
176
177
  assert_nil c[1]
177
178
  assert_equal 60, c[2]
178
179
  assert_equal 53, c[9]
@@ -405,6 +406,10 @@ class CalculationsTest < ActiveRecord::TestCase
405
406
  Account.sum(:credit_limit, :from => 'accounts', :conditions => "credit_limit > 50")
406
407
  end
407
408
 
409
+ def test_sum_array_compatibility
410
+ assert_equal Account.sum(:credit_limit), Account.sum(&:credit_limit)
411
+ end
412
+
408
413
  def test_average_with_from_option
409
414
  assert_equal Account.average(:credit_limit), Account.average(:credit_limit, :from => 'accounts')
410
415
  assert_equal Account.average(:credit_limit, :conditions => "credit_limit > 50"),
@@ -443,4 +448,35 @@ class CalculationsTest < ActiveRecord::TestCase
443
448
  distinct_authors_for_approved_count = Topic.group(:approved).count(:author_name, :distinct => true)[true]
444
449
  assert_equal distinct_authors_for_approved_count, 2
445
450
  end
451
+
452
+ def test_pluck
453
+ assert_equal [1,2,3,4], Topic.order(:id).pluck(:id)
454
+ end
455
+
456
+ def test_pluck_type_cast
457
+ topic = topics(:first)
458
+ relation = Topic.where(:id => topic.id)
459
+ assert_equal [ topic.approved ], relation.pluck(:approved)
460
+ assert_equal [ topic.last_read ], relation.pluck(:last_read)
461
+ assert_equal [ topic.written_on ], relation.pluck(:written_on)
462
+ end
463
+
464
+ def test_pluck_and_uniq
465
+ assert_equal [50, 53, 55, 60], Account.order(:credit_limit).uniq.pluck(:credit_limit)
466
+ end
467
+
468
+ def test_pluck_in_relation
469
+ company = Company.first
470
+ contract = company.contracts.create!
471
+ assert_equal [contract.id], company.contracts.pluck(:id)
472
+ end
473
+
474
+ def test_pluck_with_serialization
475
+ t = Topic.create!(:content => { :foo => :bar })
476
+ assert_equal [{:foo => :bar}], Topic.where(:id => t.id).pluck(:content)
477
+ end
478
+
479
+ def test_pluck_with_qualified_column_name
480
+ assert_equal [1,2,3,4], Topic.order(:id).pluck("topics.id")
481
+ end
446
482
  end
@@ -6,6 +6,8 @@ require 'models/topic'
6
6
  require 'models/developer'
7
7
 
8
8
  require MIGRATIONS_ROOT + "/valid/2_we_need_reminders"
9
+ require MIGRATIONS_ROOT + "/rename/1_we_need_things"
10
+ require MIGRATIONS_ROOT + "/rename/2_rename_things"
9
11
  require MIGRATIONS_ROOT + "/decimal/1_give_me_big_numbers"
10
12
 
11
13
  if ActiveRecord::Base.connection.supports_migrations?
@@ -13,6 +15,8 @@ if ActiveRecord::Base.connection.supports_migrations?
13
15
 
14
16
  class Reminder < ActiveRecord::Base; end
15
17
 
18
+ class Thing < ActiveRecord::Base; end
19
+
16
20
  class ActiveRecord::Migration
17
21
  class << self
18
22
  attr_accessor :message_count
@@ -65,6 +69,11 @@ if ActiveRecord::Base.connection.supports_migrations?
65
69
  ActiveRecord::Base.connection.initialize_schema_migrations_table
66
70
  ActiveRecord::Base.connection.execute "DELETE FROM #{ActiveRecord::Migrator.schema_migrations_table_name}"
67
71
 
72
+ %w(things awesome_things prefix_things_suffix prefix_awesome_things_suffix).each do |table|
73
+ Thing.connection.drop_table(table) rescue nil
74
+ end
75
+ Thing.reset_column_information
76
+
68
77
  %w(reminders people_reminders prefix_reminders_suffix).each do |table|
69
78
  Reminder.connection.drop_table(table) rescue nil
70
79
  end
@@ -133,6 +142,18 @@ if ActiveRecord::Base.connection.supports_migrations?
133
142
  assert_nothing_raised { Person.connection.add_index("people", %w(last_name first_name administrator), :name => "named_admin") }
134
143
  assert_nothing_raised { Person.connection.remove_index("people", :name => "named_admin") }
135
144
  end
145
+
146
+ # Selected adapters support index sort order
147
+ if current_adapter?(:SQLite3Adapter, :MysqlAdapter, :Mysql2Adapter, :PostgreSQLAdapter)
148
+ assert_nothing_raised { Person.connection.add_index("people", ["last_name"], :order => {:last_name => :desc}) }
149
+ assert_nothing_raised { Person.connection.remove_index("people", ["last_name"]) }
150
+ assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"], :order => {:last_name => :desc}) }
151
+ assert_nothing_raised { Person.connection.remove_index("people", ["last_name", "first_name"]) }
152
+ assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"], :order => {:last_name => :desc, :first_name => :asc}) }
153
+ assert_nothing_raised { Person.connection.remove_index("people", ["last_name", "first_name"]) }
154
+ assert_nothing_raised { Person.connection.add_index("people", ["last_name", "first_name"], :order => :desc) }
155
+ assert_nothing_raised { Person.connection.remove_index("people", ["last_name", "first_name"]) }
156
+ end
136
157
  end
137
158
 
138
159
  def test_index_symbol_names
@@ -152,6 +173,13 @@ if ActiveRecord::Base.connection.supports_migrations?
152
173
  Person.connection.remove_index("people", :name => good_index_name)
153
174
  end
154
175
 
176
+ def test_add_index_attribute_length_limit
177
+ Person.connection.add_index :people, [:first_name, :primary_contact_id], :length => {:first_name => 10, :primary_contact_id => nil}, :name => "attribute_length"
178
+ assert Person.connection.index_exists?(:people, [:first_name, :primary_contact_id], :name => "attribute_length")
179
+ ensure
180
+ Person.connection.remove_index(:people, :name => "attribute_length")
181
+ end
182
+
155
183
  def test_remove_nonexistent_index
156
184
  # we do this by name, so OpenBase is a wash as noted above
157
185
  unless current_adapter?(:OpenBaseAdapter)
@@ -406,8 +434,8 @@ if ActiveRecord::Base.connection.supports_migrations?
406
434
  created_at_column = created_columns.detect {|c| c.name == 'created_at' }
407
435
  updated_at_column = created_columns.detect {|c| c.name == 'updated_at' }
408
436
 
409
- assert created_at_column.null
410
- assert updated_at_column.null
437
+ assert !created_at_column.null
438
+ assert !updated_at_column.null
411
439
  ensure
412
440
  Person.connection.drop_table table_name rescue nil
413
441
  end
@@ -488,9 +516,13 @@ if ActiveRecord::Base.connection.supports_migrations?
488
516
 
489
517
  # Do a manual insertion
490
518
  if current_adapter?(:OracleAdapter)
491
- Person.connection.execute "insert into people (id, wealth) values (people_seq.nextval, 12345678901234567890.0123456789)"
519
+ Person.connection.execute "insert into people (id, wealth, created_at, updated_at) values (people_seq.nextval, 12345678901234567890.0123456789, sysdate, sysdate)"
492
520
  elsif current_adapter?(:OpenBaseAdapter) || (current_adapter?(:MysqlAdapter) && Mysql.client_version < 50003) #before mysql 5.0.3 decimals stored as strings
493
- Person.connection.execute "insert into people (wealth) values ('12345678901234567890.0123456789')"
521
+ Person.connection.execute "insert into people (wealth, created_at, updated_at) values ('12345678901234567890.0123456789', 0, 0)"
522
+ elsif current_adapter?(:PostgreSQLAdapter)
523
+ Person.connection.execute "insert into people (wealth, created_at, updated_at) values (12345678901234567890.0123456789, now(), now())"
524
+ elsif current_adapter?(:IBM_DBAdapter)
525
+ Person.connection.execute "insert into people (wealth, created_at, updated_at, lock_version, first_name) values (12345678901234567890.0123456789, CURRENT TIMESTAMP, CURRENT TIMESTAMP, 0, 'Jim')"
494
526
  else
495
527
  Person.connection.execute "insert into people (wealth) values (12345678901234567890.0123456789)"
496
528
  end
@@ -508,7 +540,12 @@ if ActiveRecord::Base.connection.supports_migrations?
508
540
  Person.delete_all
509
541
 
510
542
  # Now use the Rails insertion
511
- assert_nothing_raised { Person.create :wealth => BigDecimal.new("12345678901234567890.0123456789") }
543
+ unless current_adapter?(:IBM_DBAdapter)
544
+ assert_nothing_raised { Person.create :wealth => BigDecimal.new("12345678901234567890.0123456789") }
545
+ else
546
+ # First_name is a not null column, hence ensure a value is specified
547
+ assert_nothing_raised { Person.create ({:wealth => BigDecimal.new("12345678901234567890.0123456789"), :first_name => "James"}) }
548
+ end
512
549
 
513
550
  # SELECT
514
551
  row = Person.find(:first)
@@ -533,6 +570,42 @@ if ActiveRecord::Base.connection.supports_migrations?
533
570
  assert_equal 7, wealth_column.scale
534
571
  end
535
572
 
573
+ # Test SQLite adapter specifically for decimal types with precision and scale
574
+ # attributes, since these need to be maintained in schema but aren't actually
575
+ # used in SQLite itself
576
+ if current_adapter?(:SQLite3Adapter)
577
+ def test_change_column_with_new_precision_and_scale
578
+ Person.delete_all
579
+ Person.connection.add_column 'people', 'wealth', :decimal, :precision => 9, :scale => 7
580
+ Person.reset_column_information
581
+
582
+ Person.connection.change_column 'people', 'wealth', :decimal, :precision => 12, :scale => 8
583
+ Person.reset_column_information
584
+
585
+ wealth_column = Person.columns_hash['wealth']
586
+ assert_equal 12, wealth_column.precision
587
+ assert_equal 8, wealth_column.scale
588
+ end
589
+
590
+ def test_change_column_preserve_other_column_precision_and_scale
591
+ Person.delete_all
592
+ Person.connection.add_column 'people', 'last_name', :string
593
+ Person.connection.add_column 'people', 'wealth', :decimal, :precision => 9, :scale => 7
594
+ Person.reset_column_information
595
+
596
+ wealth_column = Person.columns_hash['wealth']
597
+ assert_equal 9, wealth_column.precision
598
+ assert_equal 7, wealth_column.scale
599
+
600
+ Person.connection.change_column 'people', 'last_name', :string, :null => false
601
+ Person.reset_column_information
602
+
603
+ wealth_column = Person.columns_hash['wealth']
604
+ assert_equal 9, wealth_column.precision
605
+ assert_equal 7, wealth_column.scale
606
+ end
607
+ end
608
+
536
609
  def test_native_types
537
610
  Person.delete_all
538
611
  Person.connection.add_column "people", "last_name", :string
@@ -1036,7 +1109,7 @@ if ActiveRecord::Base.connection.supports_migrations?
1036
1109
  t.column :title, :string
1037
1110
  end
1038
1111
  person_klass = Class.new(Person)
1039
- person_klass.set_table_name 'testings'
1112
+ person_klass.table_name = 'testings'
1040
1113
 
1041
1114
  person_klass.connection.add_column "testings", "wealth", :integer, :null => false, :default => 99
1042
1115
  person_klass.reset_column_information
@@ -1276,6 +1349,24 @@ if ActiveRecord::Base.connection.supports_migrations?
1276
1349
  assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
1277
1350
  end
1278
1351
 
1352
+ def test_filtering_migrations
1353
+ assert !Person.column_methods_hash.include?(:last_name)
1354
+ assert !Reminder.table_exists?
1355
+
1356
+ name_filter = lambda { |migration| migration.name == "ValidPeopleHaveLastNames" }
1357
+ ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/valid", &name_filter)
1358
+
1359
+ Person.reset_column_information
1360
+ assert Person.column_methods_hash.include?(:last_name)
1361
+ assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
1362
+
1363
+ ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", &name_filter)
1364
+
1365
+ Person.reset_column_information
1366
+ assert !Person.column_methods_hash.include?(:last_name)
1367
+ assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
1368
+ end
1369
+
1279
1370
  class MockMigration < ActiveRecord::Migration
1280
1371
  attr_reader :went_up, :went_down
1281
1372
  def initialize
@@ -1387,6 +1478,15 @@ if ActiveRecord::Base.connection.supports_migrations?
1387
1478
  end
1388
1479
  end
1389
1480
 
1481
+ def test_finds_migrations_in_subdirectories
1482
+ migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/valid_with_subdirectories").migrations
1483
+
1484
+ [[1, 'ValidPeopleHaveLastNames'], [2, 'WeNeedReminders'], [3, 'InnocentJointable']].each_with_index do |pair, i|
1485
+ assert_equal migrations[i].version, pair.first
1486
+ assert_equal migrations[i].name, pair.last
1487
+ end
1488
+ end
1489
+
1390
1490
  def test_finds_migrations_from_two_directories
1391
1491
  directories = [MIGRATIONS_ROOT + '/valid_with_timestamps', MIGRATIONS_ROOT + '/to_copy_with_timestamps']
1392
1492
  migrations = ActiveRecord::Migrator.new(:up, directories).migrations
@@ -1401,6 +1501,15 @@ if ActiveRecord::Base.connection.supports_migrations?
1401
1501
  end
1402
1502
  end
1403
1503
 
1504
+ def test_dump_schema_information_outputs_lexically_ordered_versions
1505
+ migration_path = MIGRATIONS_ROOT + '/valid_with_timestamps'
1506
+ ActiveRecord::Migrator.run(:up, migration_path, 20100301010101)
1507
+ ActiveRecord::Migrator.run(:up, migration_path, 20100201010101)
1508
+
1509
+ schema_info = ActiveRecord::Base.connection.dump_schema_information
1510
+ assert_match(/20100201010101.*20100301010101/m, schema_info)
1511
+ end
1512
+
1404
1513
  def test_finds_pending_migrations
1405
1514
  ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/interleaved/pass_2", 1)
1406
1515
  migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/interleaved/pass_2").pending_migrations
@@ -1575,6 +1684,28 @@ if ActiveRecord::Base.connection.supports_migrations?
1575
1684
  Reminder.reset_table_name
1576
1685
  end
1577
1686
 
1687
+ def test_rename_table_with_prefix_and_suffix
1688
+ assert !Thing.table_exists?
1689
+ ActiveRecord::Base.table_name_prefix = 'prefix_'
1690
+ ActiveRecord::Base.table_name_suffix = '_suffix'
1691
+ Thing.reset_table_name
1692
+ Thing.reset_sequence_name
1693
+ WeNeedThings.up
1694
+
1695
+ assert Thing.create("content" => "hello world")
1696
+ assert_equal "hello world", Thing.find(:first).content
1697
+
1698
+ RenameThings.up
1699
+ Thing.table_name = "prefix_awesome_things_suffix"
1700
+
1701
+ assert_equal "hello world", Thing.find(:first).content
1702
+ ensure
1703
+ ActiveRecord::Base.table_name_prefix = ''
1704
+ ActiveRecord::Base.table_name_suffix = ''
1705
+ Thing.reset_table_name
1706
+ Thing.reset_sequence_name
1707
+ end
1708
+
1578
1709
  def test_add_drop_table_with_prefix_and_suffix
1579
1710
  assert !Reminder.table_exists?
1580
1711
  ActiveRecord::Base.table_name_prefix = 'prefix_'
@@ -1680,91 +1811,6 @@ if ActiveRecord::Base.connection.supports_migrations?
1680
1811
 
1681
1812
  end
1682
1813
 
1683
- class SexyMigrationsTest < ActiveRecord::TestCase
1684
- def test_references_column_type_adds_id
1685
- with_new_table do |t|
1686
- t.expects(:column).with('customer_id', :integer, {})
1687
- t.references :customer
1688
- end
1689
- end
1690
-
1691
- def test_references_column_type_with_polymorphic_adds_type
1692
- with_new_table do |t|
1693
- t.expects(:column).with('taggable_type', :string, {})
1694
- t.expects(:column).with('taggable_id', :integer, {})
1695
- t.references :taggable, :polymorphic => true
1696
- end
1697
- end
1698
-
1699
- def test_references_column_type_with_polymorphic_and_options_null_is_false_adds_table_flag
1700
- with_new_table do |t|
1701
- t.expects(:column).with('taggable_type', :string, {:null => false})
1702
- t.expects(:column).with('taggable_id', :integer, {:null => false})
1703
- t.references :taggable, :polymorphic => true, :null => false
1704
- end
1705
- end
1706
-
1707
- def test_belongs_to_works_like_references
1708
- with_new_table do |t|
1709
- t.expects(:column).with('customer_id', :integer, {})
1710
- t.belongs_to :customer
1711
- end
1712
- end
1713
-
1714
- def test_timestamps_creates_updated_at_and_created_at
1715
- with_new_table do |t|
1716
- t.expects(:column).with(:created_at, :datetime, kind_of(Hash))
1717
- t.expects(:column).with(:updated_at, :datetime, kind_of(Hash))
1718
- t.timestamps
1719
- end
1720
- end
1721
-
1722
- def test_integer_creates_integer_column
1723
- with_new_table do |t|
1724
- t.expects(:column).with(:foo, 'integer', {})
1725
- t.expects(:column).with(:bar, 'integer', {})
1726
- t.integer :foo, :bar
1727
- end
1728
- end
1729
-
1730
- def test_string_creates_string_column
1731
- with_new_table do |t|
1732
- t.expects(:column).with(:foo, 'string', {})
1733
- t.expects(:column).with(:bar, 'string', {})
1734
- t.string :foo, :bar
1735
- end
1736
- end
1737
-
1738
- if current_adapter?(:PostgreSQLAdapter) || current_adapter?(:SQLite3Adapter) || current_adapter?(:MysqlAdapter) || current_adapter?(:Mysql2Adapter) || current_adapter?(:IBM_DBAdapter)
1739
- def test_xml_creates_xml_column
1740
- type = (current_adapter?(:PostgreSQLAdapter) || current_adapter?(:IBM_DBAdapter)) ? 'xml' : :text
1741
-
1742
- with_new_table do |t|
1743
- t.expects(:column).with(:data, type, {})
1744
- t.xml :data
1745
- end
1746
- end
1747
- else
1748
- def test_xml_creates_xml_column
1749
- with_new_table do |t|
1750
- assert_raises(NotImplementedError) do
1751
- t.xml :data
1752
- end
1753
- end
1754
- end
1755
- end
1756
-
1757
- protected
1758
- def with_new_table
1759
- Person.connection.create_table :delete_me, :force => true do |t|
1760
- yield t
1761
- end
1762
- ensure
1763
- Person.connection.drop_table :delete_me rescue nil
1764
- end
1765
-
1766
- end # SexyMigrationsTest
1767
-
1768
1814
  class MigrationLoggerTest < ActiveRecord::TestCase
1769
1815
  def test_migration_should_be_run_without_logger
1770
1816
  previous_logger = ActiveRecord::Base.logger
@@ -2194,9 +2240,12 @@ if ActiveRecord::Base.connection.supports_migrations?
2194
2240
  @existing_migrations = Dir[@migrations_path + "/*.rb"]
2195
2241
 
2196
2242
  copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy"})
2197
- assert File.exists?(@migrations_path + "/4_people_have_hobbies.rb")
2198
- assert File.exists?(@migrations_path + "/5_people_have_descriptions.rb")
2199
- assert_equal [@migrations_path + "/4_people_have_hobbies.rb", @migrations_path + "/5_people_have_descriptions.rb"], copied.map(&:filename)
2243
+ assert File.exists?(@migrations_path + "/4_people_have_hobbies.bukkits.rb")
2244
+ assert File.exists?(@migrations_path + "/5_people_have_descriptions.bukkits.rb")
2245
+ assert_equal [@migrations_path + "/4_people_have_hobbies.bukkits.rb", @migrations_path + "/5_people_have_descriptions.bukkits.rb"], copied.map(&:filename)
2246
+
2247
+ expected = "# This migration comes from bukkits (originally 1)"
2248
+ assert_equal expected, IO.readlines(@migrations_path + "/4_people_have_hobbies.bukkits.rb")[0].chomp
2200
2249
 
2201
2250
  files_count = Dir[@migrations_path + "/*.rb"].length
2202
2251
  copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy"})
@@ -2215,10 +2264,10 @@ if ActiveRecord::Base.connection.supports_migrations?
2215
2264
  sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy"
2216
2265
  sources[:omg] = MIGRATIONS_ROOT + "/to_copy2"
2217
2266
  ActiveRecord::Migration.copy(@migrations_path, sources)
2218
- assert File.exists?(@migrations_path + "/4_people_have_hobbies.rb")
2219
- assert File.exists?(@migrations_path + "/5_people_have_descriptions.rb")
2220
- assert File.exists?(@migrations_path + "/6_create_articles.rb")
2221
- assert File.exists?(@migrations_path + "/7_create_comments.rb")
2267
+ assert File.exists?(@migrations_path + "/4_people_have_hobbies.bukkits.rb")
2268
+ assert File.exists?(@migrations_path + "/5_people_have_descriptions.bukkits.rb")
2269
+ assert File.exists?(@migrations_path + "/6_create_articles.omg.rb")
2270
+ assert File.exists?(@migrations_path + "/7_create_comments.omg.rb")
2222
2271
 
2223
2272
  files_count = Dir[@migrations_path + "/*.rb"].length
2224
2273
  ActiveRecord::Migration.copy(@migrations_path, sources)
@@ -2233,10 +2282,10 @@ if ActiveRecord::Base.connection.supports_migrations?
2233
2282
 
2234
2283
  Time.travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
2235
2284
  copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
2236
- assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.rb")
2237
- assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.rb")
2238
- expected = [@migrations_path + "/20100726101010_people_have_hobbies.rb",
2239
- @migrations_path + "/20100726101011_people_have_descriptions.rb"]
2285
+ assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
2286
+ assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
2287
+ expected = [@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb",
2288
+ @migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb"]
2240
2289
  assert_equal expected, copied.map(&:filename)
2241
2290
 
2242
2291
  files_count = Dir[@migrations_path + "/*.rb"].length
@@ -2258,10 +2307,10 @@ if ActiveRecord::Base.connection.supports_migrations?
2258
2307
 
2259
2308
  Time.travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
2260
2309
  copied = ActiveRecord::Migration.copy(@migrations_path, sources)
2261
- assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.rb")
2262
- assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.rb")
2263
- assert File.exists?(@migrations_path + "/20100726101012_create_articles.rb")
2264
- assert File.exists?(@migrations_path + "/20100726101013_create_comments.rb")
2310
+ assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
2311
+ assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
2312
+ assert File.exists?(@migrations_path + "/20100726101012_create_articles.omg.rb")
2313
+ assert File.exists?(@migrations_path + "/20100726101013_create_comments.omg.rb")
2265
2314
  assert_equal 4, copied.length
2266
2315
 
2267
2316
  files_count = Dir[@migrations_path + "/*.rb"].length
@@ -2278,8 +2327,8 @@ if ActiveRecord::Base.connection.supports_migrations?
2278
2327
 
2279
2328
  Time.travel_to(Time.utc(2010, 2, 20, 10, 10, 10)) do
2280
2329
  ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
2281
- assert File.exists?(@migrations_path + "/20100301010102_people_have_hobbies.rb")
2282
- assert File.exists?(@migrations_path + "/20100301010103_people_have_descriptions.rb")
2330
+ assert File.exists?(@migrations_path + "/20100301010102_people_have_hobbies.bukkits.rb")
2331
+ assert File.exists?(@migrations_path + "/20100301010103_people_have_descriptions.bukkits.rb")
2283
2332
 
2284
2333
  files_count = Dir[@migrations_path + "/*.rb"].length
2285
2334
  copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
@@ -2295,15 +2344,34 @@ if ActiveRecord::Base.connection.supports_migrations?
2295
2344
  @existing_migrations = Dir[@migrations_path + "/*.rb"]
2296
2345
 
2297
2346
  sources = ActiveSupport::OrderedHash.new
2298
- sources[:bukkits] = sources[:omg] = MIGRATIONS_ROOT + "/to_copy_with_timestamps"
2347
+ sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy_with_timestamps"
2348
+ sources[:omg] = MIGRATIONS_ROOT + "/to_copy_with_name_collision"
2299
2349
 
2300
2350
  skipped = []
2301
2351
  on_skip = Proc.new { |name, migration| skipped << "#{name} #{migration.name}" }
2302
2352
  copied = ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip)
2303
2353
  assert_equal 2, copied.length
2304
2354
 
2305
- assert_equal 2, skipped.length
2306
- assert_equal ["bukkits PeopleHaveHobbies", "bukkits PeopleHaveDescriptions"], skipped
2355
+ assert_equal 1, skipped.length
2356
+ assert_equal ["omg PeopleHaveHobbies"], skipped
2357
+ ensure
2358
+ clear
2359
+ end
2360
+
2361
+ def test_skip_is_not_called_if_migrations_are_from_the_same_plugin
2362
+ @migrations_path = MIGRATIONS_ROOT + "/valid_with_timestamps"
2363
+ @existing_migrations = Dir[@migrations_path + "/*.rb"]
2364
+
2365
+ sources = ActiveSupport::OrderedHash.new
2366
+ sources[:bukkits] = MIGRATIONS_ROOT + "/to_copy_with_timestamps"
2367
+
2368
+ skipped = []
2369
+ on_skip = Proc.new { |name, migration| skipped << "#{name} #{migration.name}" }
2370
+ copied = ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip)
2371
+ ActiveRecord::Migration.copy(@migrations_path, sources, :on_skip => on_skip)
2372
+
2373
+ assert_equal 2, copied.length
2374
+ assert_equal 0, skipped.length
2307
2375
  ensure
2308
2376
  clear
2309
2377
  end
@@ -2314,8 +2382,8 @@ if ActiveRecord::Base.connection.supports_migrations?
2314
2382
 
2315
2383
  Time.travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
2316
2384
  copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
2317
- assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.rb")
2318
- assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.rb")
2385
+ assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
2386
+ assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
2319
2387
  assert_equal 2, copied.length
2320
2388
  end
2321
2389
  ensure
@@ -2329,8 +2397,8 @@ if ActiveRecord::Base.connection.supports_migrations?
2329
2397
 
2330
2398
  Time.travel_to(Time.utc(2010, 7, 26, 10, 10, 10)) do
2331
2399
  copied = ActiveRecord::Migration.copy(@migrations_path, {:bukkits => MIGRATIONS_ROOT + "/to_copy_with_timestamps"})
2332
- assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.rb")
2333
- assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.rb")
2400
+ assert File.exists?(@migrations_path + "/20100726101010_people_have_hobbies.bukkits.rb")
2401
+ assert File.exists?(@migrations_path + "/20100726101011_people_have_descriptions.bukkits.rb")
2334
2402
  assert_equal 2, copied.length
2335
2403
  end
2336
2404
  ensure