Skip to content

Commit

Permalink
Ensure t.timestamps respects options. [#828 state:resolved]
Browse files Browse the repository at this point in the history
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
Patrick Reagan authored and tarmo committed Aug 24, 2008
1 parent 8e75057 commit 9c11b96
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
Expand Up @@ -444,9 +444,10 @@ def #{column_type}(*args)

# Appends <tt>:datetime</tt> columns <tt>:created_at</tt> and
# <tt>:updated_at</tt> to the table.
def timestamps
column(:created_at, :datetime)
column(:updated_at, :datetime)
def timestamps(*args)
options = args.extract_options!
column(:created_at, :datetime, options)
column(:updated_at, :datetime, options)
end

def references(*args)
Expand Down
37 changes: 35 additions & 2 deletions activerecord/test/cases/migration_test.rb
Expand Up @@ -237,6 +237,39 @@ def test_create_table_with_force_true_does_not_drop_nonexisting_table
end
end

def test_create_table_with_timestamps_should_create_datetime_columns
table_name = :testings

Person.connection.create_table table_name do |t|
t.timestamps
end
created_columns = Person.connection.columns(table_name)

created_at_column = created_columns.detect {|c| c.name == 'created_at' }
updated_at_column = created_columns.detect {|c| c.name == 'updated_at' }

assert created_at_column.null
assert updated_at_column.null
ensure
Person.connection.drop_table table_name rescue nil
end

def test_create_table_with_timestamps_should_create_datetime_columns_with_options
table_name = :testings

Person.connection.create_table table_name do |t|
t.timestamps :null => false
end
created_columns = Person.connection.columns(table_name)

created_at_column = created_columns.detect {|c| c.name == 'created_at' }
updated_at_column = created_columns.detect {|c| c.name == 'updated_at' }

assert !created_at_column.null
assert !updated_at_column.null
ensure
Person.connection.drop_table table_name rescue nil
end

# SQL Server, Sybase, and SQLite3 will not allow you to add a NOT NULL
# column to a table without a default value.
Expand Down Expand Up @@ -1172,8 +1205,8 @@ def test_belongs_to_works_like_references

def test_timestamps_creates_updated_at_and_created_at
with_new_table do |t|
t.expects(:column).with(:created_at, :datetime)
t.expects(:column).with(:updated_at, :datetime)
t.expects(:column).with(:created_at, :datetime, kind_of(Hash))
t.expects(:column).with(:updated_at, :datetime, kind_of(Hash))
t.timestamps
end
end
Expand Down

0 comments on commit 9c11b96

Please sign in to comment.