| | 42 | def test_add_timestamps |
|---|
| | 43 | #we need to actually modify some data, so we make execute to point to the original method |
|---|
| | 44 | ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do |
|---|
| | 45 | alias_method :execute_with_stub, :execute |
|---|
| | 46 | alias_method :execute, :execute_without_stub |
|---|
| | 47 | end |
|---|
| | 48 | ActiveRecord::Base.connection.create_table :delete_me do |t| |
|---|
| | 49 | end |
|---|
| | 50 | ActiveRecord::Base.connection.add_timestamps :delete_me |
|---|
| | 51 | assert_equal ActiveRecord::Base.connection.execute("SHOW FIELDS FROM delete_me where FIELD='updated_at' AND TYPE='datetime'").num_rows, 1 |
|---|
| | 52 | assert_equal ActiveRecord::Base.connection.execute("SHOW FIELDS FROM delete_me where FIELD='created_at' AND TYPE='datetime'").num_rows, 1 |
|---|
| | 53 | ensure |
|---|
| | 54 | ActiveRecord::Base.connection.drop_table :delete_me rescue nil |
|---|
| | 55 | #before finishing, we restore the alias to the mock-up method |
|---|
| | 56 | ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do |
|---|
| | 57 | alias_method :execute, :execute_with_stub |
|---|
| | 58 | end |
|---|
| | 59 | end |
|---|
| | 60 | |
|---|
| | 61 | def test_remove_timestamps |
|---|
| | 62 | #we need to actually modify some data, so we make execute to point to the original method |
|---|
| | 63 | ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do |
|---|
| | 64 | alias_method :execute_with_stub, :execute |
|---|
| | 65 | alias_method :execute, :execute_without_stub |
|---|
| | 66 | end |
|---|
| | 67 | ActiveRecord::Base.connection.create_table :delete_me do |t| |
|---|
| | 68 | t.timestamps |
|---|
| | 69 | end |
|---|
| | 70 | ActiveRecord::Base.connection.remove_timestamps :delete_me |
|---|
| | 71 | assert_equal ActiveRecord::Base.connection.execute("SHOW FIELDS FROM delete_me where FIELD='updated_at' AND TYPE='datetime'").num_rows, 0 |
|---|
| | 72 | assert_equal ActiveRecord::Base.connection.execute("SHOW FIELDS FROM delete_me where FIELD='created_at' AND TYPE='datetime'").num_rows, 0 |
|---|
| | 73 | ensure |
|---|
| | 74 | ActiveRecord::Base.connection.drop_table :delete_me rescue nil |
|---|
| | 75 | #before finishing, we restore the alias to the mock-up method |
|---|
| | 76 | ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do |
|---|
| | 77 | alias_method :execute, :execute_with_stub |
|---|
| | 78 | end |
|---|
| | 79 | end |
|---|
| | 80 | |
|---|
| | 81 | |
|---|