0
@@ -40,47 +40,56 @@ class ActiveSchemaTest < ActiveRecord::TestCase
0
def test_add_timestamps
0
- #we need to actually modify some data, so we make execute to point to the original method
0
- ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
0
- alias_method :execute_with_stub, :execute
0
- alias_method :execute, :execute_without_stub
0
- ActiveRecord::Base.connection.create_table :delete_me do |t|
0
- ActiveRecord::Base.connection.add_timestamps :delete_me
0
- assert_equal ActiveRecord::Base.connection.execute("SHOW FIELDS FROM delete_me where FIELD='updated_at' AND TYPE='datetime'").num_rows, 1
0
- assert_equal ActiveRecord::Base.connection.execute("SHOW FIELDS FROM delete_me where FIELD='created_at' AND TYPE='datetime'").num_rows, 1
0
- ActiveRecord::Base.connection.drop_table :delete_me rescue nil
0
- #before finishing, we restore the alias to the mock-up method
0
- ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
0
- alias_method :execute, :execute_with_stub
0
+ ActiveRecord::Base.connection.create_table :delete_me do |t|
0
+ ActiveRecord::Base.connection.add_timestamps :delete_me
0
+ assert column_present?('delete_me', 'updated_at', 'datetime')
0
+ assert column_present?('delete_me', 'created_at', 'datetime')
0
+ ActiveRecord::Base.connection.drop_table :delete_me rescue nil
0
def test_remove_timestamps
0
- #we need to actually modify some data, so we make execute to point to the original method
0
- ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
0
- alias_method :execute_with_stub, :execute
0
- alias_method :execute, :execute_without_stub
0
- ActiveRecord::Base.connection.create_table :delete_me do |t|
0
- ActiveRecord::Base.connection.remove_timestamps :delete_me
0
- assert_equal ActiveRecord::Base.connection.execute("SHOW FIELDS FROM delete_me where FIELD='updated_at' AND TYPE='datetime'").num_rows, 0
0
- assert_equal ActiveRecord::Base.connection.execute("SHOW FIELDS FROM delete_me where FIELD='created_at' AND TYPE='datetime'").num_rows, 0
0
- ActiveRecord::Base.connection.drop_table :delete_me rescue nil
0
- #before finishing, we restore the alias to the mock-up method
0
- ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
0
- alias_method :execute, :execute_with_stub
0
+ ActiveRecord::Base.connection.create_table :delete_me do |t|
0
+ ActiveRecord::Base.connection.remove_timestamps :delete_me
0
+ assert !column_present?('delete_me', 'updated_at', 'datetime')
0
+ assert !column_present?('delete_me', 'created_at', 'datetime')
0
+ ActiveRecord::Base.connection.drop_table :delete_me rescue nil
0
+ #we need to actually modify some data, so we make execute point to the original method
0
+ ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
0
+ alias_method :execute_with_stub, :execute
0
+ alias_method :execute, :execute_without_stub
0
+ #before finishing, we restore the alias to the mock-up method
0
+ ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
0
+ alias_method :execute, :execute_with_stub
0
def method_missing(method_symbol, *arguments)
0
ActiveRecord::Base.connection.send(method_symbol, *arguments)
0
+ def column_present?(table_name, column_name, type)
0
+ results = ActiveRecord::Base.connection.select_all("SHOW FIELDS FROM #{table_name} LIKE '#{column_name}'")
0
+ results.first && results.first['Type'] == type