activerecord 2.1.2 → 2.2.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 (110) hide show
  1. data/CHANGELOG +32 -6
  2. data/README +0 -0
  3. data/Rakefile +4 -5
  4. data/lib/active_record.rb +11 -10
  5. data/lib/active_record/aggregations.rb +110 -38
  6. data/lib/active_record/association_preload.rb +104 -15
  7. data/lib/active_record/associations.rb +427 -212
  8. data/lib/active_record/associations/association_collection.rb +101 -16
  9. data/lib/active_record/associations/association_proxy.rb +65 -13
  10. data/lib/active_record/associations/belongs_to_association.rb +2 -2
  11. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +0 -0
  12. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +13 -3
  13. data/lib/active_record/associations/has_many_association.rb +28 -28
  14. data/lib/active_record/associations/has_many_through_association.rb +21 -19
  15. data/lib/active_record/associations/has_one_association.rb +24 -7
  16. data/lib/active_record/associations/has_one_through_association.rb +3 -4
  17. data/lib/active_record/attribute_methods.rb +13 -5
  18. data/lib/active_record/base.rb +435 -212
  19. data/lib/active_record/calculations.rb +12 -5
  20. data/lib/active_record/callbacks.rb +28 -9
  21. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +355 -0
  22. data/lib/active_record/connection_adapters/abstract/connection_specification.rb +42 -215
  23. data/lib/active_record/connection_adapters/abstract/database_statements.rb +30 -5
  24. data/lib/active_record/connection_adapters/abstract/query_cache.rb +2 -1
  25. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +48 -7
  26. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +10 -4
  27. data/lib/active_record/connection_adapters/abstract_adapter.rb +67 -26
  28. data/lib/active_record/connection_adapters/mysql_adapter.rb +71 -45
  29. data/lib/active_record/connection_adapters/postgresql_adapter.rb +155 -84
  30. data/lib/active_record/dirty.rb +25 -7
  31. data/lib/active_record/dynamic_finder_match.rb +41 -0
  32. data/lib/active_record/fixtures.rb +10 -9
  33. data/lib/active_record/i18n_interpolation_deprecation.rb +26 -0
  34. data/lib/active_record/locale/en.yml +54 -0
  35. data/lib/active_record/migration.rb +47 -10
  36. data/lib/active_record/named_scope.rb +29 -16
  37. data/lib/active_record/reflection.rb +118 -54
  38. data/lib/active_record/schema_dumper.rb +13 -7
  39. data/lib/active_record/test_case.rb +18 -5
  40. data/lib/active_record/transactions.rb +89 -34
  41. data/lib/active_record/validations.rb +270 -180
  42. data/lib/active_record/version.rb +1 -1
  43. data/test/cases/active_schema_test_mysql.rb +5 -0
  44. data/test/cases/adapter_test.rb +6 -0
  45. data/test/cases/aggregations_test.rb +39 -0
  46. data/test/cases/associations/belongs_to_associations_test.rb +10 -0
  47. data/test/cases/associations/eager_load_nested_include_test.rb +30 -12
  48. data/test/cases/associations/eager_test.rb +54 -5
  49. data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +77 -10
  50. data/test/cases/associations/has_many_associations_test.rb +74 -7
  51. data/test/cases/associations/has_many_through_associations_test.rb +50 -3
  52. data/test/cases/associations/has_one_associations_test.rb +17 -0
  53. data/test/cases/associations/has_one_through_associations_test.rb +49 -1
  54. data/test/cases/associations_test.rb +0 -0
  55. data/test/cases/attribute_methods_test.rb +59 -4
  56. data/test/cases/base_test.rb +93 -21
  57. data/test/cases/binary_test.rb +1 -5
  58. data/test/cases/calculations_test.rb +5 -0
  59. data/test/cases/callbacks_observers_test.rb +38 -0
  60. data/test/cases/connection_test_mysql.rb +1 -1
  61. data/test/cases/defaults_test.rb +32 -1
  62. data/test/cases/deprecated_finder_test.rb +0 -0
  63. data/test/cases/dirty_test.rb +13 -0
  64. data/test/cases/finder_test.rb +162 -12
  65. data/test/cases/fixtures_test.rb +32 -3
  66. data/test/cases/helper.rb +15 -0
  67. data/test/cases/i18n_test.rb +41 -0
  68. data/test/cases/inheritance_test.rb +2 -2
  69. data/test/cases/lifecycle_test.rb +0 -0
  70. data/test/cases/locking_test.rb +4 -9
  71. data/test/cases/method_scoping_test.rb +109 -2
  72. data/test/cases/migration_test.rb +43 -8
  73. data/test/cases/multiple_db_test.rb +25 -0
  74. data/test/cases/named_scope_test.rb +74 -0
  75. data/test/cases/pooled_connections_test.rb +103 -0
  76. data/test/cases/readonly_test.rb +0 -0
  77. data/test/cases/reflection_test.rb +11 -3
  78. data/test/cases/reload_models_test.rb +20 -0
  79. data/test/cases/sanitize_test.rb +25 -0
  80. data/test/cases/schema_authorization_test_postgresql.rb +2 -2
  81. data/test/cases/transactions_test.rb +62 -12
  82. data/test/cases/unconnected_test.rb +0 -0
  83. data/test/cases/validations_i18n_test.rb +921 -0
  84. data/test/cases/validations_test.rb +44 -33
  85. data/test/connections/native_mysql/connection.rb +1 -3
  86. data/test/fixtures/companies.yml +1 -0
  87. data/test/fixtures/customers.yml +10 -1
  88. data/test/fixtures/fixture_database.sqlite3 +0 -0
  89. data/test/fixtures/fixture_database_2.sqlite3 +0 -0
  90. data/test/fixtures/organizations.yml +5 -0
  91. data/test/migrations/broken/100_migration_that_raises_exception.rb +10 -0
  92. data/test/models/author.rb +3 -0
  93. data/test/models/category.rb +3 -0
  94. data/test/models/club.rb +6 -0
  95. data/test/models/company.rb +25 -1
  96. data/test/models/customer.rb +19 -1
  97. data/test/models/member.rb +2 -0
  98. data/test/models/member_detail.rb +4 -0
  99. data/test/models/organization.rb +4 -0
  100. data/test/models/parrot.rb +1 -0
  101. data/test/models/post.rb +3 -0
  102. data/test/models/reply.rb +0 -0
  103. data/test/models/topic.rb +3 -0
  104. data/test/schema/schema.rb +12 -1
  105. metadata +22 -10
  106. data/lib/active_record/vendor/mysql.rb +0 -1214
  107. data/test/cases/adapter_test_sqlserver.rb +0 -95
  108. data/test/cases/table_name_test_sqlserver.rb +0 -23
  109. data/test/cases/threaded_connections_test.rb +0 -48
  110. data/test/schema/sqlserver_specific_schema.rb +0 -5
@@ -496,6 +496,15 @@ class ValidationsTest < ActiveRecord::TestCase
496
496
  assert_not_equal "has already been taken", t3.errors.on(:title)
497
497
  end
498
498
 
499
+ def test_validate_case_sensitive_uniqueness_with_attribute_passed_as_integer
500
+ Topic.validates_uniqueness_of(:title, :case_sensitve => true)
501
+ t = Topic.create!('title' => 101)
502
+
503
+ t2 = Topic.new('title' => 101)
504
+ assert !t2.valid?
505
+ assert t2.errors.on(:title)
506
+ end
507
+
499
508
  def test_validate_uniqueness_with_non_standard_table_names
500
509
  i1 = WarehouseThing.create(:value => 1000)
501
510
  assert !i1.valid?, "i1 should not be valid"
@@ -603,7 +612,7 @@ class ValidationsTest < ActiveRecord::TestCase
603
612
  end
604
613
 
605
614
  def test_validate_format_with_formatted_message
606
- Topic.validates_format_of(:title, :with => /^Valid Title$/, :message => "can't be %s")
615
+ Topic.validates_format_of(:title, :with => /^Valid Title$/, :message => "can't be {{value}}")
607
616
  t = Topic.create(:title => 'Invalid title')
608
617
  assert_equal "can't be Invalid title", t.errors.on(:title)
609
618
  end
@@ -664,7 +673,7 @@ class ValidationsTest < ActiveRecord::TestCase
664
673
  end
665
674
 
666
675
  def test_validates_inclusion_of_with_formatted_message
667
- Topic.validates_inclusion_of( :title, :in => %w( a b c d e f g ), :message => "option %s is not in the list" )
676
+ Topic.validates_inclusion_of( :title, :in => %w( a b c d e f g ), :message => "option {{value}} is not in the list" )
668
677
 
669
678
  assert Topic.create("title" => "a", "content" => "abc").valid?
670
679
 
@@ -689,7 +698,7 @@ class ValidationsTest < ActiveRecord::TestCase
689
698
  end
690
699
 
691
700
  def test_validates_exclusion_of_with_formatted_message
692
- Topic.validates_exclusion_of( :title, :in => %w( abe monkey ), :message => "option %s is restricted" )
701
+ Topic.validates_exclusion_of( :title, :in => %w( abe monkey ), :message => "option {{value}} is restricted" )
693
702
 
694
703
  assert Topic.create("title" => "something", "content" => "abc")
695
704
 
@@ -789,7 +798,7 @@ class ValidationsTest < ActiveRecord::TestCase
789
798
  end
790
799
 
791
800
  def test_optionally_validates_length_of_using_within_on_create
792
- Topic.validates_length_of :title, :content, :within => 5..10, :on => :create, :too_long => "my string is too long: %d"
801
+ Topic.validates_length_of :title, :content, :within => 5..10, :on => :create, :too_long => "my string is too long: {{count}}"
793
802
 
794
803
  t = Topic.create("title" => "thisisnotvalid", "content" => "whatever")
795
804
  assert !t.save
@@ -810,7 +819,7 @@ class ValidationsTest < ActiveRecord::TestCase
810
819
  end
811
820
 
812
821
  def test_optionally_validates_length_of_using_within_on_update
813
- Topic.validates_length_of :title, :content, :within => 5..10, :on => :update, :too_short => "my string is too short: %d"
822
+ Topic.validates_length_of :title, :content, :within => 5..10, :on => :update, :too_short => "my string is too short: {{count}}"
814
823
 
815
824
  t = Topic.create("title" => "vali", "content" => "whatever")
816
825
  assert !t.save
@@ -872,7 +881,9 @@ class ValidationsTest < ActiveRecord::TestCase
872
881
  end
873
882
 
874
883
  def test_validates_length_with_globally_modified_error_message
875
- ActiveRecord::Errors.default_error_messages[:too_short] = 'tu est trops petit hombre %d'
884
+ ActiveSupport::Deprecation.silence do
885
+ ActiveRecord::Errors.default_error_messages[:too_short] = 'tu est trops petit hombre {{count}}'
886
+ end
876
887
  Topic.validates_length_of :title, :minimum => 10
877
888
  t = Topic.create(:title => 'too short')
878
889
  assert !t.valid?
@@ -915,7 +926,7 @@ class ValidationsTest < ActiveRecord::TestCase
915
926
  end
916
927
 
917
928
  def test_validates_length_of_custom_errors_for_minimum_with_message
918
- Topic.validates_length_of( :title, :minimum=>5, :message=>"boo %d" )
929
+ Topic.validates_length_of( :title, :minimum=>5, :message=>"boo {{count}}" )
919
930
  t = Topic.create("title" => "uhoh", "content" => "whatever")
920
931
  assert !t.valid?
921
932
  assert t.errors.on(:title)
@@ -923,7 +934,7 @@ class ValidationsTest < ActiveRecord::TestCase
923
934
  end
924
935
 
925
936
  def test_validates_length_of_custom_errors_for_minimum_with_too_short
926
- Topic.validates_length_of( :title, :minimum=>5, :too_short=>"hoo %d" )
937
+ Topic.validates_length_of( :title, :minimum=>5, :too_short=>"hoo {{count}}" )
927
938
  t = Topic.create("title" => "uhoh", "content" => "whatever")
928
939
  assert !t.valid?
929
940
  assert t.errors.on(:title)
@@ -931,7 +942,7 @@ class ValidationsTest < ActiveRecord::TestCase
931
942
  end
932
943
 
933
944
  def test_validates_length_of_custom_errors_for_maximum_with_message
934
- Topic.validates_length_of( :title, :maximum=>5, :message=>"boo %d" )
945
+ Topic.validates_length_of( :title, :maximum=>5, :message=>"boo {{count}}" )
935
946
  t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
936
947
  assert !t.valid?
937
948
  assert t.errors.on(:title)
@@ -939,7 +950,7 @@ class ValidationsTest < ActiveRecord::TestCase
939
950
  end
940
951
 
941
952
  def test_validates_length_of_custom_errors_for_maximum_with_too_long
942
- Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d" )
953
+ Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}" )
943
954
  t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
944
955
  assert !t.valid?
945
956
  assert t.errors.on(:title)
@@ -947,7 +958,7 @@ class ValidationsTest < ActiveRecord::TestCase
947
958
  end
948
959
 
949
960
  def test_validates_length_of_custom_errors_for_is_with_message
950
- Topic.validates_length_of( :title, :is=>5, :message=>"boo %d" )
961
+ Topic.validates_length_of( :title, :is=>5, :message=>"boo {{count}}" )
951
962
  t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
952
963
  assert !t.valid?
953
964
  assert t.errors.on(:title)
@@ -955,7 +966,7 @@ class ValidationsTest < ActiveRecord::TestCase
955
966
  end
956
967
 
957
968
  def test_validates_length_of_custom_errors_for_is_with_wrong_length
958
- Topic.validates_length_of( :title, :is=>5, :wrong_length=>"hoo %d" )
969
+ Topic.validates_length_of( :title, :is=>5, :wrong_length=>"hoo {{count}}" )
959
970
  t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
960
971
  assert !t.valid?
961
972
  assert t.errors.on(:title)
@@ -1021,7 +1032,7 @@ class ValidationsTest < ActiveRecord::TestCase
1021
1032
 
1022
1033
  def test_optionally_validates_length_of_using_within_on_create_utf8
1023
1034
  with_kcode('UTF8') do
1024
- Topic.validates_length_of :title, :within => 5..10, :on => :create, :too_long => "長すぎます: %d"
1035
+ Topic.validates_length_of :title, :within => 5..10, :on => :create, :too_long => "長すぎます: {{count}}"
1025
1036
 
1026
1037
  t = Topic.create("title" => "一二三四五六七八九十A", "content" => "whatever")
1027
1038
  assert !t.save
@@ -1044,7 +1055,7 @@ class ValidationsTest < ActiveRecord::TestCase
1044
1055
 
1045
1056
  def test_optionally_validates_length_of_using_within_on_update_utf8
1046
1057
  with_kcode('UTF8') do
1047
- Topic.validates_length_of :title, :within => 5..10, :on => :update, :too_short => "短すぎます: %d"
1058
+ Topic.validates_length_of :title, :within => 5..10, :on => :update, :too_short => "短すぎます: {{count}}"
1048
1059
 
1049
1060
  t = Topic.create("title" => "一二三4", "content" => "whatever")
1050
1061
  assert !t.save
@@ -1079,7 +1090,7 @@ class ValidationsTest < ActiveRecord::TestCase
1079
1090
  end
1080
1091
 
1081
1092
  def test_validates_length_of_with_block
1082
- Topic.validates_length_of :content, :minimum => 5, :too_short=>"Your essay must be at least %d words.",
1093
+ Topic.validates_length_of :content, :minimum => 5, :too_short=>"Your essay must be at least {{count}} words.",
1083
1094
  :tokenizer => lambda {|str| str.scan(/\w+/) }
1084
1095
  t = Topic.create!(:content => "this content should be long enough")
1085
1096
  assert t.valid?
@@ -1230,7 +1241,7 @@ class ValidationsTest < ActiveRecord::TestCase
1230
1241
 
1231
1242
  def test_if_validation_using_method_true
1232
1243
  # When the method returns true
1233
- Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d", :if => :condition_is_true )
1244
+ Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}", :if => :condition_is_true )
1234
1245
  t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
1235
1246
  assert !t.valid?
1236
1247
  assert t.errors.on(:title)
@@ -1239,7 +1250,7 @@ class ValidationsTest < ActiveRecord::TestCase
1239
1250
 
1240
1251
  def test_unless_validation_using_method_true
1241
1252
  # When the method returns true
1242
- Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d", :unless => :condition_is_true )
1253
+ Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}", :unless => :condition_is_true )
1243
1254
  t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
1244
1255
  assert t.valid?
1245
1256
  assert !t.errors.on(:title)
@@ -1247,7 +1258,7 @@ class ValidationsTest < ActiveRecord::TestCase
1247
1258
 
1248
1259
  def test_if_validation_using_method_false
1249
1260
  # When the method returns false
1250
- Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d", :if => :condition_is_true_but_its_not )
1261
+ Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}", :if => :condition_is_true_but_its_not )
1251
1262
  t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
1252
1263
  assert t.valid?
1253
1264
  assert !t.errors.on(:title)
@@ -1255,7 +1266,7 @@ class ValidationsTest < ActiveRecord::TestCase
1255
1266
 
1256
1267
  def test_unless_validation_using_method_false
1257
1268
  # When the method returns false
1258
- Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d", :unless => :condition_is_true_but_its_not )
1269
+ Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}", :unless => :condition_is_true_but_its_not )
1259
1270
  t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
1260
1271
  assert !t.valid?
1261
1272
  assert t.errors.on(:title)
@@ -1264,7 +1275,7 @@ class ValidationsTest < ActiveRecord::TestCase
1264
1275
 
1265
1276
  def test_if_validation_using_string_true
1266
1277
  # When the evaluated string returns true
1267
- Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d", :if => "a = 1; a == 1" )
1278
+ Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}", :if => "a = 1; a == 1" )
1268
1279
  t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
1269
1280
  assert !t.valid?
1270
1281
  assert t.errors.on(:title)
@@ -1273,7 +1284,7 @@ class ValidationsTest < ActiveRecord::TestCase
1273
1284
 
1274
1285
  def test_unless_validation_using_string_true
1275
1286
  # When the evaluated string returns true
1276
- Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d", :unless => "a = 1; a == 1" )
1287
+ Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}", :unless => "a = 1; a == 1" )
1277
1288
  t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
1278
1289
  assert t.valid?
1279
1290
  assert !t.errors.on(:title)
@@ -1281,7 +1292,7 @@ class ValidationsTest < ActiveRecord::TestCase
1281
1292
 
1282
1293
  def test_if_validation_using_string_false
1283
1294
  # When the evaluated string returns false
1284
- Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d", :if => "false")
1295
+ Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}", :if => "false")
1285
1296
  t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
1286
1297
  assert t.valid?
1287
1298
  assert !t.errors.on(:title)
@@ -1289,7 +1300,7 @@ class ValidationsTest < ActiveRecord::TestCase
1289
1300
 
1290
1301
  def test_unless_validation_using_string_false
1291
1302
  # When the evaluated string returns false
1292
- Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d", :unless => "false")
1303
+ Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}", :unless => "false")
1293
1304
  t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
1294
1305
  assert !t.valid?
1295
1306
  assert t.errors.on(:title)
@@ -1298,7 +1309,7 @@ class ValidationsTest < ActiveRecord::TestCase
1298
1309
 
1299
1310
  def test_if_validation_using_block_true
1300
1311
  # When the block returns true
1301
- Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d",
1312
+ Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}",
1302
1313
  :if => Proc.new { |r| r.content.size > 4 } )
1303
1314
  t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
1304
1315
  assert !t.valid?
@@ -1308,7 +1319,7 @@ class ValidationsTest < ActiveRecord::TestCase
1308
1319
 
1309
1320
  def test_unless_validation_using_block_true
1310
1321
  # When the block returns true
1311
- Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d",
1322
+ Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}",
1312
1323
  :unless => Proc.new { |r| r.content.size > 4 } )
1313
1324
  t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
1314
1325
  assert t.valid?
@@ -1317,7 +1328,7 @@ class ValidationsTest < ActiveRecord::TestCase
1317
1328
 
1318
1329
  def test_if_validation_using_block_false
1319
1330
  # When the block returns false
1320
- Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d",
1331
+ Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}",
1321
1332
  :if => Proc.new { |r| r.title != "uhohuhoh"} )
1322
1333
  t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
1323
1334
  assert t.valid?
@@ -1326,7 +1337,7 @@ class ValidationsTest < ActiveRecord::TestCase
1326
1337
 
1327
1338
  def test_unless_validation_using_block_false
1328
1339
  # When the block returns false
1329
- Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo %d",
1340
+ Topic.validates_length_of( :title, :maximum=>5, :too_long=>"hoo {{count}}",
1330
1341
  :unless => Proc.new { |r| r.title != "uhohuhoh"} )
1331
1342
  t = Topic.create("title" => "uhohuhoh", "content" => "whatever")
1332
1343
  assert !t.valid?
@@ -1428,8 +1439,8 @@ class ValidatesNumericalityTest < ActiveRecord::TestCase
1428
1439
  def test_validates_numericality_of_with_nil_allowed
1429
1440
  Topic.validates_numericality_of :approved, :allow_nil => true
1430
1441
 
1431
- invalid!(BLANK + JUNK)
1432
- valid!(NIL + FLOATS + INTEGERS + BIGDECIMAL + INFINITY)
1442
+ invalid!(JUNK)
1443
+ valid!(NIL + BLANK + FLOATS + INTEGERS + BIGDECIMAL + INFINITY)
1433
1444
  end
1434
1445
 
1435
1446
  def test_validates_numericality_of_with_integer_only
@@ -1442,8 +1453,8 @@ class ValidatesNumericalityTest < ActiveRecord::TestCase
1442
1453
  def test_validates_numericality_of_with_integer_only_and_nil_allowed
1443
1454
  Topic.validates_numericality_of :approved, :only_integer => true, :allow_nil => true
1444
1455
 
1445
- invalid!(BLANK + JUNK + FLOATS + BIGDECIMAL + INFINITY)
1446
- valid!(NIL + INTEGERS)
1456
+ invalid!(JUNK + FLOATS + BIGDECIMAL + INFINITY)
1457
+ valid!(NIL + BLANK + INTEGERS)
1447
1458
  end
1448
1459
 
1449
1460
  def test_validates_numericality_with_greater_than
@@ -1503,13 +1514,13 @@ class ValidatesNumericalityTest < ActiveRecord::TestCase
1503
1514
  end
1504
1515
 
1505
1516
  def test_validates_numericality_with_numeric_message
1506
- Topic.validates_numericality_of :approved, :less_than => 4, :message => "smaller than %d"
1517
+ Topic.validates_numericality_of :approved, :less_than => 4, :message => "smaller than {{count}}"
1507
1518
  topic = Topic.new("title" => "numeric test", "approved" => 10)
1508
1519
 
1509
1520
  assert !topic.valid?
1510
1521
  assert_equal "smaller than 4", topic.errors.on(:approved)
1511
1522
 
1512
- Topic.validates_numericality_of :approved, :greater_than => 4, :message => "greater than %d"
1523
+ Topic.validates_numericality_of :approved, :greater_than => 4, :message => "greater than {{count}}"
1513
1524
  topic = Topic.new("title" => "numeric test", "approved" => 1)
1514
1525
 
1515
1526
  assert !topic.valid?
@@ -2,9 +2,7 @@ print "Using native MySQL\n"
2
2
  require_dependency 'models/course'
3
3
  require 'logger'
4
4
 
5
- RAILS_DEFAULT_LOGGER = Logger.new('debug.log')
6
- RAILS_DEFAULT_LOGGER.level = Logger::DEBUG
7
- ActiveRecord::Base.logger = RAILS_DEFAULT_LOGGER
5
+ ActiveRecord::Base.logger = Logger.new("debug.log")
8
6
 
9
7
  # GRANT ALL PRIVILEGES ON activerecord_unittest.* to 'rails'@'localhost';
10
8
  # GRANT ALL PRIVILEGES ON activerecord_unittest2.* to 'rails'@'localhost';
@@ -5,6 +5,7 @@ first_client:
5
5
  client_of: 2
6
6
  name: Summit
7
7
  ruby_type: Client
8
+ firm_name: 37signals
8
9
 
9
10
  first_firm:
10
11
  id: 1
@@ -6,7 +6,7 @@ david:
6
6
  address_city: Scary Town
7
7
  address_country: Loony Land
8
8
  gps_location: 35.544623640962634x-105.9309951055148
9
-
9
+
10
10
  zaphod:
11
11
  id: 2
12
12
  name: Zaphod
@@ -14,4 +14,13 @@ zaphod:
14
14
  address_street: Avenue Road
15
15
  address_city: Hamlet Town
16
16
  address_country: Nation Land
17
+ gps_location: NULL
18
+
19
+ barney:
20
+ id: 3
21
+ name: Barney Gumble
22
+ balance: 1
23
+ address_street: Quiet Road
24
+ address_city: Peaceful Town
25
+ address_country: Tranquil Land
17
26
  gps_location: NULL
@@ -0,0 +1,5 @@
1
+ nsa:
2
+ name: No Such Agency
3
+ discordians:
4
+ name: Discordians
5
+
@@ -0,0 +1,10 @@
1
+ class MigrationThatRaisesException < ActiveRecord::Migration
2
+ def self.up
3
+ add_column "people", "last_name", :string
4
+ raise 'Something broke'
5
+ end
6
+
7
+ def self.down
8
+ remove_column "people", "last_name"
9
+ end
10
+ end
@@ -2,6 +2,7 @@ class Author < ActiveRecord::Base
2
2
  has_many :posts
3
3
  has_many :posts_with_comments, :include => :comments, :class_name => "Post"
4
4
  has_many :posts_with_comments_sorted_by_comment_id, :include => :comments, :class_name => "Post", :order => 'comments.id'
5
+ has_many :posts_sorted_by_id_limited, :class_name => "Post", :order => 'posts.id', :limit => 1
5
6
  has_many :posts_with_categories, :include => :categories, :class_name => "Post"
6
7
  has_many :posts_with_comments_and_categories, :include => [ :comments, :categories ], :order => "posts.id", :class_name => "Post"
7
8
  has_many :posts_containing_the_letter_a, :class_name => "Post"
@@ -16,6 +17,8 @@ class Author < ActiveRecord::Base
16
17
  proxy_target
17
18
  end
18
19
  end
20
+ has_one :post_about_thinking, :class_name => 'Post', :conditions => "posts.title like '%thinking%'"
21
+ has_one :post_about_thinking_with_last_comment, :class_name => 'Post', :conditions => "posts.title like '%thinking%'", :include => :last_comment
19
22
  has_many :comments, :through => :posts
20
23
  has_many :comments_containing_the_letter_e, :through => :posts, :source => :comments
21
24
  has_many :comments_with_order_and_conditions, :through => :posts, :source => :comments, :order => 'comments.body', :conditions => "comments.body like 'Thank%'"
@@ -13,6 +13,9 @@ class Category < ActiveRecord::Base
13
13
  has_and_belongs_to_many :post_with_conditions,
14
14
  :class_name => 'Post',
15
15
  :conditions => { :title => 'Yet Another Testing Title' }
16
+
17
+ has_and_belongs_to_many :posts_gruoped_by_title, :class_name => "Post", :group => "title", :select => "title"
18
+
16
19
  def self.what_are_you
17
20
  'a category...'
18
21
  end
@@ -4,4 +4,10 @@ class Club < ActiveRecord::Base
4
4
  has_many :current_memberships
5
5
  has_one :sponsor
6
6
  has_one :sponsored_member, :through => :sponsor, :source => :sponsorable, :source_type => "Member"
7
+
8
+ private
9
+
10
+ def private_method
11
+ "I'm sorry sir, this is a *private* club, not a *pirate* club"
12
+ end
7
13
  end
@@ -13,6 +13,12 @@ class Company < AbstractCompany
13
13
  def arbitrary_method
14
14
  "I am Jack's profound disappointment"
15
15
  end
16
+
17
+ private
18
+
19
+ def private_method
20
+ "I am Jack's innermost fears and aspirations"
21
+ end
16
22
  end
17
23
 
18
24
  module Namespaced
@@ -53,11 +59,16 @@ class Firm < Company
53
59
  has_many :clients_using_finder_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE 1=1'
54
60
  has_many :plain_clients, :class_name => 'Client'
55
61
  has_many :readonly_clients, :class_name => 'Client', :readonly => true
62
+ has_many :clients_using_primary_key, :class_name => 'Client',
63
+ :primary_key => 'name', :foreign_key => 'firm_name'
64
+ has_many :clients_grouped_by_firm_id, :class_name => "Client", :group => "firm_id", :select => "firm_id"
65
+ has_many :clients_grouped_by_name, :class_name => "Client", :group => "name", :select => "name"
56
66
 
57
67
  has_one :account, :foreign_key => "firm_id", :dependent => :destroy, :validate => true
58
68
  has_one :unvalidated_account, :foreign_key => "firm_id", :class_name => 'Account', :validate => false
59
69
  has_one :account_with_select, :foreign_key => "firm_id", :select => "id, firm_id", :class_name=>'Account'
60
70
  has_one :readonly_account, :foreign_key => "firm_id", :class_name => "Account", :readonly => true
71
+ has_one :account_using_primary_key, :primary_key => "firm_id", :class_name => "Account"
61
72
  end
62
73
 
63
74
  class DependentFirm < Company
@@ -101,6 +112,14 @@ class Client < Company
101
112
  def rating?
102
113
  query_attribute :rating
103
114
  end
115
+
116
+ class << self
117
+ private
118
+
119
+ def private_method
120
+ "darkness"
121
+ end
122
+ end
104
123
  end
105
124
 
106
125
 
@@ -124,9 +143,14 @@ class Account < ActiveRecord::Base
124
143
  true
125
144
  end
126
145
 
127
-
128
146
  protected
129
147
  def validate
130
148
  errors.add_on_empty "credit_limit"
131
149
  end
150
+
151
+ private
152
+
153
+ def private_method
154
+ "Sir, yes sir!"
155
+ end
132
156
  end