Browse files

Merge pull request #9597 from senny/9110_serialized_not_null_default

test case for `serialize` default values.
  • Loading branch information...
2 parents 2e3e171 + fa18c61 commit c6839277a9262ea87329c719443cf19e33038f3f @rafaelfranca rafaelfranca committed Mar 7, 2013
View
7 activerecord/test/cases/serialized_attribute_test.rb
@@ -1,6 +1,7 @@
require 'cases/helper'
require 'models/topic'
require 'models/person'
+require 'models/traffic_light'
require 'bcrypt'
class SerializedAttributeTest < ActiveRecord::TestCase
@@ -234,4 +235,10 @@ def test_serialize_attribute_can_be_serialized_in_an_integer_column
person = person.reload
assert_equal(insures, person.insures)
end
+
+ def test_regression_serialized_default_on_text_column_with_null_false
+ light = TrafficLight.new
+ assert_equal [], light.state
+ assert_equal [], light.long_state
+ end
end
View
4 activerecord/test/fixtures/traffic_lights.yml
@@ -4,3 +4,7 @@ uk:
- Green
- Red
- Orange
+ long_state:
+ - "Green, go ahead"
+ - "Red, wait"
+ - "Orange, caution light is about to switch"
View
1 activerecord/test/models/traffic_light.rb
@@ -1,3 +1,4 @@
class TrafficLight < ActiveRecord::Base
serialize :state, Array
+ serialize :long_state, Array
end
View
1 activerecord/test/schema/schema.rb
@@ -687,6 +687,7 @@ def create_table(*args, &block)
create_table :traffic_lights, :force => true do |t|
t.string :location
t.string :state
+ t.text :long_state, :null => false
t.datetime :created_at
t.datetime :updated_at
end

0 comments on commit c683927

Please sign in to comment.