aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/schema_dumper_test.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2016-08-22 15:46:04 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2016-08-22 15:46:04 -0300
commitdf84e9867219e9311aef6f4efd5dd9ec675bee5c (patch)
tree69e1aaa4201ca87ad671a90adfc60bf8ae9eb58a /activerecord/test/cases/schema_dumper_test.rb
parentd25a5ce256c56d2f9e140aaf59f48945ddfcac1a (diff)
downloadrails-df84e9867219e9311aef6f4efd5dd9ec675bee5c.tar.gz
rails-df84e9867219e9311aef6f4efd5dd9ec675bee5c.tar.bz2
rails-df84e9867219e9311aef6f4efd5dd9ec675bee5c.zip
Remove the SchemaDumper options and change the default behavior
Now the schema dumper by default doesn't align the types and arguments in the ruby format anymore.
Diffstat (limited to 'activerecord/test/cases/schema_dumper_test.rb')
-rw-r--r--activerecord/test/cases/schema_dumper_test.rb105
1 files changed, 12 insertions, 93 deletions
diff --git a/activerecord/test/cases/schema_dumper_test.rb b/activerecord/test/cases/schema_dumper_test.rb
index 23cfe46d7f..57b1bc889a 100644
--- a/activerecord/test/cases/schema_dumper_test.rb
+++ b/activerecord/test/cases/schema_dumper_test.rb
@@ -70,38 +70,35 @@ class SchemaDumperTest < ActiveRecord::TestCase
assert_match %r{create_table "CamelCase"}, output
end
- def assert_line_up(lines, pattern, required = false)
+ def assert_no_line_up(lines, pattern)
return assert(true) if lines.empty?
matches = lines.map { |line| line.match(pattern) }
- 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
+ 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_types_line_up
+ def test_types_no_line_up
column_definition_lines.each do |column_set|
next if column_set.empty?
- lengths = column_set.map do |column|
- if match = column.match(/\bt\.\w+\s+(?="\w+?")/)
- match[0].length
- end
- end.compact
-
- assert_equal 1, lengths.uniq.length
+ assert column_set.all? { |column| !column.match(/\bt\.\w+\s{2,}/) }
end
end
- def test_arguments_line_up
+ def test_arguments_no_line_up
column_definition_lines.each do |column_set|
- assert_line_up(column_set, /default: /)
- assert_line_up(column_set, /limit: /)
- assert_line_up(column_set, /null: /)
+ assert_no_line_up(column_set, /default: /)
+ assert_no_line_up(column_set, /limit: /)
+ assert_no_line_up(column_set, /null: /)
end
end
@@ -442,81 +439,3 @@ 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