Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45625 from adrianna-chang-shopify/ac-extract-buil…
…d-create-table-definition Extract `#build_create_table_definition` method
- Loading branch information
Showing
4 changed files
with
75 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
activerecord/test/cases/migration/schema_definitions_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
require "cases/helper" | ||
|
||
module ActiveRecord | ||
class Migration | ||
class SchemaDefinitionsTest < ActiveRecord::TestCase | ||
attr_reader :connection | ||
|
||
def setup | ||
@connection = ActiveRecord::Base.connection | ||
end | ||
|
||
def test_build_create_table_definition_with_block | ||
td = connection.build_create_table_definition :test do |t| | ||
t.column :foo, :string | ||
end | ||
|
||
id_column = td.columns.find { |col| col.name == "id" } | ||
assert_predicate id_column, :present? | ||
assert id_column.type | ||
assert id_column.sql_type | ||
|
||
foo_column = td.columns.find { |col| col.name == "foo" } | ||
assert_predicate foo_column, :present? | ||
assert foo_column.type | ||
assert foo_column.sql_type | ||
end | ||
|
||
def test_build_create_table_definition_without_block | ||
td = connection.build_create_table_definition(:test) | ||
|
||
id_column = td.columns.find { |col| col.name == "id" } | ||
assert_predicate id_column, :present? | ||
assert id_column.type | ||
assert id_column.sql_type | ||
end | ||
end | ||
end | ||
end |