aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/schema_dumper_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases/schema_dumper_test.rb')
-rw-r--r--activerecord/test/cases/schema_dumper_test.rb106
1 files changed, 92 insertions, 14 deletions
diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb
index 12f4196724..23cfe46d7f 100644
--- a/activerecord/test/cases/schema_dumper_test.rb
+++ b/activerecord/test/cases/schema_dumper_test.rb
@@ -1,5 +1,5 @@
require "cases/helper"
-require 'support/schema_dumping_helper'
+require "support/schema_dumping_helper"
class SchemaDumperTest < ActiveRecord::TestCase
include SchemaDumpingHelper
@@ -20,7 +20,7 @@ class SchemaDumperTest < ActiveRecord::TestCase
def test_dump_schema_information_outputs_lexically_ordered_versions
versions = %w{ 20100101010101 20100201010101 20100301010101 }
versions.reverse_each do |v|
- ActiveRecord::SchemaMigration.create!(:version => v)
+ ActiveRecord::SchemaMigration.create!(version: v)
end
schema_info = ActiveRecord::Base.connection.dump_schema_information
@@ -37,7 +37,7 @@ class SchemaDumperTest < ActiveRecord::TestCase
versions = %w{ 20100101010101 20100201010101 20100301010101 }
versions.reverse_each do |v|
- ActiveRecord::SchemaMigration.create!(:version => v)
+ ActiveRecord::SchemaMigration.create!(version: v)
end
schema_info = ActiveRecord::Base.connection.dump_schema_information
@@ -76,11 +76,11 @@ class SchemaDumperTest < ActiveRecord::TestCase
assert matches.all? if required
matches.compact!
return assert(true) if matches.empty?
- assert_equal 1, matches.map{ |match| match.offset(0).first }.uniq.length
+ assert_equal 1, matches.map { |match| match.offset(0).first }.uniq.length
end
def column_definition_lines(output = standard_dump)
- output.scan(/^( *)create_table.*?\n(.*?)^\1end/m).map{ |m| m.last.split(/\n/) }
+ output.scan(/^( *)create_table.*?\n(.*?)^\1end/m).map { |m| m.last.split(/\n/) }
end
def test_types_line_up
@@ -169,7 +169,7 @@ class SchemaDumperTest < ActiveRecord::TestCase
end
def test_schema_dump_with_string_ignored_table
- output = dump_all_table_schema(['accounts'])
+ output = dump_all_table_schema(["accounts"])
assert_no_match %r{create_table "accounts"}, output
assert_match %r{create_table "authors"}, output
assert_no_match %r{create_table "schema_migrations"}, output
@@ -289,7 +289,7 @@ class SchemaDumperTest < ActiveRecord::TestCase
def test_schema_dump_includes_extensions
connection = ActiveRecord::Base.connection
- connection.stubs(:extensions).returns(['hstore'])
+ connection.stubs(:extensions).returns(["hstore"])
output = perform_schema_dump
assert_match "# These are extensions that must be enabled", output
assert_match %r{enable_extension "hstore"}, output
@@ -359,8 +359,8 @@ class SchemaDumperTest < ActiveRecord::TestCase
def test_schema_dump_with_table_name_prefix_and_suffix
original, $stdout = $stdout, StringIO.new
- ActiveRecord::Base.table_name_prefix = 'foo_'
- ActiveRecord::Base.table_name_suffix = '_bar'
+ ActiveRecord::Base.table_name_prefix = "foo_"
+ ActiveRecord::Base.table_name_suffix = "_bar"
migration = CreateDogMigration.new
migration.migrate(:up)
@@ -378,7 +378,7 @@ class SchemaDumperTest < ActiveRecord::TestCase
ensure
migration.migrate(:down)
- ActiveRecord::Base.table_name_suffix = ActiveRecord::Base.table_name_prefix = ''
+ ActiveRecord::Base.table_name_suffix = ActiveRecord::Base.table_name_prefix = ""
$stdout = original
end
@@ -396,7 +396,7 @@ class SchemaDumperTest < ActiveRecord::TestCase
original_table_name_prefix = ActiveRecord::Base.table_name_prefix
original_schema_dumper_ignore_tables = ActiveRecord::SchemaDumper.ignore_tables
- ActiveRecord::Base.table_name_prefix = 'omg_'
+ ActiveRecord::Base.table_name_prefix = "omg_"
ActiveRecord::SchemaDumper.ignore_tables = ["cats"]
migration = create_cat_migration.new
migration.migrate(:up)
@@ -422,7 +422,7 @@ class SchemaDumperDefaultsTest < ActiveRecord::TestCase
@connection = ActiveRecord::Base.connection
@connection.create_table :defaults, force: true do |t|
t.string :string_with_default, default: "Hello!"
- t.date :date_with_default, default: '2014-06-05'
+ t.date :date_with_default, default: "2014-06-05"
t.datetime :datetime_with_default, default: "2014-06-05 07:17:04"
t.time :time_with_default, default: "07:17:04"
end
@@ -430,11 +430,11 @@ class SchemaDumperDefaultsTest < ActiveRecord::TestCase
teardown do
return unless @connection
- @connection.drop_table 'defaults', if_exists: true
+ @connection.drop_table "defaults", if_exists: true
end
def test_schema_dump_defaults_with_universally_supported_types
- output = dump_table_schema('defaults')
+ output = dump_table_schema("defaults")
assert_match %r{t\.string\s+"string_with_default",.*?default: "Hello!"}, output
assert_match %r{t\.date\s+"date_with_default",\s+default: '2014-06-05'}, output
@@ -442,3 +442,81 @@ class SchemaDumperDefaultsTest < ActiveRecord::TestCase
assert_match %r{t\.time\s+"time_with_default",\s+default: '2000-01-01 07:17:04'}, output
end
end
+
+class SchemaDumperNoStandardizedArgumentWidthsTest < ActiveRecord::TestCase
+ include SchemaDumpingHelper
+
+ setup do
+ ActiveRecord::SchemaDumper.standardized_argument_widths = false
+ ActiveRecord::SchemaMigration.create_table
+ end
+
+ teardown do
+ ActiveRecord::SchemaDumper.standardized_argument_widths = true
+ end
+
+ def standard_dump
+ @@standard_dump ||= perform_schema_dump
+ end
+
+ def perform_schema_dump
+ dump_all_table_schema []
+ end
+
+ def assert_no_line_up(lines, pattern)
+ return assert(true) if lines.empty?
+ matches = lines.map { |line| line.match(pattern) }
+ matches.compact!
+ return assert(true) if matches.empty?
+ line_matches = lines.map { |line| [line, line.match(pattern)] }.select { |line, match| match }
+ assert line_matches.all? { |line, match|
+ start = match.offset(0).first
+ line[start - 2..start - 1] == ", "
+ }
+ end
+
+ def column_definition_lines(output = standard_dump)
+ output.scan(/^( *)create_table.*?\n(.*?)^\1end/m).map { |m| m.last.split(/\n/) }
+ end
+
+ def test_arguments_no_line_up
+ column_definition_lines.each do |column_set|
+ assert_no_line_up(column_set, /default: /)
+ assert_no_line_up(column_set, /limit: /)
+ assert_no_line_up(column_set, /null: /)
+ end
+ end
+end
+
+class SchemaDumperNoStandardizedTypeWidthsTest < ActiveRecord::TestCase
+ include SchemaDumpingHelper
+
+ setup do
+ ActiveRecord::SchemaDumper.standardized_type_widths = false
+ ActiveRecord::SchemaMigration.create_table
+ end
+
+ teardown do
+ ActiveRecord::SchemaDumper.standardized_type_widths = true
+ end
+
+ def standard_dump
+ @@standard_dump ||= perform_schema_dump
+ end
+
+ def perform_schema_dump
+ dump_all_table_schema []
+ end
+
+ def column_definition_lines(output = standard_dump)
+ output.scan(/^( *)create_table.*?\n(.*?)^\1end/m).map { |m| m.last.split(/\n/) }
+ end
+
+ def test_types_no_line_up
+ column_definition_lines.each do |column_set|
+ next if column_set.empty?
+
+ assert column_set.all? { |column| !column.match(/\bt\.\w+\s{2,}/) }
+ end
+ end
+end