activerecord 2.2.3 → 2.3.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (120) hide show
  1. data/CHANGELOG +438 -396
  2. data/Rakefile +4 -2
  3. data/lib/active_record.rb +46 -43
  4. data/lib/active_record/association_preload.rb +34 -19
  5. data/lib/active_record/associations.rb +193 -251
  6. data/lib/active_record/associations/association_collection.rb +38 -21
  7. data/lib/active_record/associations/association_proxy.rb +11 -4
  8. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +2 -2
  9. data/lib/active_record/associations/has_many_association.rb +2 -2
  10. data/lib/active_record/associations/has_many_through_association.rb +8 -8
  11. data/lib/active_record/associations/has_one_association.rb +11 -2
  12. data/lib/active_record/attribute_methods.rb +1 -0
  13. data/lib/active_record/autosave_association.rb +349 -0
  14. data/lib/active_record/base.rb +292 -106
  15. data/lib/active_record/batches.rb +73 -0
  16. data/lib/active_record/calculations.rb +34 -16
  17. data/lib/active_record/callbacks.rb +37 -8
  18. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +16 -0
  19. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +3 -0
  20. data/lib/active_record/connection_adapters/abstract/database_statements.rb +103 -15
  21. data/lib/active_record/connection_adapters/abstract/query_cache.rb +6 -6
  22. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +28 -25
  23. data/lib/active_record/connection_adapters/abstract_adapter.rb +29 -5
  24. data/lib/active_record/connection_adapters/mysql_adapter.rb +50 -21
  25. data/lib/active_record/connection_adapters/postgresql_adapter.rb +26 -41
  26. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -1
  27. data/lib/active_record/connection_adapters/sqlite_adapter.rb +41 -21
  28. data/lib/active_record/dirty.rb +1 -1
  29. data/lib/active_record/dynamic_scope_match.rb +25 -0
  30. data/lib/active_record/fixtures.rb +193 -198
  31. data/lib/active_record/locale/en.yml +1 -1
  32. data/lib/active_record/locking/optimistic.rb +33 -0
  33. data/lib/active_record/migration.rb +8 -2
  34. data/lib/active_record/named_scope.rb +13 -6
  35. data/lib/active_record/nested_attributes.rb +329 -0
  36. data/lib/active_record/query_cache.rb +25 -13
  37. data/lib/active_record/reflection.rb +6 -1
  38. data/lib/active_record/schema_dumper.rb +2 -0
  39. data/lib/active_record/serialization.rb +3 -1
  40. data/lib/active_record/serializers/json_serializer.rb +19 -0
  41. data/lib/active_record/serializers/xml_serializer.rb +28 -13
  42. data/lib/active_record/session_store.rb +318 -0
  43. data/lib/active_record/test_case.rb +15 -9
  44. data/lib/active_record/timestamp.rb +2 -2
  45. data/lib/active_record/transactions.rb +58 -8
  46. data/lib/active_record/validations.rb +29 -24
  47. data/lib/active_record/version.rb +2 -2
  48. data/test/cases/ar_schema_test.rb +0 -1
  49. data/test/cases/associations/belongs_to_associations_test.rb +35 -131
  50. data/test/cases/associations/cascaded_eager_loading_test.rb +8 -0
  51. data/test/cases/associations/eager_load_nested_include_test.rb +29 -0
  52. data/test/cases/associations/eager_test.rb +137 -7
  53. data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +45 -7
  54. data/test/cases/associations/has_many_associations_test.rb +110 -149
  55. data/test/cases/associations/has_many_through_associations_test.rb +39 -7
  56. data/test/cases/associations/has_one_associations_test.rb +39 -92
  57. data/test/cases/associations/has_one_through_associations_test.rb +34 -3
  58. data/test/cases/associations/inner_join_association_test.rb +0 -5
  59. data/test/cases/associations/join_model_test.rb +5 -7
  60. data/test/cases/attribute_methods_test.rb +13 -1
  61. data/test/cases/autosave_association_test.rb +901 -0
  62. data/test/cases/base_test.rb +41 -21
  63. data/test/cases/batches_test.rb +61 -0
  64. data/test/cases/calculations_test.rb +37 -17
  65. data/test/cases/callbacks_test.rb +43 -5
  66. data/test/cases/connection_pool_test.rb +25 -0
  67. data/test/cases/copy_table_test_sqlite.rb +11 -0
  68. data/test/cases/datatype_test_postgresql.rb +1 -0
  69. data/test/cases/defaults_test.rb +37 -26
  70. data/test/cases/dirty_test.rb +26 -2
  71. data/test/cases/finder_test.rb +79 -44
  72. data/test/cases/fixtures_test.rb +15 -19
  73. data/test/cases/helper.rb +26 -19
  74. data/test/cases/inheritance_test.rb +2 -2
  75. data/test/cases/json_serialization_test.rb +1 -1
  76. data/test/cases/locking_test.rb +23 -5
  77. data/test/cases/method_scoping_test.rb +126 -3
  78. data/test/cases/migration_test.rb +253 -237
  79. data/test/cases/named_scope_test.rb +73 -3
  80. data/test/cases/nested_attributes_test.rb +509 -0
  81. data/test/cases/query_cache_test.rb +0 -4
  82. data/test/cases/reflection_test.rb +13 -3
  83. data/test/cases/reload_models_test.rb +3 -1
  84. data/test/cases/repair_helper.rb +50 -0
  85. data/test/cases/schema_dumper_test.rb +0 -1
  86. data/test/cases/transactions_test.rb +177 -12
  87. data/test/cases/validations_i18n_test.rb +288 -294
  88. data/test/cases/validations_test.rb +230 -180
  89. data/test/cases/xml_serialization_test.rb +19 -1
  90. data/test/fixtures/fixture_database.sqlite3 +0 -0
  91. data/test/fixtures/fixture_database_2.sqlite3 +0 -0
  92. data/test/fixtures/member_types.yml +6 -0
  93. data/test/fixtures/members.yml +3 -1
  94. data/test/fixtures/people.yml +10 -1
  95. data/test/fixtures/toys.yml +4 -0
  96. data/test/models/author.rb +1 -2
  97. data/test/models/bird.rb +3 -0
  98. data/test/models/category.rb +1 -0
  99. data/test/models/company.rb +3 -0
  100. data/test/models/developer.rb +12 -0
  101. data/test/models/event.rb +3 -0
  102. data/test/models/member.rb +1 -0
  103. data/test/models/member_detail.rb +1 -0
  104. data/test/models/member_type.rb +3 -0
  105. data/test/models/owner.rb +2 -1
  106. data/test/models/parrot.rb +2 -0
  107. data/test/models/person.rb +6 -0
  108. data/test/models/pet.rb +2 -1
  109. data/test/models/pirate.rb +55 -1
  110. data/test/models/post.rb +6 -0
  111. data/test/models/project.rb +1 -0
  112. data/test/models/reply.rb +6 -0
  113. data/test/models/ship.rb +8 -1
  114. data/test/models/ship_part.rb +5 -0
  115. data/test/models/topic.rb +13 -1
  116. data/test/models/toy.rb +4 -0
  117. data/test/schema/schema.rb +35 -2
  118. metadata +70 -9
  119. data/test/fixtures/fixture_database.sqlite +0 -0
  120. data/test/fixtures/fixture_database_2.sqlite +0 -0
@@ -68,7 +68,7 @@ class InheritanceTest < ActiveRecord::TestCase
68
68
  if current_adapter?(:SybaseAdapter)
69
69
  Company.connection.execute "SET IDENTITY_INSERT companies OFF"
70
70
  end
71
- assert_raises(ActiveRecord::SubclassNotFound) { Company.find(100) }
71
+ assert_raise(ActiveRecord::SubclassNotFound) { Company.find(100) }
72
72
  end
73
73
 
74
74
  def test_inheritance_find
@@ -124,7 +124,7 @@ class InheritanceTest < ActiveRecord::TestCase
124
124
  end
125
125
 
126
126
  def test_finding_incorrect_type_data
127
- assert_raises(ActiveRecord::RecordNotFound) { Firm.find(2) }
127
+ assert_raise(ActiveRecord::RecordNotFound) { Firm.find(2) }
128
128
  assert_nothing_raised { Firm.find(1) }
129
129
  end
130
130
 
@@ -200,6 +200,6 @@ class DatabaseConnectedJsonEncodingTest < ActiveRecord::TestCase
200
200
  2 => @mary
201
201
  }
202
202
 
203
- assert_equal %({1: {"name": "David"}}), authors_hash.to_json(:only => [1, :name])
203
+ assert_equal %({"1": {"name": "David"}}), authors_hash.to_json(:only => [1, :name])
204
204
  end
205
205
  end
@@ -35,7 +35,25 @@ class OptimisticLockingTest < ActiveRecord::TestCase
35
35
  assert_equal 0, p2.lock_version
36
36
 
37
37
  p2.first_name = 'sue'
38
- assert_raises(ActiveRecord::StaleObjectError) { p2.save! }
38
+ assert_raise(ActiveRecord::StaleObjectError) { p2.save! }
39
+ end
40
+
41
+ def test_lock_destroy
42
+ p1 = Person.find(1)
43
+ p2 = Person.find(1)
44
+ assert_equal 0, p1.lock_version
45
+ assert_equal 0, p2.lock_version
46
+
47
+ p1.first_name = 'stu'
48
+ p1.save!
49
+ assert_equal 1, p1.lock_version
50
+ assert_equal 0, p2.lock_version
51
+
52
+ assert_raises(ActiveRecord::StaleObjectError) { p2.destroy }
53
+
54
+ assert p1.destroy
55
+ assert_equal true, p1.frozen?
56
+ assert_raises(ActiveRecord::RecordNotFound) { Person.find(1) }
39
57
  end
40
58
 
41
59
  def test_lock_repeating
@@ -50,9 +68,9 @@ class OptimisticLockingTest < ActiveRecord::TestCase
50
68
  assert_equal 0, p2.lock_version
51
69
 
52
70
  p2.first_name = 'sue'
53
- assert_raises(ActiveRecord::StaleObjectError) { p2.save! }
71
+ assert_raise(ActiveRecord::StaleObjectError) { p2.save! }
54
72
  p2.first_name = 'sue2'
55
- assert_raises(ActiveRecord::StaleObjectError) { p2.save! }
73
+ assert_raise(ActiveRecord::StaleObjectError) { p2.save! }
56
74
  end
57
75
 
58
76
  def test_lock_new
@@ -71,7 +89,7 @@ class OptimisticLockingTest < ActiveRecord::TestCase
71
89
  assert_equal 0, p2.lock_version
72
90
 
73
91
  p2.first_name = 'sue'
74
- assert_raises(ActiveRecord::StaleObjectError) { p2.save! }
92
+ assert_raise(ActiveRecord::StaleObjectError) { p2.save! }
75
93
  end
76
94
 
77
95
  def test_lock_new_with_nil
@@ -95,7 +113,7 @@ class OptimisticLockingTest < ActiveRecord::TestCase
95
113
  assert_equal 0, t2.version
96
114
 
97
115
  t2.tps_report_number = 800
98
- assert_raises(ActiveRecord::StaleObjectError) { t2.save! }
116
+ assert_raise(ActiveRecord::StaleObjectError) { t2.save! }
99
117
  end
100
118
 
101
119
  def test_lock_column_is_mass_assignable
@@ -27,6 +27,24 @@ class MethodScopingTest < ActiveRecord::TestCase
27
27
  end
28
28
  end
29
29
 
30
+ def test_scoped_find_last
31
+ highest_salary = Developer.find(:first, :order => "salary DESC")
32
+
33
+ Developer.with_scope(:find => { :order => "salary" }) do
34
+ assert_equal highest_salary, Developer.last
35
+ end
36
+ end
37
+
38
+ def test_scoped_find_last_preserves_scope
39
+ lowest_salary = Developer.find(:first, :order => "salary ASC")
40
+ highest_salary = Developer.find(:first, :order => "salary DESC")
41
+
42
+ Developer.with_scope(:find => { :order => "salary" }) do
43
+ assert_equal highest_salary, Developer.last
44
+ assert_equal lowest_salary, Developer.first
45
+ end
46
+ end
47
+
30
48
  def test_scoped_find_combines_conditions
31
49
  Developer.with_scope(:find => { :conditions => "salary = 9000" }) do
32
50
  assert_equal developers(:poor_jamis), Developer.find(:first, :conditions => "name = 'Jamis'")
@@ -168,6 +186,16 @@ class MethodScopingTest < ActiveRecord::TestCase
168
186
  assert_equal authors(:david).attributes, scoped_authors.first.attributes
169
187
  end
170
188
 
189
+ def test_scoped_find_strips_spaces_from_string_joins_and_eliminates_duplicate_string_joins
190
+ scoped_authors = Author.with_scope(:find => { :joins => ' INNER JOIN posts ON posts.author_id = authors.id '}) do
191
+ Author.find(:all, :select => 'DISTINCT authors.*', :joins => ['INNER JOIN posts ON posts.author_id = authors.id'], :conditions => 'posts.id = 1')
192
+ end
193
+ assert scoped_authors.include?(authors(:david))
194
+ assert !scoped_authors.include?(authors(:mary))
195
+ assert_equal 1, scoped_authors.size
196
+ assert_equal authors(:david).attributes, scoped_authors.first.attributes
197
+ end
198
+
171
199
  def test_scoped_count_include
172
200
  # with the include, will retrieve only developers for the given project
173
201
  Developer.with_scope(:find => { :include => :projects }) do
@@ -234,6 +262,15 @@ class NestedScopingTest < ActiveRecord::TestCase
234
262
  end
235
263
  end
236
264
 
265
+ def test_merge_inner_scope_has_priority
266
+ Developer.with_scope(:find => { :limit => 5 }) do
267
+ Developer.with_scope(:find => { :limit => 10 }) do
268
+ merged_option = Developer.instance_eval('current_scoped_methods')[:find]
269
+ assert_equal({ :limit => 10 }, merged_option)
270
+ end
271
+ end
272
+ end
273
+
237
274
  def test_replace_options
238
275
  Developer.with_scope(:find => { :conditions => "name = 'David'" }) do
239
276
  Developer.with_exclusive_scope(:find => { :conditions => "name = 'Jamis'" }) do
@@ -374,6 +411,29 @@ class NestedScopingTest < ActiveRecord::TestCase
374
411
  end
375
412
  end
376
413
 
414
+ def test_nested_scoped_create
415
+ comment = nil
416
+ Comment.with_scope(:create => { :post_id => 1}) do
417
+ Comment.with_scope(:create => { :post_id => 2}) do
418
+ assert_equal({ :post_id => 2 }, Comment.send(:current_scoped_methods)[:create])
419
+ comment = Comment.create :body => "Hey guys, nested scopes are broken. Please fix!"
420
+ end
421
+ end
422
+ assert_equal 2, comment.post_id
423
+ end
424
+
425
+ def test_nested_exclusive_scope_for_create
426
+ comment = nil
427
+ Comment.with_scope(:create => { :body => "Hey guys, nested scopes are broken. Please fix!" }) do
428
+ Comment.with_exclusive_scope(:create => { :post_id => 1 }) do
429
+ assert_equal({ :post_id => 1 }, Comment.send(:current_scoped_methods)[:create])
430
+ comment = Comment.create :body => "Hey guys"
431
+ end
432
+ end
433
+ assert_equal 1, comment.post_id
434
+ assert_equal 'Hey guys', comment.body
435
+ end
436
+
377
437
  def test_merged_scoped_find_on_blank_conditions
378
438
  [nil, " ", [], {}].each do |blank|
379
439
  Developer.with_scope(:find => {:conditions => blank}) do
@@ -497,7 +557,6 @@ class HasManyScopingTest< ActiveRecord::TestCase
497
557
  end
498
558
  end
499
559
 
500
-
501
560
  class HasAndBelongsToManyScopingTest< ActiveRecord::TestCase
502
561
  fixtures :posts, :categories, :categories_posts
503
562
 
@@ -523,11 +582,76 @@ class HasAndBelongsToManyScopingTest< ActiveRecord::TestCase
523
582
  end
524
583
  end
525
584
 
585
+ class DefaultScopingTest < ActiveRecord::TestCase
586
+ fixtures :developers
587
+
588
+ def test_default_scope
589
+ expected = Developer.find(:all, :order => 'salary DESC').collect { |dev| dev.salary }
590
+ received = DeveloperOrderedBySalary.find(:all).collect { |dev| dev.salary }
591
+ assert_equal expected, received
592
+ end
593
+
594
+ def test_default_scoping_with_threads
595
+ scope = [{ :create => {}, :find => { :order => 'salary DESC' } }]
596
+
597
+ 2.times do
598
+ Thread.new { assert_equal scope, DeveloperOrderedBySalary.send(:scoped_methods) }.join
599
+ end
600
+ end
601
+
602
+ def test_default_scoping_with_inheritance
603
+ scope = [{ :create => {}, :find => { :order => 'salary DESC' } }]
604
+
605
+ # Inherit a class having a default scope and define a new default scope
606
+ klass = Class.new(DeveloperOrderedBySalary)
607
+ klass.send :default_scope, {}
608
+
609
+ # Scopes added on children should append to parent scope
610
+ expected_klass_scope = [{ :create => {}, :find => { :order => 'salary DESC' }}, { :create => {}, :find => {} }]
611
+ assert_equal expected_klass_scope, klass.send(:scoped_methods)
612
+
613
+ # Parent should still have the original scope
614
+ assert_equal scope, DeveloperOrderedBySalary.send(:scoped_methods)
615
+ end
616
+
617
+ def test_method_scope
618
+ expected = Developer.find(:all, :order => 'name DESC').collect { |dev| dev.salary }
619
+ received = DeveloperOrderedBySalary.all_ordered_by_name.collect { |dev| dev.salary }
620
+ assert_equal expected, received
621
+ end
622
+
623
+ def test_nested_scope
624
+ expected = Developer.find(:all, :order => 'name DESC').collect { |dev| dev.salary }
625
+ received = DeveloperOrderedBySalary.with_scope(:find => { :order => 'name DESC'}) do
626
+ DeveloperOrderedBySalary.find(:all).collect { |dev| dev.salary }
627
+ end
628
+ assert_equal expected, received
629
+ end
630
+
631
+ def test_named_scope
632
+ expected = Developer.find(:all, :order => 'salary DESC, name DESC').collect { |dev| dev.salary }
633
+ received = DeveloperOrderedBySalary.by_name.find(:all).collect { |dev| dev.salary }
634
+ assert_equal expected, received
635
+ end
636
+
637
+ def test_nested_exclusive_scope
638
+ expected = Developer.find(:all, :limit => 100).collect { |dev| dev.salary }
639
+ received = DeveloperOrderedBySalary.with_exclusive_scope(:find => { :limit => 100 }) do
640
+ DeveloperOrderedBySalary.find(:all).collect { |dev| dev.salary }
641
+ end
642
+ assert_equal expected, received
643
+ end
644
+
645
+ def test_overwriting_default_scope
646
+ expected = Developer.find(:all, :order => 'salary').collect { |dev| dev.salary }
647
+ received = DeveloperOrderedBySalary.find(:all, :order => 'salary').collect { |dev| dev.salary }
648
+ assert_equal expected, received
649
+ end
650
+ end
526
651
 
527
652
  =begin
528
653
  # We disabled the scoping for has_one and belongs_to as we can't think of a proper use case
529
654
 
530
-
531
655
  class BelongsToScopingTest< ActiveRecord::TestCase
532
656
  fixtures :comments, :posts
533
657
 
@@ -547,7 +671,6 @@ class BelongsToScopingTest< ActiveRecord::TestCase
547
671
 
548
672
  end
549
673
 
550
-
551
674
  class HasOneScopingTest< ActiveRecord::TestCase
552
675
  fixtures :comments, :posts
553
676
 
@@ -93,6 +93,30 @@ if ActiveRecord::Base.connection.supports_migrations?
93
93
  end
94
94
  end
95
95
 
96
+ def testing_table_with_only_foo_attribute
97
+ Person.connection.create_table :testings, :id => false do |t|
98
+ t.column :foo, :string
99
+ end
100
+
101
+ yield Person.connection
102
+ ensure
103
+ Person.connection.drop_table :testings rescue nil
104
+ end
105
+ protected :testing_table_with_only_foo_attribute
106
+
107
+ def test_create_table_without_id
108
+ testing_table_with_only_foo_attribute do |connection|
109
+ assert_equal connection.columns(:testings).size, 1
110
+ end
111
+ end
112
+
113
+ def test_add_column_with_primary_key_attribute
114
+ testing_table_with_only_foo_attribute do |connection|
115
+ assert_nothing_raised { connection.add_column :testings, :id, :primary_key }
116
+ assert_equal connection.columns(:testings).size, 2
117
+ end
118
+ end
119
+
96
120
  def test_create_table_adds_id
97
121
  Person.connection.create_table :testings do |t|
98
122
  t.column :foo, :string
@@ -111,7 +135,7 @@ if ActiveRecord::Base.connection.supports_migrations?
111
135
  end
112
136
  end
113
137
 
114
- assert_raises(ActiveRecord::StatementInvalid) do
138
+ assert_raise(ActiveRecord::StatementInvalid) do
115
139
  Person.connection.execute "insert into testings (foo) values (NULL)"
116
140
  end
117
141
  ensure
@@ -219,22 +243,20 @@ if ActiveRecord::Base.connection.supports_migrations?
219
243
  ActiveRecord::Base.primary_key_prefix_type = nil
220
244
  end
221
245
 
222
- uses_mocha('test_create_table_with_force_true_does_not_drop_nonexisting_table') do
223
- def test_create_table_with_force_true_does_not_drop_nonexisting_table
224
- if Person.connection.table_exists?(:testings2)
225
- Person.connection.drop_table :testings2
226
- end
246
+ def test_create_table_with_force_true_does_not_drop_nonexisting_table
247
+ if Person.connection.table_exists?(:testings2)
248
+ Person.connection.drop_table :testings2
249
+ end
227
250
 
228
- # using a copy as we need the drop_table method to
229
- # continue to work for the ensure block of the test
230
- temp_conn = Person.connection.dup
231
- temp_conn.expects(:drop_table).never
232
- temp_conn.create_table :testings2, :force => true do |t|
233
- t.column :foo, :string
234
- end
235
- ensure
236
- Person.connection.drop_table :testings2 rescue nil
251
+ # using a copy as we need the drop_table method to
252
+ # continue to work for the ensure block of the test
253
+ temp_conn = Person.connection.dup
254
+ temp_conn.expects(:drop_table).never
255
+ temp_conn.create_table :testings2, :force => true do |t|
256
+ t.column :foo, :string
237
257
  end
258
+ ensure
259
+ Person.connection.drop_table :testings2 rescue nil
238
260
  end
239
261
 
240
262
  def test_create_table_with_timestamps_should_create_datetime_columns
@@ -280,7 +302,7 @@ if ActiveRecord::Base.connection.supports_migrations?
280
302
  end
281
303
  Person.connection.add_column :testings, :bar, :string, :null => false
282
304
 
283
- assert_raises(ActiveRecord::StatementInvalid) do
305
+ assert_raise(ActiveRecord::StatementInvalid) do
284
306
  Person.connection.execute "insert into testings (foo, bar) values ('hello', NULL)"
285
307
  end
286
308
  ensure
@@ -299,7 +321,7 @@ if ActiveRecord::Base.connection.supports_migrations?
299
321
  Person.connection.enable_identity_insert("testings", false) if current_adapter?(:SybaseAdapter)
300
322
  assert_nothing_raised {Person.connection.add_column :testings, :bar, :string, :null => false, :default => "default" }
301
323
 
302
- assert_raises(ActiveRecord::StatementInvalid) do
324
+ assert_raise(ActiveRecord::StatementInvalid) do
303
325
  unless current_adapter?(:OpenBaseAdapter)
304
326
  Person.connection.execute "insert into testings (#{con.quote_column_name('id')}, #{con.quote_column_name('foo')}, #{con.quote_column_name('bar')}) values (2, 'hello', NULL)"
305
327
  else
@@ -547,7 +569,7 @@ if ActiveRecord::Base.connection.supports_migrations?
547
569
  else
548
570
  ActiveRecord::ActiveRecordError
549
571
  end
550
- assert_raises(exception) do
572
+ assert_raise(exception) do
551
573
  Person.connection.rename_column "hats", "nonexistent", "should_fail"
552
574
  end
553
575
  ensure
@@ -797,7 +819,7 @@ if ActiveRecord::Base.connection.supports_migrations?
797
819
  assert_equal "hello world", Reminder.find(:first).content
798
820
 
799
821
  WeNeedReminders.down
800
- assert_raises(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
822
+ assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
801
823
  end
802
824
 
803
825
  def test_add_table_with_decimals
@@ -858,7 +880,7 @@ if ActiveRecord::Base.connection.supports_migrations?
858
880
  end
859
881
 
860
882
  GiveMeBigNumbers.down
861
- assert_raises(ActiveRecord::StatementInvalid) { BigNumber.find(:first) }
883
+ assert_raise(ActiveRecord::StatementInvalid) { BigNumber.find(:first) }
862
884
  end
863
885
 
864
886
  def test_migrator
@@ -878,7 +900,7 @@ if ActiveRecord::Base.connection.supports_migrations?
878
900
  assert_equal 0, ActiveRecord::Migrator.current_version
879
901
  Person.reset_column_information
880
902
  assert !Person.column_methods_hash.include?(:last_name)
881
- assert_raises(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
903
+ assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
882
904
  end
883
905
 
884
906
  def test_migrator_one_up
@@ -930,11 +952,11 @@ if ActiveRecord::Base.connection.supports_migrations?
930
952
  assert_equal(0, ActiveRecord::Migrator.current_version)
931
953
  end
932
954
 
933
- if current_adapter?(:PostgreSQLAdapter)
955
+ if ActiveRecord::Base.connection.supports_ddl_transactions?
934
956
  def test_migrator_one_up_with_exception_and_rollback
935
957
  assert !Person.column_methods_hash.include?(:last_name)
936
958
 
937
- e = assert_raises(StandardError) do
959
+ e = assert_raise(StandardError) do
938
960
  ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/broken", 100)
939
961
  end
940
962
 
@@ -947,20 +969,20 @@ if ActiveRecord::Base.connection.supports_migrations?
947
969
 
948
970
  def test_finds_migrations
949
971
  migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/valid").migrations
950
- [['1', 'people_have_last_names'],
951
- ['2', 'we_need_reminders'],
952
- ['3', 'innocent_jointable']].each_with_index do |pair, i|
953
- migrations[i].version == pair.first
954
- migrations[1].name == pair.last
972
+
973
+ [[1, 'PeopleHaveLastNames'], [2, 'WeNeedReminders'], [3, 'InnocentJointable']].each_with_index do |pair, i|
974
+ assert_equal migrations[i].version, pair.first
975
+ assert_equal migrations[i].name, pair.last
955
976
  end
956
977
  end
957
978
 
958
979
  def test_finds_pending_migrations
959
980
  ActiveRecord::Migrator.up(MIGRATIONS_ROOT + "/interleaved/pass_2", 1)
960
981
  migrations = ActiveRecord::Migrator.new(:up, MIGRATIONS_ROOT + "/interleaved/pass_2").pending_migrations
982
+
961
983
  assert_equal 1, migrations.size
962
- migrations[0].version == '3'
963
- migrations[0].name == 'innocent_jointable'
984
+ assert_equal migrations[0].version, 3
985
+ assert_equal migrations[0].name, 'InnocentJointable'
964
986
  end
965
987
 
966
988
  def test_only_loads_pending_migrations
@@ -1109,7 +1131,7 @@ if ActiveRecord::Base.connection.supports_migrations?
1109
1131
  assert_equal "hello world", Reminder.find(:first).content
1110
1132
 
1111
1133
  WeNeedReminders.down
1112
- assert_raises(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
1134
+ assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
1113
1135
  ensure
1114
1136
  ActiveRecord::Base.table_name_prefix = ''
1115
1137
  ActiveRecord::Base.table_name_suffix = ''
@@ -1139,13 +1161,13 @@ if ActiveRecord::Base.connection.supports_migrations?
1139
1161
  end
1140
1162
 
1141
1163
  def test_migrator_with_duplicates
1142
- assert_raises(ActiveRecord::DuplicateMigrationVersionError) do
1164
+ assert_raise(ActiveRecord::DuplicateMigrationVersionError) do
1143
1165
  ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/duplicate", nil)
1144
1166
  end
1145
1167
  end
1146
1168
 
1147
1169
  def test_migrator_with_duplicate_names
1148
- assert_raises(ActiveRecord::DuplicateMigrationNameError, "Multiple migrations have the name Chunky") do
1170
+ assert_raise(ActiveRecord::DuplicateMigrationNameError, "Multiple migrations have the name Chunky") do
1149
1171
  ActiveRecord::Migrator.migrate(MIGRATIONS_ROOT + "/duplicate_names", nil)
1150
1172
  end
1151
1173
  end
@@ -1161,7 +1183,7 @@ if ActiveRecord::Base.connection.supports_migrations?
1161
1183
 
1162
1184
  # table name is 29 chars, the standard sequence name will
1163
1185
  # be 33 chars and fail
1164
- assert_raises(ActiveRecord::StatementInvalid) do
1186
+ assert_raise(ActiveRecord::StatementInvalid) do
1165
1187
  begin
1166
1188
  Person.connection.create_table :table_with_name_thats_just_ok do |t|
1167
1189
  t.column :foo, :string, :null => false
@@ -1188,7 +1210,7 @@ if ActiveRecord::Base.connection.supports_migrations?
1188
1210
  end
1189
1211
 
1190
1212
  # confirm the custom sequence got dropped
1191
- assert_raises(ActiveRecord::StatementInvalid) do
1213
+ assert_raise(ActiveRecord::StatementInvalid) do
1192
1214
  Person.connection.execute("select suitably_short_seq.nextval from dual")
1193
1215
  end
1194
1216
  end
@@ -1203,277 +1225,271 @@ if ActiveRecord::Base.connection.supports_migrations?
1203
1225
 
1204
1226
  end
1205
1227
 
1206
- uses_mocha 'Sexy migration tests' do
1207
- class SexyMigrationsTest < ActiveRecord::TestCase
1208
- def test_references_column_type_adds_id
1209
- with_new_table do |t|
1210
- t.expects(:column).with('customer_id', :integer, {})
1211
- t.references :customer
1212
- end
1228
+ class SexyMigrationsTest < ActiveRecord::TestCase
1229
+ def test_references_column_type_adds_id
1230
+ with_new_table do |t|
1231
+ t.expects(:column).with('customer_id', :integer, {})
1232
+ t.references :customer
1213
1233
  end
1234
+ end
1214
1235
 
1215
- def test_references_column_type_with_polymorphic_adds_type
1216
- with_new_table do |t|
1217
- t.expects(:column).with('taggable_type', :string, {})
1218
- t.expects(:column).with('taggable_id', :integer, {})
1219
- t.references :taggable, :polymorphic => true
1220
- end
1236
+ def test_references_column_type_with_polymorphic_adds_type
1237
+ with_new_table do |t|
1238
+ t.expects(:column).with('taggable_type', :string, {})
1239
+ t.expects(:column).with('taggable_id', :integer, {})
1240
+ t.references :taggable, :polymorphic => true
1221
1241
  end
1242
+ end
1222
1243
 
1223
- def test_references_column_type_with_polymorphic_and_options_null_is_false_adds_table_flag
1224
- with_new_table do |t|
1225
- t.expects(:column).with('taggable_type', :string, {:null => false})
1226
- t.expects(:column).with('taggable_id', :integer, {:null => false})
1227
- t.references :taggable, :polymorphic => true, :null => false
1228
- end
1244
+ def test_references_column_type_with_polymorphic_and_options_null_is_false_adds_table_flag
1245
+ with_new_table do |t|
1246
+ t.expects(:column).with('taggable_type', :string, {:null => false})
1247
+ t.expects(:column).with('taggable_id', :integer, {:null => false})
1248
+ t.references :taggable, :polymorphic => true, :null => false
1229
1249
  end
1250
+ end
1230
1251
 
1231
- def test_belongs_to_works_like_references
1232
- with_new_table do |t|
1233
- t.expects(:column).with('customer_id', :integer, {})
1234
- t.belongs_to :customer
1235
- end
1252
+ def test_belongs_to_works_like_references
1253
+ with_new_table do |t|
1254
+ t.expects(:column).with('customer_id', :integer, {})
1255
+ t.belongs_to :customer
1236
1256
  end
1257
+ end
1237
1258
 
1238
- def test_timestamps_creates_updated_at_and_created_at
1239
- with_new_table do |t|
1240
- t.expects(:column).with(:created_at, :datetime, kind_of(Hash))
1241
- t.expects(:column).with(:updated_at, :datetime, kind_of(Hash))
1242
- t.timestamps
1243
- end
1259
+ def test_timestamps_creates_updated_at_and_created_at
1260
+ with_new_table do |t|
1261
+ t.expects(:column).with(:created_at, :datetime, kind_of(Hash))
1262
+ t.expects(:column).with(:updated_at, :datetime, kind_of(Hash))
1263
+ t.timestamps
1244
1264
  end
1265
+ end
1245
1266
 
1246
- def test_integer_creates_integer_column
1247
- with_new_table do |t|
1248
- t.expects(:column).with(:foo, 'integer', {})
1249
- t.expects(:column).with(:bar, 'integer', {})
1250
- t.integer :foo, :bar
1251
- end
1267
+ def test_integer_creates_integer_column
1268
+ with_new_table do |t|
1269
+ t.expects(:column).with(:foo, 'integer', {})
1270
+ t.expects(:column).with(:bar, 'integer', {})
1271
+ t.integer :foo, :bar
1252
1272
  end
1273
+ end
1253
1274
 
1254
- def test_string_creates_string_column
1255
- with_new_table do |t|
1256
- t.expects(:column).with(:foo, 'string', {})
1257
- t.expects(:column).with(:bar, 'string', {})
1258
- t.string :foo, :bar
1259
- end
1275
+ def test_string_creates_string_column
1276
+ with_new_table do |t|
1277
+ t.expects(:column).with(:foo, 'string', {})
1278
+ t.expects(:column).with(:bar, 'string', {})
1279
+ t.string :foo, :bar
1260
1280
  end
1281
+ end
1261
1282
 
1262
- protected
1263
- def with_new_table
1264
- Person.connection.create_table :delete_me, :force => true do |t|
1265
- yield t
1266
- end
1267
- ensure
1268
- Person.connection.drop_table :delete_me rescue nil
1283
+ protected
1284
+ def with_new_table
1285
+ Person.connection.create_table :delete_me, :force => true do |t|
1286
+ yield t
1269
1287
  end
1288
+ ensure
1289
+ Person.connection.drop_table :delete_me rescue nil
1290
+ end
1270
1291
 
1271
- end # SexyMigrationsTest
1272
- end # uses_mocha
1292
+ end # SexyMigrationsTest
1273
1293
 
1274
- uses_mocha 'ChangeTable migration tests' do
1275
- class ChangeTableMigrationsTest < ActiveRecord::TestCase
1276
- def setup
1277
- @connection = Person.connection
1278
- @connection.create_table :delete_me, :force => true do |t|
1279
- end
1294
+ class ChangeTableMigrationsTest < ActiveRecord::TestCase
1295
+ def setup
1296
+ @connection = Person.connection
1297
+ @connection.create_table :delete_me, :force => true do |t|
1280
1298
  end
1299
+ end
1281
1300
 
1282
- def teardown
1283
- Person.connection.drop_table :delete_me rescue nil
1284
- end
1301
+ def teardown
1302
+ Person.connection.drop_table :delete_me rescue nil
1303
+ end
1285
1304
 
1286
- def test_references_column_type_adds_id
1287
- with_change_table do |t|
1288
- @connection.expects(:add_column).with(:delete_me, 'customer_id', :integer, {})
1289
- t.references :customer
1290
- end
1305
+ def test_references_column_type_adds_id
1306
+ with_change_table do |t|
1307
+ @connection.expects(:add_column).with(:delete_me, 'customer_id', :integer, {})
1308
+ t.references :customer
1291
1309
  end
1310
+ end
1292
1311
 
1293
- def test_remove_references_column_type_removes_id
1294
- with_change_table do |t|
1295
- @connection.expects(:remove_column).with(:delete_me, 'customer_id')
1296
- t.remove_references :customer
1297
- end
1312
+ def test_remove_references_column_type_removes_id
1313
+ with_change_table do |t|
1314
+ @connection.expects(:remove_column).with(:delete_me, 'customer_id')
1315
+ t.remove_references :customer
1298
1316
  end
1317
+ end
1299
1318
 
1300
- def test_add_belongs_to_works_like_add_references
1301
- with_change_table do |t|
1302
- @connection.expects(:add_column).with(:delete_me, 'customer_id', :integer, {})
1303
- t.belongs_to :customer
1304
- end
1319
+ def test_add_belongs_to_works_like_add_references
1320
+ with_change_table do |t|
1321
+ @connection.expects(:add_column).with(:delete_me, 'customer_id', :integer, {})
1322
+ t.belongs_to :customer
1305
1323
  end
1324
+ end
1306
1325
 
1307
- def test_remove_belongs_to_works_like_remove_references
1308
- with_change_table do |t|
1309
- @connection.expects(:remove_column).with(:delete_me, 'customer_id')
1310
- t.remove_belongs_to :customer
1311
- end
1326
+ def test_remove_belongs_to_works_like_remove_references
1327
+ with_change_table do |t|
1328
+ @connection.expects(:remove_column).with(:delete_me, 'customer_id')
1329
+ t.remove_belongs_to :customer
1312
1330
  end
1331
+ end
1313
1332
 
1314
- def test_references_column_type_with_polymorphic_adds_type
1315
- with_change_table do |t|
1316
- @connection.expects(:add_column).with(:delete_me, 'taggable_type', :string, {})
1317
- @connection.expects(:add_column).with(:delete_me, 'taggable_id', :integer, {})
1318
- t.references :taggable, :polymorphic => true
1319
- end
1333
+ def test_references_column_type_with_polymorphic_adds_type
1334
+ with_change_table do |t|
1335
+ @connection.expects(:add_column).with(:delete_me, 'taggable_type', :string, {})
1336
+ @connection.expects(:add_column).with(:delete_me, 'taggable_id', :integer, {})
1337
+ t.references :taggable, :polymorphic => true
1320
1338
  end
1339
+ end
1321
1340
 
1322
- def test_remove_references_column_type_with_polymorphic_removes_type
1323
- with_change_table do |t|
1324
- @connection.expects(:remove_column).with(:delete_me, 'taggable_type')
1325
- @connection.expects(:remove_column).with(:delete_me, 'taggable_id')
1326
- t.remove_references :taggable, :polymorphic => true
1327
- end
1341
+ def test_remove_references_column_type_with_polymorphic_removes_type
1342
+ with_change_table do |t|
1343
+ @connection.expects(:remove_column).with(:delete_me, 'taggable_type')
1344
+ @connection.expects(:remove_column).with(:delete_me, 'taggable_id')
1345
+ t.remove_references :taggable, :polymorphic => true
1328
1346
  end
1347
+ end
1329
1348
 
1330
- def test_references_column_type_with_polymorphic_and_options_null_is_false_adds_table_flag
1331
- with_change_table do |t|
1332
- @connection.expects(:add_column).with(:delete_me, 'taggable_type', :string, {:null => false})
1333
- @connection.expects(:add_column).with(:delete_me, 'taggable_id', :integer, {:null => false})
1334
- t.references :taggable, :polymorphic => true, :null => false
1335
- end
1349
+ def test_references_column_type_with_polymorphic_and_options_null_is_false_adds_table_flag
1350
+ with_change_table do |t|
1351
+ @connection.expects(:add_column).with(:delete_me, 'taggable_type', :string, {:null => false})
1352
+ @connection.expects(:add_column).with(:delete_me, 'taggable_id', :integer, {:null => false})
1353
+ t.references :taggable, :polymorphic => true, :null => false
1336
1354
  end
1355
+ end
1337
1356
 
1338
- def test_remove_references_column_type_with_polymorphic_and_options_null_is_false_removes_table_flag
1339
- with_change_table do |t|
1340
- @connection.expects(:remove_column).with(:delete_me, 'taggable_type')
1341
- @connection.expects(:remove_column).with(:delete_me, 'taggable_id')
1342
- t.remove_references :taggable, :polymorphic => true, :null => false
1343
- end
1357
+ def test_remove_references_column_type_with_polymorphic_and_options_null_is_false_removes_table_flag
1358
+ with_change_table do |t|
1359
+ @connection.expects(:remove_column).with(:delete_me, 'taggable_type')
1360
+ @connection.expects(:remove_column).with(:delete_me, 'taggable_id')
1361
+ t.remove_references :taggable, :polymorphic => true, :null => false
1344
1362
  end
1363
+ end
1345
1364
 
1346
- def test_timestamps_creates_updated_at_and_created_at
1347
- with_change_table do |t|
1348
- @connection.expects(:add_timestamps).with(:delete_me)
1349
- t.timestamps
1350
- end
1365
+ def test_timestamps_creates_updated_at_and_created_at
1366
+ with_change_table do |t|
1367
+ @connection.expects(:add_timestamps).with(:delete_me)
1368
+ t.timestamps
1351
1369
  end
1370
+ end
1352
1371
 
1353
- def test_remove_timestamps_creates_updated_at_and_created_at
1354
- with_change_table do |t|
1355
- @connection.expects(:remove_timestamps).with(:delete_me)
1356
- t.remove_timestamps
1357
- end
1372
+ def test_remove_timestamps_creates_updated_at_and_created_at
1373
+ with_change_table do |t|
1374
+ @connection.expects(:remove_timestamps).with(:delete_me)
1375
+ t.remove_timestamps
1358
1376
  end
1377
+ end
1359
1378
 
1360
- def string_column
1361
- if current_adapter?(:PostgreSQLAdapter)
1362
- "character varying(255)"
1363
- else
1364
- 'varchar(255)'
1365
- end
1379
+ def string_column
1380
+ if current_adapter?(:PostgreSQLAdapter)
1381
+ "character varying(255)"
1382
+ else
1383
+ 'varchar(255)'
1366
1384
  end
1385
+ end
1367
1386
 
1368
- def integer_column
1369
- if current_adapter?(:MysqlAdapter)
1370
- 'int(11)'
1371
- else
1372
- 'integer'
1373
- end
1387
+ def integer_column
1388
+ if current_adapter?(:MysqlAdapter)
1389
+ 'int(11)'
1390
+ else
1391
+ 'integer'
1374
1392
  end
1393
+ end
1375
1394
 
1376
- def test_integer_creates_integer_column
1377
- with_change_table do |t|
1378
- @connection.expects(:add_column).with(:delete_me, :foo, integer_column, {})
1379
- @connection.expects(:add_column).with(:delete_me, :bar, integer_column, {})
1380
- t.integer :foo, :bar
1381
- end
1395
+ def test_integer_creates_integer_column
1396
+ with_change_table do |t|
1397
+ @connection.expects(:add_column).with(:delete_me, :foo, integer_column, {})
1398
+ @connection.expects(:add_column).with(:delete_me, :bar, integer_column, {})
1399
+ t.integer :foo, :bar
1382
1400
  end
1401
+ end
1383
1402
 
1384
- def test_string_creates_string_column
1385
- with_change_table do |t|
1386
- @connection.expects(:add_column).with(:delete_me, :foo, string_column, {})
1387
- @connection.expects(:add_column).with(:delete_me, :bar, string_column, {})
1388
- t.string :foo, :bar
1389
- end
1403
+ def test_string_creates_string_column
1404
+ with_change_table do |t|
1405
+ @connection.expects(:add_column).with(:delete_me, :foo, string_column, {})
1406
+ @connection.expects(:add_column).with(:delete_me, :bar, string_column, {})
1407
+ t.string :foo, :bar
1390
1408
  end
1409
+ end
1391
1410
 
1392
- def test_column_creates_column
1393
- with_change_table do |t|
1394
- @connection.expects(:add_column).with(:delete_me, :bar, :integer, {})
1395
- t.column :bar, :integer
1396
- end
1411
+ def test_column_creates_column
1412
+ with_change_table do |t|
1413
+ @connection.expects(:add_column).with(:delete_me, :bar, :integer, {})
1414
+ t.column :bar, :integer
1397
1415
  end
1416
+ end
1398
1417
 
1399
- def test_column_creates_column_with_options
1400
- with_change_table do |t|
1401
- @connection.expects(:add_column).with(:delete_me, :bar, :integer, {:null => false})
1402
- t.column :bar, :integer, :null => false
1403
- end
1418
+ def test_column_creates_column_with_options
1419
+ with_change_table do |t|
1420
+ @connection.expects(:add_column).with(:delete_me, :bar, :integer, {:null => false})
1421
+ t.column :bar, :integer, :null => false
1404
1422
  end
1423
+ end
1405
1424
 
1406
- def test_index_creates_index
1407
- with_change_table do |t|
1408
- @connection.expects(:add_index).with(:delete_me, :bar, {})
1409
- t.index :bar
1410
- end
1425
+ def test_index_creates_index
1426
+ with_change_table do |t|
1427
+ @connection.expects(:add_index).with(:delete_me, :bar, {})
1428
+ t.index :bar
1411
1429
  end
1430
+ end
1412
1431
 
1413
- def test_index_creates_index_with_options
1414
- with_change_table do |t|
1415
- @connection.expects(:add_index).with(:delete_me, :bar, {:unique => true})
1416
- t.index :bar, :unique => true
1417
- end
1432
+ def test_index_creates_index_with_options
1433
+ with_change_table do |t|
1434
+ @connection.expects(:add_index).with(:delete_me, :bar, {:unique => true})
1435
+ t.index :bar, :unique => true
1418
1436
  end
1437
+ end
1419
1438
 
1420
- def test_change_changes_column
1421
- with_change_table do |t|
1422
- @connection.expects(:change_column).with(:delete_me, :bar, :string, {})
1423
- t.change :bar, :string
1424
- end
1439
+ def test_change_changes_column
1440
+ with_change_table do |t|
1441
+ @connection.expects(:change_column).with(:delete_me, :bar, :string, {})
1442
+ t.change :bar, :string
1425
1443
  end
1444
+ end
1426
1445
 
1427
- def test_change_changes_column_with_options
1428
- with_change_table do |t|
1429
- @connection.expects(:change_column).with(:delete_me, :bar, :string, {:null => true})
1430
- t.change :bar, :string, :null => true
1431
- end
1446
+ def test_change_changes_column_with_options
1447
+ with_change_table do |t|
1448
+ @connection.expects(:change_column).with(:delete_me, :bar, :string, {:null => true})
1449
+ t.change :bar, :string, :null => true
1432
1450
  end
1451
+ end
1433
1452
 
1434
- def test_change_default_changes_column
1435
- with_change_table do |t|
1436
- @connection.expects(:change_column_default).with(:delete_me, :bar, :string)
1437
- t.change_default :bar, :string
1438
- end
1453
+ def test_change_default_changes_column
1454
+ with_change_table do |t|
1455
+ @connection.expects(:change_column_default).with(:delete_me, :bar, :string)
1456
+ t.change_default :bar, :string
1439
1457
  end
1458
+ end
1440
1459
 
1441
- def test_remove_drops_single_column
1442
- with_change_table do |t|
1443
- @connection.expects(:remove_column).with(:delete_me, [:bar])
1444
- t.remove :bar
1445
- end
1460
+ def test_remove_drops_single_column
1461
+ with_change_table do |t|
1462
+ @connection.expects(:remove_column).with(:delete_me, [:bar])
1463
+ t.remove :bar
1446
1464
  end
1465
+ end
1447
1466
 
1448
- def test_remove_drops_multiple_columns
1449
- with_change_table do |t|
1450
- @connection.expects(:remove_column).with(:delete_me, [:bar, :baz])
1451
- t.remove :bar, :baz
1452
- end
1467
+ def test_remove_drops_multiple_columns
1468
+ with_change_table do |t|
1469
+ @connection.expects(:remove_column).with(:delete_me, [:bar, :baz])
1470
+ t.remove :bar, :baz
1453
1471
  end
1472
+ end
1454
1473
 
1455
- def test_remove_index_removes_index_with_options
1456
- with_change_table do |t|
1457
- @connection.expects(:remove_index).with(:delete_me, {:unique => true})
1458
- t.remove_index :unique => true
1459
- end
1474
+ def test_remove_index_removes_index_with_options
1475
+ with_change_table do |t|
1476
+ @connection.expects(:remove_index).with(:delete_me, {:unique => true})
1477
+ t.remove_index :unique => true
1460
1478
  end
1479
+ end
1461
1480
 
1462
- def test_rename_renames_column
1463
- with_change_table do |t|
1464
- @connection.expects(:rename_column).with(:delete_me, :bar, :baz)
1465
- t.rename :bar, :baz
1466
- end
1481
+ def test_rename_renames_column
1482
+ with_change_table do |t|
1483
+ @connection.expects(:rename_column).with(:delete_me, :bar, :baz)
1484
+ t.rename :bar, :baz
1467
1485
  end
1486
+ end
1468
1487
 
1469
- protected
1470
- def with_change_table
1471
- Person.connection.change_table :delete_me do |t|
1472
- yield t
1473
- end
1488
+ protected
1489
+ def with_change_table
1490
+ Person.connection.change_table :delete_me do |t|
1491
+ yield t
1474
1492
  end
1475
-
1476
- end # ChangeTable test
1477
- end # uses_mocha
1478
-
1493
+ end
1494
+ end
1479
1495
  end