Skip to content

Commit a2f14e2

Browse files
committed
Revert "Merge pull request rails#1163 from amatsuda/sexier_migration_31"
This reverts commit 0e407a9, reversing changes made to 533a9f8. Conflicts: activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb activerecord/test/cases/migration_test.rb
1 parent 649f251 commit a2f14e2

File tree

4 files changed

+13
-142
lines changed

4 files changed

+13
-142
lines changed

activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,11 @@ def column_exists?(table_name, column_name, type = nil, options = {})
155155
# )
156156
#
157157
# See also TableDefinition#column for details on how to create columns.
158-
def create_table(table_name, options = {}, &blk)
158+
def create_table(table_name, options = {})
159159
td = table_definition
160160
td.primary_key(options[:primary_key] || Base.get_primary_key(table_name.to_s.singularize)) unless options[:id] == false
161161

162-
if block_given?
163-
if blk.arity == 1
164-
yield td
165-
else
166-
td.instance_eval(&blk)
167-
end
168-
end
162+
yield td if block_given?
169163

170164
if options[:force] && table_exists?(table_name)
171165
drop_table(table_name)

activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -480,30 +480,28 @@ def move_table(from, to, options = {}, &block) #:nodoc:
480480
drop_table(from)
481481
end
482482

483-
def copy_table(from, to, options = {}, &block) #:nodoc:
484-
from_columns, from_primary_key = columns(from), primary_key(from)
485-
options = options.merge(:id => (!from_columns.detect {|c| c.name == 'id'}.nil? && 'id' == primary_key(from).to_s))
486-
table_definition = nil
483+
def copy_table(from, to, options = {}) #:nodoc:
484+
options = options.merge(:id => (!columns(from).detect{|c| c.name == 'id'}.nil? && 'id' == primary_key(from).to_s))
487485
create_table(to, options) do |definition|
488-
table_definition = definition
489-
from_columns.each do |column|
486+
@definition = definition
487+
columns(from).each do |column|
490488
column_name = options[:rename] ?
491489
(options[:rename][column.name] ||
492490
options[:rename][column.name.to_sym] ||
493491
column.name) : column.name
494492

495-
table_definition.column(column_name, column.type,
493+
@definition.column(column_name, column.type,
496494
:limit => column.limit, :default => column.default,
497495
:precision => column.precision, :scale => column.scale,
498496
:null => column.null)
499497
end
500-
table_definition.primary_key from_primary_key if from_primary_key
501-
table_definition.instance_eval(&block) if block
498+
@definition.primary_key(primary_key(from)) if primary_key(from)
499+
yield @definition if block_given?
502500
end
503501

504502
copy_table_indexes(from, to, options[:rename] || {})
505503
copy_table_contents(from, to,
506-
table_definition.columns.map {|column| column.name},
504+
@definition.columns.map {|column| column.name},
507505
options[:rename] || {})
508506
end
509507

activerecord/lib/active_record/session_store.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,12 @@ def drop_table!
6464
end
6565

6666
def create_table!
67-
id_col_name, data_col_name = session_id_column, data_column_name
6867
connection_pool.clear_table_cache!(table_name)
6968
connection.create_table(table_name) do |t|
70-
t.string id_col_name, :limit => 255
71-
t.text data_col_name
69+
t.string session_id_column, :limit => 255
70+
t.text data_column_name
7271
end
73-
connection.add_index table_name, id_col_name, :unique => true
72+
connection.add_index table_name, session_id_column, :unique => true
7473
end
7574
end
7675

activerecord/test/cases/migration_test.rb

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,126 +1639,6 @@ def with_env_tz(new_tz = 'US/Eastern')
16391639

16401640
end
16411641

1642-
class SexyMigrationsTest < ActiveRecord::TestCase
1643-
def test_references_column_type_adds_id
1644-
with_new_table do |t|
1645-
t.expects(:column).with('customer_id', :integer, {})
1646-
t.references :customer
1647-
end
1648-
end
1649-
1650-
def test_references_column_type_with_polymorphic_adds_type
1651-
with_new_table do |t|
1652-
t.expects(:column).with('taggable_type', :string, {})
1653-
t.expects(:column).with('taggable_id', :integer, {})
1654-
t.references :taggable, :polymorphic => true
1655-
end
1656-
end
1657-
1658-
def test_references_column_type_with_polymorphic_and_options_null_is_false_adds_table_flag
1659-
with_new_table do |t|
1660-
t.expects(:column).with('taggable_type', :string, {:null => false})
1661-
t.expects(:column).with('taggable_id', :integer, {:null => false})
1662-
t.references :taggable, :polymorphic => true, :null => false
1663-
end
1664-
end
1665-
1666-
def test_belongs_to_works_like_references
1667-
with_new_table do |t|
1668-
t.expects(:column).with('customer_id', :integer, {})
1669-
t.belongs_to :customer
1670-
end
1671-
end
1672-
1673-
def test_timestamps_creates_updated_at_and_created_at
1674-
with_new_table do |t|
1675-
t.expects(:column).with(:created_at, :datetime, kind_of(Hash))
1676-
t.expects(:column).with(:updated_at, :datetime, kind_of(Hash))
1677-
t.timestamps
1678-
end
1679-
end
1680-
1681-
def test_integer_creates_integer_column
1682-
with_new_table do |t|
1683-
t.expects(:column).with(:foo, 'integer', {})
1684-
t.expects(:column).with(:bar, 'integer', {})
1685-
t.integer :foo, :bar
1686-
end
1687-
end
1688-
1689-
def test_string_creates_string_column
1690-
with_new_table do |t|
1691-
t.expects(:column).with(:foo, 'string', {})
1692-
t.expects(:column).with(:bar, 'string', {})
1693-
t.string :foo, :bar
1694-
end
1695-
end
1696-
1697-
if current_adapter?(:PostgreSQLAdapter) || current_adapter?(:SQLite3Adapter) || current_adapter?(:MysqlAdapter) || current_adapter?(:Mysql2Adapter)
1698-
def test_xml_creates_xml_column
1699-
type = current_adapter?(:PostgreSQLAdapter) ? 'xml' : :text
1700-
1701-
with_new_table do |t|
1702-
t.expects(:column).with(:data, type, {})
1703-
t.xml :data
1704-
end
1705-
end
1706-
else
1707-
def test_xml_creates_xml_column
1708-
with_new_table do |t|
1709-
assert_raises(NotImplementedError) do
1710-
t.xml :data
1711-
end
1712-
end
1713-
end
1714-
end
1715-
1716-
protected
1717-
def with_new_table
1718-
Person.connection.create_table :delete_me, :force => true do |t|
1719-
yield t
1720-
end
1721-
ensure
1722-
Person.connection.drop_table :delete_me rescue nil
1723-
end
1724-
1725-
end # SexyMigrationsTest
1726-
1727-
class SexierMigrationsTest < ActiveRecord::TestCase
1728-
def test_create_table_with_column_without_block_parameter
1729-
Person.connection.create_table :testings, :force => true do
1730-
column :foo, :string
1731-
end
1732-
assert Person.connection.column_exists?(:testings, :foo, :string)
1733-
ensure
1734-
Person.connection.drop_table :testings rescue nil
1735-
end
1736-
1737-
def test_create_table_with_sexy_column_without_block_parameter
1738-
Person.connection.create_table :testings, :force => true do
1739-
integer :bar
1740-
end
1741-
assert Person.connection.column_exists?(:testings, :bar, :integer)
1742-
ensure
1743-
Person.connection.drop_table :testings rescue nil
1744-
end
1745-
1746-
def test_create_table_should_not_have_mixed_syntax
1747-
assert_raise(NoMethodError) do
1748-
Person.connection.create_table :testings, :force => true do |t|
1749-
t.string :foo
1750-
integer :bar
1751-
end
1752-
end
1753-
assert_raise(NameError) do
1754-
Person.connection.create_table :testings, :force => true do
1755-
t.string :foo
1756-
integer :bar
1757-
end
1758-
end
1759-
end
1760-
end # SexierMigrationsTest
1761-
17621642
class MigrationLoggerTest < ActiveRecord::TestCase
17631643
def test_migration_should_be_run_without_logger
17641644
previous_logger = ActiveRecord::Base.logger

0 commit comments

Comments
 (0)