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.
- data/CHANGELOG +32 -6
- data/README +0 -0
- data/Rakefile +4 -5
- data/lib/active_record.rb +11 -10
- data/lib/active_record/aggregations.rb +110 -38
- data/lib/active_record/association_preload.rb +104 -15
- data/lib/active_record/associations.rb +427 -212
- data/lib/active_record/associations/association_collection.rb +101 -16
- data/lib/active_record/associations/association_proxy.rb +65 -13
- data/lib/active_record/associations/belongs_to_association.rb +2 -2
- data/lib/active_record/associations/belongs_to_polymorphic_association.rb +0 -0
- data/lib/active_record/associations/has_and_belongs_to_many_association.rb +13 -3
- data/lib/active_record/associations/has_many_association.rb +28 -28
- data/lib/active_record/associations/has_many_through_association.rb +21 -19
- data/lib/active_record/associations/has_one_association.rb +24 -7
- data/lib/active_record/associations/has_one_through_association.rb +3 -4
- data/lib/active_record/attribute_methods.rb +13 -5
- data/lib/active_record/base.rb +435 -212
- data/lib/active_record/calculations.rb +12 -5
- data/lib/active_record/callbacks.rb +28 -9
- data/lib/active_record/connection_adapters/abstract/connection_pool.rb +355 -0
- data/lib/active_record/connection_adapters/abstract/connection_specification.rb +42 -215
- data/lib/active_record/connection_adapters/abstract/database_statements.rb +30 -5
- data/lib/active_record/connection_adapters/abstract/query_cache.rb +2 -1
- data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +48 -7
- data/lib/active_record/connection_adapters/abstract/schema_statements.rb +10 -4
- data/lib/active_record/connection_adapters/abstract_adapter.rb +67 -26
- data/lib/active_record/connection_adapters/mysql_adapter.rb +71 -45
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +155 -84
- data/lib/active_record/dirty.rb +25 -7
- data/lib/active_record/dynamic_finder_match.rb +41 -0
- data/lib/active_record/fixtures.rb +10 -9
- data/lib/active_record/i18n_interpolation_deprecation.rb +26 -0
- data/lib/active_record/locale/en.yml +54 -0
- data/lib/active_record/migration.rb +47 -10
- data/lib/active_record/named_scope.rb +29 -16
- data/lib/active_record/reflection.rb +118 -54
- data/lib/active_record/schema_dumper.rb +13 -7
- data/lib/active_record/test_case.rb +18 -5
- data/lib/active_record/transactions.rb +89 -34
- data/lib/active_record/validations.rb +270 -180
- data/lib/active_record/version.rb +1 -1
- data/test/cases/active_schema_test_mysql.rb +5 -0
- data/test/cases/adapter_test.rb +6 -0
- data/test/cases/aggregations_test.rb +39 -0
- data/test/cases/associations/belongs_to_associations_test.rb +10 -0
- data/test/cases/associations/eager_load_nested_include_test.rb +30 -12
- data/test/cases/associations/eager_test.rb +54 -5
- data/test/cases/associations/has_and_belongs_to_many_associations_test.rb +77 -10
- data/test/cases/associations/has_many_associations_test.rb +74 -7
- data/test/cases/associations/has_many_through_associations_test.rb +50 -3
- data/test/cases/associations/has_one_associations_test.rb +17 -0
- data/test/cases/associations/has_one_through_associations_test.rb +49 -1
- data/test/cases/associations_test.rb +0 -0
- data/test/cases/attribute_methods_test.rb +59 -4
- data/test/cases/base_test.rb +93 -21
- data/test/cases/binary_test.rb +1 -5
- data/test/cases/calculations_test.rb +5 -0
- data/test/cases/callbacks_observers_test.rb +38 -0
- data/test/cases/connection_test_mysql.rb +1 -1
- data/test/cases/defaults_test.rb +32 -1
- data/test/cases/deprecated_finder_test.rb +0 -0
- data/test/cases/dirty_test.rb +13 -0
- data/test/cases/finder_test.rb +162 -12
- data/test/cases/fixtures_test.rb +32 -3
- data/test/cases/helper.rb +15 -0
- data/test/cases/i18n_test.rb +41 -0
- data/test/cases/inheritance_test.rb +2 -2
- data/test/cases/lifecycle_test.rb +0 -0
- data/test/cases/locking_test.rb +4 -9
- data/test/cases/method_scoping_test.rb +109 -2
- data/test/cases/migration_test.rb +43 -8
- data/test/cases/multiple_db_test.rb +25 -0
- data/test/cases/named_scope_test.rb +74 -0
- data/test/cases/pooled_connections_test.rb +103 -0
- data/test/cases/readonly_test.rb +0 -0
- data/test/cases/reflection_test.rb +11 -3
- data/test/cases/reload_models_test.rb +20 -0
- data/test/cases/sanitize_test.rb +25 -0
- data/test/cases/schema_authorization_test_postgresql.rb +2 -2
- data/test/cases/transactions_test.rb +62 -12
- data/test/cases/unconnected_test.rb +0 -0
- data/test/cases/validations_i18n_test.rb +921 -0
- data/test/cases/validations_test.rb +44 -33
- data/test/connections/native_mysql/connection.rb +1 -3
- data/test/fixtures/companies.yml +1 -0
- data/test/fixtures/customers.yml +10 -1
- data/test/fixtures/fixture_database.sqlite3 +0 -0
- data/test/fixtures/fixture_database_2.sqlite3 +0 -0
- data/test/fixtures/organizations.yml +5 -0
- data/test/migrations/broken/100_migration_that_raises_exception.rb +10 -0
- data/test/models/author.rb +3 -0
- data/test/models/category.rb +3 -0
- data/test/models/club.rb +6 -0
- data/test/models/company.rb +25 -1
- data/test/models/customer.rb +19 -1
- data/test/models/member.rb +2 -0
- data/test/models/member_detail.rb +4 -0
- data/test/models/organization.rb +4 -0
- data/test/models/parrot.rb +1 -0
- data/test/models/post.rb +3 -0
- data/test/models/reply.rb +0 -0
- data/test/models/topic.rb +3 -0
- data/test/schema/schema.rb +12 -1
- metadata +22 -10
- data/lib/active_record/vendor/mysql.rb +0 -1214
- data/test/cases/adapter_test_sqlserver.rb +0 -95
- data/test/cases/table_name_test_sqlserver.rb +0 -23
- data/test/cases/threaded_connections_test.rb +0 -48
- 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
|
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
|
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
|
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:
|
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:
|
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
|
-
|
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
|
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
|
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
|
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
|
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
|
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
|
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 => "長すぎます:
|
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 => "短すぎます:
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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!(
|
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!(
|
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
|
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
|
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
|
-
|
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';
|
data/test/fixtures/companies.yml
CHANGED
data/test/fixtures/customers.yml
CHANGED
@@ -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
|
Binary file
|
Binary file
|
data/test/models/author.rb
CHANGED
@@ -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%'"
|
data/test/models/category.rb
CHANGED
@@ -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
|
data/test/models/club.rb
CHANGED
@@ -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
|
data/test/models/company.rb
CHANGED
@@ -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
|