aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/schema_dumper_test.rb
diff options
context:
space:
mode:
authorMarcel Molina <marcel@vernix.org>2006-04-26 06:15:51 +0000
committerMarcel Molina <marcel@vernix.org>2006-04-26 06:15:51 +0000
commitf274a89f8b23cedf020a1d59a8fe0438d6bc9be9 (patch)
tree21cef2c22632ee0f882f32e94134a4bcc791ad26 /activerecord/test/schema_dumper_test.rb
parent5d61d2336cceebf388369f22fa4cfbc07983bde5 (diff)
downloadrails-f274a89f8b23cedf020a1d59a8fe0438d6bc9be9.tar.gz
rails-f274a89f8b23cedf020a1d59a8fe0438d6bc9be9.tar.bz2
rails-f274a89f8b23cedf020a1d59a8fe0438d6bc9be9.zip
Prettify output of schema_dumper by making things line up. Closes #4241 [Caio Chassot <caio@v2studio.com>]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4273 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/schema_dumper_test.rb')
-rw-r--r--activerecord/test/schema_dumper_test.rb33
1 files changed, 30 insertions, 3 deletions
diff --git a/activerecord/test/schema_dumper_test.rb b/activerecord/test/schema_dumper_test.rb
index 5dd0d4e9a2..37e8a99048 100644
--- a/activerecord/test/schema_dumper_test.rb
+++ b/activerecord/test/schema_dumper_test.rb
@@ -5,16 +5,43 @@ require 'stringio'
if ActiveRecord::Base.connection.respond_to?(:tables)
class SchemaDumperTest < Test::Unit::TestCase
- def test_schema_dump
+ def standard_dump
stream = StringIO.new
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
- output = stream.string
-
+ stream.string
+ end
+
+ def test_schema_dump
+ output = standard_dump
assert_match %r{create_table "accounts"}, output
assert_match %r{create_table "authors"}, output
assert_no_match %r{create_table "schema_info"}, output
end
+ def assert_line_up(lines, pattern, required = false)
+ 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
+ end
+
+ def test_arguments_line_up
+ output = standard_dump
+ output.scan(/^( *)create_table.*?\n(.*?)^\1end/m).map{ |m| m.last.split(/\n/) }.each do |column_set|
+ assert_line_up(column_set, /:(?:integer|float|datetime|timestamp|time|date|text|binary|string|boolean)/, true)
+ assert_line_up(column_set, /:default => /)
+ assert_line_up(column_set, /:limit => /)
+ assert_line_up(column_set, /:null => /)
+ end
+ end
+
+ def test_no_dump_errors
+ output = standard_dump
+ assert_no_match %r{\# Could not dump table}, output
+ end
+
def test_schema_dump_includes_not_null_columns
stream = StringIO.new