diff options
author | Paul Mucur <paul@altmetric.com> | 2015-02-11 10:05:17 +0000 |
---|---|---|
committer | Paul Mucur <paul@altmetric.com> | 2015-04-15 09:53:55 +0100 |
commit | c0abeadc0e62fc6f7a066f4d8db9895525ad8258 (patch) | |
tree | 5363c08d005c83dcff877a82294b252c31a7b45e /activerecord/test | |
parent | 5f00ed10dd820b6802168933c2497d17c43c88f5 (diff) | |
download | rails-c0abeadc0e62fc6f7a066f4d8db9895525ad8258.tar.gz rails-c0abeadc0e62fc6f7a066f4d8db9895525ad8258.tar.bz2 rails-c0abeadc0e62fc6f7a066f4d8db9895525ad8258.zip |
Fix missing index when using timestamps with index
The `index` option used with `timestamps` should be passed to both
`column` definitions for `created_at` and `updated_at` rather than just
the first.
This was happening because `Hash#delete` is used to extract the `index`
option passed to `timestamps`, thereby mutating the `options` hash
in-place. Now take a copy of the `options` before deleting so that the
original is not modified.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/timestamp_test.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/test/cases/timestamp_test.rb b/activerecord/test/cases/timestamp_test.rb index 7c89b4b9e8..5dab32995c 100644 --- a/activerecord/test/cases/timestamp_test.rb +++ b/activerecord/test/cases/timestamp_test.rb @@ -446,6 +446,17 @@ class TimestampTest < ActiveRecord::TestCase toy = Toy.first assert_equal [:created_at, :updated_at], toy.send(:all_timestamp_attributes_in_model) end + + def test_index_is_created_for_both_timestamps + ActiveRecord::Base.connection.create_table(:foos, force: true) do |t| + t.timestamps(:foos, null: true, index: true) + end + + indexes = ActiveRecord::Base.connection.indexes('foos') + assert_equal ['created_at', 'updated_at'], indexes.flat_map(&:columns).sort + ensure + ActiveRecord::Base.connection.drop_table(:foos) + end end class TimestampsWithoutTransactionTest < ActiveRecord::TestCase |