提交 108ae52c 编写于 作者: Y Yves Senn

`timestamps` and `add_timestamps` pass additional options. Closes #17624

Option passing was already supported when using `create_table` but not
for `change_table`. This patch aligns the method signatures.
上级 f8405822
* `timestamps` and `add_timestamps` passes additional options along.
(like `null: false`)
Closes #17624.
*Yves Senn*
## Rails 4.0.12 (November 16, 2014) ##
* Cache `CollectionAssociation#reader` proxies separately before and after
......
......@@ -393,8 +393,8 @@ def rename_index(index_name, new_index_name)
# Adds timestamps (+created_at+ and +updated_at+) columns to the table. See SchemaStatements#add_timestamps
#
# t.timestamps
def timestamps
@base.add_timestamps(@table_name)
def timestamps(options = {})
@base.add_timestamps(@table_name, options)
end
# Changes the column's definition according to the new options.
......
......@@ -727,9 +727,9 @@ def columns_for_distinct(columns, orders) #:nodoc:
#
# add_timestamps(:suppliers)
#
def add_timestamps(table_name)
add_column table_name, :created_at, :datetime
add_column table_name, :updated_at, :datetime
def add_timestamps(table_name, options = {})
add_column table_name, :created_at, :datetime, options
add_column table_name, :updated_at, :datetime, options
end
# Removes the timestamp columns (+created_at+ and +updated_at+) from the table definition.
......
......@@ -721,8 +721,8 @@ def remove_index_sql(table_name, options = {})
"DROP INDEX #{index_name}"
end
def add_timestamps_sql(table_name)
[add_column_sql(table_name, :created_at, :datetime), add_column_sql(table_name, :updated_at, :datetime)]
def add_timestamps_sql(table_name, options = {})
[add_column_sql(table_name, :created_at, :datetime, options), add_column_sql(table_name, :updated_at, :datetime, options)]
end
def remove_timestamps_sql(table_name)
......
......@@ -74,8 +74,8 @@ def test_remove_references_column_type_with_polymorphic_and_options_null_is_fals
def test_timestamps_creates_updated_at_and_created_at
with_change_table do |t|
@connection.expect :add_timestamps, nil, [:delete_me]
t.timestamps
@connection.expect :add_timestamps, nil, [:delete_me, {null: false}]
t.timestamps null: false
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册