public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Ensure t.timestamps respects options. [#828 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
reagent (author)
Fri Aug 22 04:48:00 -0700 2008
lifo (committer)
Fri Aug 22 04:48:00 -0700 2008
commit  683ff235e6b81d28962f5a71ff53730a1c118fc8
tree    6fbd872794f15d60bb89ed5eecdcf3c8ef3683b2
parent  52ac9d04442296abe7f05fc4701e1be7a0eed1f8
...
443
444
445
446
447
448
 
 
 
 
449
450
451
...
443
444
445
 
 
 
446
447
448
449
450
451
452
0
@@ -443,9 +443,10 @@ module ActiveRecord
0
 
0
       # Appends <tt>:datetime</tt> columns <tt>:created_at</tt> and
0
       # <tt>:updated_at</tt> to the table.
0
-      def timestamps
0
-        column(:created_at, :datetime)
0
-        column(:updated_at, :datetime)
0
+      def timestamps(*args)
0
+        options = args.extract_options!
0
+        column(:created_at, :datetime, options)
0
+        column(:updated_at, :datetime, options)
0
       end
0
 
0
       def references(*args)
...
237
238
239
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
241
242
...
1192
1193
1194
1195
1196
 
 
1197
1198
1199
...
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
...
1225
1226
1227
 
 
1228
1229
1230
1231
1232
0
@@ -237,6 +237,39 @@ if ActiveRecord::Base.connection.supports_migrations?
0
       end
0
     end
0
 
0
+    def test_create_table_with_timestamps_should_create_datetime_columns
0
+      table_name = :testings
0
+
0
+      Person.connection.create_table table_name do |t|
0
+        t.timestamps
0
+      end
0
+      created_columns = Person.connection.columns(table_name)
0
+
0
+      created_at_column = created_columns.detect {|c| c.name == 'created_at' }
0
+      updated_at_column = created_columns.detect {|c| c.name == 'updated_at' }
0
+
0
+      assert created_at_column.null
0
+      assert updated_at_column.null
0
+    ensure
0
+      Person.connection.drop_table table_name rescue nil
0
+    end
0
+
0
+    def test_create_table_with_timestamps_should_create_datetime_columns_with_options
0
+      table_name = :testings
0
+
0
+      Person.connection.create_table table_name do |t|
0
+        t.timestamps :null => false
0
+      end
0
+      created_columns = Person.connection.columns(table_name)
0
+
0
+      created_at_column = created_columns.detect {|c| c.name == 'created_at' }
0
+      updated_at_column = created_columns.detect {|c| c.name == 'updated_at' }
0
+
0
+      assert !created_at_column.null
0
+      assert !updated_at_column.null
0
+    ensure
0
+      Person.connection.drop_table table_name rescue nil
0
+    end
0
 
0
     # SQL Server, Sybase, and SQLite3 will not allow you to add a NOT NULL
0
     # column to a table without a default value.
0
@@ -1192,8 +1225,8 @@ if ActiveRecord::Base.connection.supports_migrations?
0
 
0
       def test_timestamps_creates_updated_at_and_created_at
0
         with_new_table do |t|
0
-          t.expects(:column).with(:created_at, :datetime)
0
-          t.expects(:column).with(:updated_at, :datetime)
0
+          t.expects(:column).with(:created_at, :datetime, kind_of(Hash))
0
+          t.expects(:column).with(:updated_at, :datetime, kind_of(Hash))
0
           t.timestamps
0
         end
0
       end

Comments