@@ -403,51 +403,18 @@ def test_values_cast_from_nil_are_persisted_as_nil
403
403
assert_equal [ topic , topic2 ] , Topic . where ( content : nil ) . sort_by ( &:id )
404
404
end
405
405
406
- # MySQL doesn't support default values for text columns, so we need to skip this test for MySQL
407
- if !current_adapter? ( :Mysql2Adapter )
408
- def test_serialized_attribute_with_default_can_update_to_default
409
- @verbose_was = ActiveRecord ::Migration . verbose
410
- ActiveRecord ::Migration . verbose = false
411
-
412
- ActiveRecord ::Schema . define do
413
- create_table :tmp_posts , force : true do |t |
414
- t . text :content , null : false , default : "{}"
415
- end
416
- end
417
- klass = Class . new ( ActiveRecord ::Base ) do
418
- self . table_name = "tmp_posts"
419
- serialize ( :content , type : Hash )
420
- end
421
-
422
- t = klass . create! ( content : { "other_key" => "new_value" } )
423
- assert_equal ( { "other_key" => "new_value" } , t . content )
424
-
425
- t . update! ( content : { } )
426
- assert_equal ( { } , t . content )
427
- ensure
428
- ActiveRecord ::Migration . verbose = @verbose_was
406
+ def test_serialized_attribute_can_be_defined_in_abstract_classes
407
+ klass = Class . new ( ActiveRecord ::Base ) do
408
+ self . abstract_class = true
409
+ self . table_name = nil
410
+ serialize ( :content , type : Hash )
429
411
end
430
412
431
- def test_nil_is_always_persisted_as_default
432
- @verbose_was = ActiveRecord ::Migration . verbose
433
- ActiveRecord ::Migration . verbose = false
434
-
435
- ActiveRecord ::Schema . define do
436
- create_table :tmp_posts , force : true do |t |
437
- t . text :content , null : false , default : "{}"
438
- end
439
- end
440
- klass = Class . new ( ActiveRecord ::Base ) do
441
- self . table_name = "tmp_posts"
442
- serialize ( :content , type : Hash )
443
- end
444
-
445
- t = klass . create! ( content : { foo : "bar" } )
446
- t . update_attribute :content , nil
447
- assert_equal ( { } , t . content )
448
- ensure
449
- ActiveRecord ::Migration . verbose = @verbose_was
413
+ subclass = Class . new ( klass ) do
414
+ self . table_name = "posts"
450
415
end
416
+
417
+ subclass . define_attribute_methods
451
418
end
452
419
453
420
def test_nil_is_always_persisted_as_null
0 commit comments