0
require 'active_record/schema_dumper'
0
-if ActiveRecord::Base.connection.respond_to?(:tables)
0
- class SchemaDumperTest < ActiveRecord::TestCase
0
- ActiveRecord::SchemaDumper.ignore_tables = []
0
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
0
+class SchemaDumperTest < ActiveRecord::TestCase
0
+ ActiveRecord::SchemaDumper.ignore_tables = []
0
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
0
- output = standard_dump
0
- assert_match %r{create_table "accounts"}, output
0
- assert_match %r{create_table "authors"}, output
0
- assert_no_match %r{create_table "schema_migrations"}, output
0
+ output = standard_dump
0
+ assert_match %r{create_table "accounts"}, output
0
+ assert_match %r{create_table "authors"}, output
0
+ assert_no_match %r{create_table "schema_migrations"}, output
0
- def test_schema_dump_excludes_sqlite_sequence
0
- output = standard_dump
0
- assert_no_match %r{create_table "sqlite_sequence"}, output
0
+ def test_schema_dump_excludes_sqlite_sequence
0
+ output = standard_dump
0
+ assert_no_match %r{create_table "sqlite_sequence"}, output
0
- def assert_line_up(lines, pattern, required = false)
0
- return assert(true) if lines.empty?
0
- matches = lines.map { |line| line.match(pattern) }
0
- assert matches.all? if required
0
- return assert(true) if matches.empty?
0
- assert_equal 1, matches.map{ |match| match.offset(0).first }.uniq.length
0
+ def assert_line_up(lines, pattern, required = false)
0
+ return assert(true) if lines.empty?
0
+ matches = lines.map { |line| line.match(pattern) }
0
+ assert matches.all? if required
0
+ return assert(true) if matches.empty?
0
+ assert_equal 1, matches.map{ |match| match.offset(0).first }.uniq.length
0
- def column_definition_lines(output = standard_dump)
0
- output.scan(/^( *)create_table.*?\n(.*?)^\1end/m).map{ |m| m.last.split(/\n/) }
0
+ def column_definition_lines(output = standard_dump)
0
+ output.scan(/^( *)create_table.*?\n(.*?)^\1end/m).map{ |m| m.last.split(/\n/) }
0
- def test_types_line_up
0
- column_definition_lines.each do |column_set|
0
- next if column_set.empty?
0
+ def test_types_line_up
0
+ column_definition_lines.each do |column_set|
0
+ next if column_set.empty?
0
- lengths = column_set.map do |column|
0
- if match = column.match(/t\.(?:integer|decimal|float|datetime|timestamp|time|date|text|binary|string|boolean)\s+"/)
0
+ lengths = column_set.map do |column|
0
+ if match = column.match(/t\.(?:integer|decimal|float|datetime|timestamp|time|date|text|binary|string|boolean)\s+"/)
0
- assert_equal 1, lengths.uniq.length
0
- def test_arguments_line_up
0
- column_definition_lines.each do |column_set|
0
- assert_line_up(column_set, /:default => /)
0
- assert_line_up(column_set, /:limit => /)
0
- assert_line_up(column_set, /:null => /)
0
+ assert_equal 1, lengths.uniq.length
0
- def test_no_dump_errors
0
- output = standard_dump
0
- assert_no_match %r{\# Could not dump table}, output
0
+ def test_arguments_line_up
0
+ column_definition_lines.each do |column_set|
0
+ assert_line_up(column_set, /:default => /)
0
+ assert_line_up(column_set, /:limit => /)
0
+ assert_line_up(column_set, /:null => /)
0
- def test_schema_dump_includes_not_null_columns
0
+ def test_no_dump_errors
0
+ output = standard_dump
0
+ assert_no_match %r{\# Could not dump table}, output
0
- ActiveRecord::SchemaDumper.ignore_tables = [/^[^r]/]
0
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
0
- output = stream.string
0
- assert_match %r{:null => false}, output
0
+ def test_schema_dump_includes_not_null_columns
0
- def test_schema_dump_with_string_ignored_table
0
+ ActiveRecord::SchemaDumper.ignore_tables = [/^[^r]/]
0
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
0
+ output = stream.string
0
+ assert_match %r{:null => false}, output
0
- ActiveRecord::SchemaDumper.ignore_tables = ['accounts']
0
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
0
- output = stream.string
0
- assert_no_match %r{create_table "accounts"}, output
0
- assert_match %r{create_table "authors"}, output
0
- assert_no_match %r{create_table "schema_migrations"}, output
0
+ def test_schema_dump_with_string_ignored_table
0
- def test_schema_dump_with_regexp_ignored_table
0
+ ActiveRecord::SchemaDumper.ignore_tables = ['accounts']
0
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
0
+ output = stream.string
0
+ assert_no_match %r{create_table "accounts"}, output
0
+ assert_match %r{create_table "authors"}, output
0
+ assert_no_match %r{create_table "schema_migrations"}, output
0
- ActiveRecord::SchemaDumper.ignore_tables = [/^account/]
0
+ def test_schema_dump_with_regexp_ignored_table
0
+ ActiveRecord::SchemaDumper.ignore_tables = [/^account/]
0
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
0
+ output = stream.string
0
+ assert_no_match %r{create_table "accounts"}, output
0
+ assert_match %r{create_table "authors"}, output
0
+ assert_no_match %r{create_table "schema_migrations"}, output
0
+ def test_schema_dump_illegal_ignored_table_value
0
+ ActiveRecord::SchemaDumper.ignore_tables = [5]
0
+ assert_raise(StandardError) do
0
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
0
- output = stream.string
0
- assert_no_match %r{create_table "accounts"}, output
0
- assert_match %r{create_table "authors"}, output
0
- assert_no_match %r{create_table "schema_migrations"}, output
0
- def test_schema_dump_illegal_ignored_table_value
0
- ActiveRecord::SchemaDumper.ignore_tables = [5]
0
- assert_raise(StandardError) do
0
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
0
+ if current_adapter?(:MysqlAdapter)
0
+ def test_schema_dump_should_not_add_default_value_for_mysql_text_field
0
+ output = standard_dump
0
+ assert_match %r{t.text\s+"body",\s+:null => false$}, output
0
- if current_adapter?(:MysqlAdapter)
0
- def test_schema_dump_should_not_add_default_value_for_mysql_text_field
0
- output = standard_dump
0
- assert_match %r{t.text\s+"body",\s+:null => false$}, output
0
- def test_mysql_schema_dump_should_honor_nonstandard_primary_keys
0
- output = standard_dump
0
- match = output.match(%r{create_table "movies"(.*)do})
0
- assert_not_nil(match, "nonstandardpk table not found")
0
- assert_match %r(:primary_key => "movieid"), match[1], "non-standard primary key not preserved"
0
- def test_schema_dump_includes_length_for_mysql_blob_and_text_fields
0
- output = standard_dump
0
- assert_match %r{t.binary\s+"tiny_blob",\s+:limit => 255$}, output
0
- assert_match %r{t.binary\s+"normal_blob"$}, output
0
- assert_match %r{t.binary\s+"medium_blob",\s+:limit => 16777215$}, output
0
- assert_match %r{t.binary\s+"long_blob",\s+:limit => 2147483647$}, output
0
- assert_match %r{t.text\s+"tiny_text",\s+:limit => 255$}, output
0
- assert_match %r{t.text\s+"normal_text"$}, output
0
- assert_match %r{t.text\s+"medium_text",\s+:limit => 16777215$}, output
0
- assert_match %r{t.text\s+"long_text",\s+:limit => 2147483647$}, output
0
+ def test_mysql_schema_dump_should_honor_nonstandard_primary_keys
0
+ output = standard_dump
0
+ match = output.match(%r{create_table "movies"(.*)do})
0
+ assert_not_nil(match, "nonstandardpk table not found")
0
+ assert_match %r(:primary_key => "movieid"), match[1], "non-standard primary key not preserved"
0
- def test_schema_dump_includes_decimal_options
0
- ActiveRecord::SchemaDumper.ignore_tables = [/^[^n]/]
0
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
0
- output = stream.string
0
- assert_match %r{:precision => 3,[[:space:]]+:scale => 2,[[:space:]]+:default => 2.78}, output
0
+ def test_schema_dump_includes_length_for_mysql_blob_and_text_fields
0
+ output = standard_dump
0
+ assert_match %r{t.binary\s+"tiny_blob",\s+:limit => 255$}, output
0
+ assert_match %r{t.binary\s+"normal_blob"$}, output
0
+ assert_match %r{t.binary\s+"medium_blob",\s+:limit => 16777215$}, output
0
+ assert_match %r{t.binary\s+"long_blob",\s+:limit => 2147483647$}, output
0
+ assert_match %r{t.text\s+"tiny_text",\s+:limit => 255$}, output
0
+ assert_match %r{t.text\s+"normal_text"$}, output
0
+ assert_match %r{t.text\s+"medium_text",\s+:limit => 16777215$}, output
0
+ assert_match %r{t.text\s+"long_text",\s+:limit => 2147483647$}, output
0
+ def test_schema_dump_includes_decimal_options
0
+ ActiveRecord::SchemaDumper.ignore_tables = [/^[^n]/]
0
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, stream)
0
+ output = stream.string
0
+ assert_match %r{:precision => 3,[[:space:]]+:scale => 2,[[:space:]]+:default => 2.78}, output
Comments
No one has commented yet.