diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-07-29 12:23:37 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-07-29 12:23:37 -0700 |
commit | 3d6e1872550f284dd387ffc87a984a9036376062 (patch) | |
tree | b948b26d46341062d9598af78ba37bd664b49edf | |
parent | 455e9e748d97dc3b4f379563ca72d0ea15e73fa8 (diff) | |
download | rails-3d6e1872550f284dd387ffc87a984a9036376062.tar.gz rails-3d6e1872550f284dd387ffc87a984a9036376062.tar.bz2 rails-3d6e1872550f284dd387ffc87a984a9036376062.zip |
dump IO encoding value along with schema.rb so the file can be reloaded. fixes #1592
-rw-r--r-- | activerecord/lib/active_record/schema_dumper.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/schema_dumper_test.rb | 15 |
2 files changed, 16 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb index 19585f6214..6fe305f843 100644 --- a/activerecord/lib/active_record/schema_dumper.rb +++ b/activerecord/lib/active_record/schema_dumper.rb @@ -40,6 +40,10 @@ module ActiveRecord def header(stream) define_params = @version ? ":version => #{@version}" : "" + if stream.respond_to?(:external_encoding) + stream.puts "# encoding: #{stream.external_encoding.name}" + end + stream.puts <<HEADER # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb index 4adecf8e83..5da3f59a1f 100644 --- a/activerecord/test/cases/schema_dumper_test.rb +++ b/activerecord/test/cases/schema_dumper_test.rb @@ -3,11 +3,20 @@ require 'stringio' class SchemaDumperTest < ActiveRecord::TestCase + def setup + @stream = StringIO.new + end + def standard_dump - stream = StringIO.new + @stream = StringIO.new ActiveRecord::SchemaDumper.ignore_tables = [] - ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream) - stream.string + ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, @stream) + @stream.string + end + + def test_magic_comment + skip "only test magic comments on 1.9" if RUBY_VERSION < '1.9' + assert_match "# encoding: #{@stream.external_encoding.name}", standard_dump end def test_schema_dump |