diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-06-10 08:42:47 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-06-10 08:42:47 -0600 |
commit | 47f1c10c8fb7ed9f8999dda5b4a7f42e34afeec6 (patch) | |
tree | 25c6a517916d0b943ab0fb74e653797fa0a2d1b7 /activerecord/test | |
parent | bfb8b139aaeecd3aaadb99c3f483c1420e59c384 (diff) | |
download | rails-47f1c10c8fb7ed9f8999dda5b4a7f42e34afeec6.tar.gz rails-47f1c10c8fb7ed9f8999dda5b4a7f42e34afeec6.tar.bz2 rails-47f1c10c8fb7ed9f8999dda5b4a7f42e34afeec6.zip |
Keep the types of virtual columns after yaml serialization
On MySQL and PostgreSQL, the adapter does not type cast virtual columns
for us.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/yaml_serialization_test.rb | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/activerecord/test/cases/yaml_serialization_test.rb b/activerecord/test/cases/yaml_serialization_test.rb index d4f8ef5b4d..9f1d110ddb 100644 --- a/activerecord/test/cases/yaml_serialization_test.rb +++ b/activerecord/test/cases/yaml_serialization_test.rb @@ -1,8 +1,10 @@ require 'cases/helper' require 'models/topic' +require 'models/post' +require 'models/author' class YamlSerializationTest < ActiveRecord::TestCase - fixtures :topics + fixtures :topics, :authors, :posts def test_to_yaml_with_time_with_zone_should_not_raise_exception with_timezone_config aware_attributes: true, zone: "Pacific Time (US & Canada)" do @@ -69,4 +71,15 @@ class YamlSerializationTest < ActiveRecord::TestCase assert_not topic.new_record?, "Loaded records without ID are not new" assert_not YAML.load(YAML.dump(topic)).new_record?, "Record should not be new after deserialization" end + + def test_types_of_virtual_columns_are_not_changed_on_round_trip + author = Author.select('authors.*, count(posts.id) as posts_count') + .joins(:posts) + .group('authors.id') + .first + dumped = YAML.load(YAML.dump(author)) + + assert_equal 5, author.posts_count + assert_equal 5, dumped.posts_count + end end |