Repository: rails/rails
File: activerecord/test/cases/schema_dumper_test.rb (Ruby)

Code before:
    end

    def test_schema_dump_include_limit_for_float4_field
      output = dump_table_schema "numeric_data"
      assert_match %r{t\.float\s+"temperature_with_limit",\s+limit: 24$}, output
    end

    def test_schema_dump_keeps_enum_intact_if_it_contains_comma
      original, $stdout = $stdout, StringIO.new

      migration = Class.new(ActiveRecord::Migration::Current) do
        def up
          create_enum "enum_with_comma", ["value1", "value,2", "value3"]
        end

        def down
          drop_enum "enum_with_comma"
        end
      end

      migration.migrate(:up)
      output = dump_all_table_schema

      assert_match %r{create_enum "enum_with_comma", \["value1", "value,2", "value3"\]}, output
    ensure
      migration.migrate(:down) if migration
      $stdout = original
    end
  end

  def test_schema_dump_keeps_large_precision_integer_columns_as_decimal
    output = standard_dump

    assert_match %r{t\.decimal\s+"atoms_in_universe",\s+precision: 55}, output
  end

  def test_schema_dump_keeps_id_column_when_id_is_false_and_id_column_added
    output = standard_dump
    match = output.match(%r{create_table "goofy_string_id"(.*)do.*\n(.*)\n})
    assert_not_nil(match, "goofy_string_id table not found")
    assert_match %r(id: false), match[1], "no table id not preserved"
    assert_match %r{t\.string\s+"id",.*?null: false$}, match[2], "non-primary key id column not preserved"
  end

  def test_schema_dump_keeps_id_false_when_id_is_false_and_unique_not_null_column_added
    output = standard_dump
    assert_match %r{create_table "string_key_objects", id: false}, output
  end

  if ActiveRecord::Base.lease_connection.supports_foreign_keys?
    def test_foreign_keys_are_dumped_at_the_bottom_to_circumvent_dependency_issues

Review comment (suggestion):
Already suggested in the previous snippet - without regexp looks simpler and `migration` can't be nil
```suggestion
      assert_includes output, 'create_enum "enum_with_comma", ["value1", "value,2", "value3"]', output
    ensure
      migration.migrate(:down)
```

Code after:
    end

    def test_schema_dump_include_limit_for_float4_field
      output = dump_table_schema "numeric_data"
      assert_match %r{t\.float\s+"temperature_with_limit",\s+limit: 24$}, output
    end

    def test_schema_dump_keeps_enum_intact_if_it_contains_comma
      original, $stdout = $stdout, StringIO.new

      migration = Class.new(ActiveRecord::Migration::Current) do
        def up
          create_enum "enum_with_comma", ["value1", "value,2", "value3"]
        end

        def down
          drop_enum "enum_with_comma"
        end
      end

      migration.migrate(:up)
      output = dump_all_table_schema

      assert_includes output, 'create_enum "enum_with_comma", ["value1", "value,2", "value3"]', output
    ensure
      migration.migrate(:down)
      $stdout = original
    end
  end

  def test_schema_dump_keeps_large_precision_integer_columns_as_decimal
    output = standard_dump

    assert_match %r{t\.decimal\s+"atoms_in_universe",\s+precision: 55}, output
  end

  def test_schema_dump_keeps_id_column_when_id_is_false_and_id_column_added
    output = standard_dump
    match = output.match(%r{create_table "goofy_string_id"(.*)do.*\n(.*)\n})
    assert_not_nil(match, "goofy_string_id table not found")
    assert_match %r(id: false), match[1], "no table id not preserved"
    assert_match %r{t\.string\s+"id",.*?null: false$}, match[2], "non-primary key id column not preserved"
  end

  def test_schema_dump_keeps_id_false_when_id_is_false_and_unique_not_null_column_added
    output = standard_dump
    assert_match %r{create_table "string_key_objects", id: false}, output
  end

  if ActiveRecord::Base.lease_connection.supports_foreign_keys?
    def test_foreign_keys_are_dumped_at_the_bottom_to_circumvent_dependency_issues