aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorFrederick Cheung <frederick.cheung@gmail.com>2008-05-21 21:03:38 +0100
committerMichael Koziarski <michael@koziarski.com>2008-05-22 11:02:27 +1200
commitdd9938a44ee3a7bb6c42527a1be6fcec70bf4772 (patch)
treeedc43d66fe1088e435f90efd50f5f7166194645b /activerecord/test
parent262d23d763c05bbe5f433a99cb9f02e48a8cdd4a (diff)
downloadrails-dd9938a44ee3a7bb6c42527a1be6fcec70bf4772.tar.gz
rails-dd9938a44ee3a7bb6c42527a1be6fcec70bf4772.tar.bz2
rails-dd9938a44ee3a7bb6c42527a1be6fcec70bf4772.zip
Fix mysql 4.1 incompatibility in the active record schema tests.
Signed-off-by: Michael Koziarski <michael@koziarski.com> [#233 state:resolved ]
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/active_schema_test_mysql.rb73
1 files changed, 41 insertions, 32 deletions
diff --git a/activerecord/test/cases/active_schema_test_mysql.rb b/activerecord/test/cases/active_schema_test_mysql.rb
index ddf3e82162..2a42dc3517 100644
--- a/activerecord/test/cases/active_schema_test_mysql.rb
+++ b/activerecord/test/cases/active_schema_test_mysql.rb
@@ -40,47 +40,56 @@ class ActiveSchemaTest < ActiveRecord::TestCase
end
def test_add_timestamps
- #we need to actually modify some data, so we make execute to point to the original method
- ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
- alias_method :execute_with_stub, :execute
- alias_method :execute, :execute_without_stub
- end
- ActiveRecord::Base.connection.create_table :delete_me do |t|
- end
- ActiveRecord::Base.connection.add_timestamps :delete_me
- assert_equal ActiveRecord::Base.connection.execute("SHOW FIELDS FROM delete_me where FIELD='updated_at' AND TYPE='datetime'").num_rows, 1
- assert_equal ActiveRecord::Base.connection.execute("SHOW FIELDS FROM delete_me where FIELD='created_at' AND TYPE='datetime'").num_rows, 1
- ensure
- ActiveRecord::Base.connection.drop_table :delete_me rescue nil
- #before finishing, we restore the alias to the mock-up method
- ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
- alias_method :execute, :execute_with_stub
+ with_real_execute do
+ begin
+ ActiveRecord::Base.connection.create_table :delete_me do |t|
+ end
+ ActiveRecord::Base.connection.add_timestamps :delete_me
+ assert column_present?('delete_me', 'updated_at', 'datetime')
+ assert column_present?('delete_me', 'created_at', 'datetime')
+ ensure
+ ActiveRecord::Base.connection.drop_table :delete_me rescue nil
+ end
end
end
def test_remove_timestamps
- #we need to actually modify some data, so we make execute to point to the original method
- ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
- alias_method :execute_with_stub, :execute
- alias_method :execute, :execute_without_stub
- end
- ActiveRecord::Base.connection.create_table :delete_me do |t|
- t.timestamps
- end
- ActiveRecord::Base.connection.remove_timestamps :delete_me
- assert_equal ActiveRecord::Base.connection.execute("SHOW FIELDS FROM delete_me where FIELD='updated_at' AND TYPE='datetime'").num_rows, 0
- assert_equal ActiveRecord::Base.connection.execute("SHOW FIELDS FROM delete_me where FIELD='created_at' AND TYPE='datetime'").num_rows, 0
- ensure
- ActiveRecord::Base.connection.drop_table :delete_me rescue nil
- #before finishing, we restore the alias to the mock-up method
- ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
- alias_method :execute, :execute_with_stub
+ with_real_execute do
+ begin
+ ActiveRecord::Base.connection.create_table :delete_me do |t|
+ t.timestamps
+ end
+ ActiveRecord::Base.connection.remove_timestamps :delete_me
+ assert !column_present?('delete_me', 'updated_at', 'datetime')
+ assert !column_present?('delete_me', 'created_at', 'datetime')
+ ensure
+ ActiveRecord::Base.connection.drop_table :delete_me rescue nil
+ end
end
end
-
private
+ def with_real_execute
+ #we need to actually modify some data, so we make execute point to the original method
+ ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
+ alias_method :execute_with_stub, :execute
+ alias_method :execute, :execute_without_stub
+ end
+ yield
+ ensure
+ #before finishing, we restore the alias to the mock-up method
+ ActiveRecord::ConnectionAdapters::MysqlAdapter.class_eval do
+ alias_method :execute, :execute_with_stub
+ end
+ end
+
+
def method_missing(method_symbol, *arguments)
ActiveRecord::Base.connection.send(method_symbol, *arguments)
end
+
+ def column_present?(table_name, column_name, type)
+ results = ActiveRecord::Base.connection.select_all("SHOW FIELDS FROM #{table_name} LIKE '#{column_name}'")
+ results.first && results.first['Type'] == type
+ end
end