aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/firebird/migration_test.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-06-25 13:29:17 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2010-06-25 14:47:14 -0700
commit5e2b473b478d93d6a1aa627d688b2b2ce05fa9ef (patch)
treec0778a2075f34feeec6f52426055e88280529e26 /activerecord/test/cases/adapters/firebird/migration_test.rb
parentefbd0eb9f7508187259208caf6b51eec206cbac9 (diff)
downloadrails-5e2b473b478d93d6a1aa627d688b2b2ce05fa9ef.tar.gz
rails-5e2b473b478d93d6a1aa627d688b2b2ce05fa9ef.tar.bz2
rails-5e2b473b478d93d6a1aa627d688b2b2ce05fa9ef.zip
reorganizing adapter specific tests. [#4974 state:resolved]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activerecord/test/cases/adapters/firebird/migration_test.rb')
-rw-r--r--activerecord/test/cases/adapters/firebird/migration_test.rb124
1 files changed, 124 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/firebird/migration_test.rb b/activerecord/test/cases/adapters/firebird/migration_test.rb
new file mode 100644
index 0000000000..710661b9bd
--- /dev/null
+++ b/activerecord/test/cases/adapters/firebird/migration_test.rb
@@ -0,0 +1,124 @@
+require "cases/helper"
+require 'models/course'
+
+class FirebirdMigrationTest < ActiveRecord::TestCase
+ self.use_transactional_fixtures = false
+
+ def setup
+ # using Course connection for tests -- need a db that doesn't already have a BOOLEAN domain
+ @connection = Course.connection
+ @fireruby_connection = @connection.instance_variable_get(:@connection)
+ end
+
+ def teardown
+ @connection.drop_table :foo rescue nil
+ @connection.execute("DROP DOMAIN D_BOOLEAN") rescue nil
+ end
+
+ def test_create_table_with_custom_sequence_name
+ assert_nothing_raised do
+ @connection.create_table(:foo, :sequence => 'foo_custom_seq') do |f|
+ f.column :bar, :string
+ end
+ end
+ assert !sequence_exists?('foo_seq')
+ assert sequence_exists?('foo_custom_seq')
+
+ assert_nothing_raised { @connection.drop_table(:foo, :sequence => 'foo_custom_seq') }
+ assert !sequence_exists?('foo_custom_seq')
+ ensure
+ FireRuby::Generator.new('foo_custom_seq', @fireruby_connection).drop rescue nil
+ end
+
+ def test_create_table_without_sequence
+ assert_nothing_raised do
+ @connection.create_table(:foo, :sequence => false) do |f|
+ f.column :bar, :string
+ end
+ end
+ assert !sequence_exists?('foo_seq')
+ assert_nothing_raised { @connection.drop_table :foo }
+
+ assert_nothing_raised do
+ @connection.create_table(:foo, :id => false) do |f|
+ f.column :bar, :string
+ end
+ end
+ assert !sequence_exists?('foo_seq')
+ assert_nothing_raised { @connection.drop_table :foo }
+ end
+
+ def test_create_table_with_boolean_column
+ assert !boolean_domain_exists?
+ assert_nothing_raised do
+ @connection.create_table :foo do |f|
+ f.column :bar, :string
+ f.column :baz, :boolean
+ end
+ end
+ assert boolean_domain_exists?
+ end
+
+ def test_add_boolean_column
+ assert !boolean_domain_exists?
+ @connection.create_table :foo do |f|
+ f.column :bar, :string
+ end
+
+ assert_nothing_raised { @connection.add_column :foo, :baz, :boolean }
+ assert boolean_domain_exists?
+ assert_equal :boolean, @connection.columns(:foo).find { |c| c.name == "baz" }.type
+ end
+
+ def test_change_column_to_boolean
+ assert !boolean_domain_exists?
+ # Manually create table with a SMALLINT column, which can be changed to a BOOLEAN
+ @connection.execute "CREATE TABLE foo (bar SMALLINT)"
+ assert_equal :integer, @connection.columns(:foo).find { |c| c.name == "bar" }.type
+
+ assert_nothing_raised { @connection.change_column :foo, :bar, :boolean }
+ assert boolean_domain_exists?
+ assert_equal :boolean, @connection.columns(:foo).find { |c| c.name == "bar" }.type
+ end
+
+ def test_rename_table_with_data_and_index
+ @connection.create_table :foo do |f|
+ f.column :baz, :string, :limit => 50
+ end
+ 100.times { |i| @connection.execute "INSERT INTO foo VALUES (GEN_ID(foo_seq, 1), 'record #{i+1}')" }
+ @connection.add_index :foo, :baz
+
+ assert_nothing_raised { @connection.rename_table :foo, :bar }
+ assert !@connection.tables.include?("foo")
+ assert @connection.tables.include?("bar")
+ assert_equal "index_bar_on_baz", @connection.indexes("bar").first.name
+ assert_equal 100, FireRuby::Generator.new("bar_seq", @fireruby_connection).last
+ assert_equal 100, @connection.select_one("SELECT COUNT(*) FROM bar")["count"]
+ ensure
+ @connection.drop_table :bar rescue nil
+ end
+
+ def test_renaming_table_with_fk_constraint_raises_error
+ @connection.create_table :parent do |p|
+ p.column :name, :string
+ end
+ @connection.create_table :child do |c|
+ c.column :parent_id, :integer
+ end
+ @connection.execute "ALTER TABLE child ADD CONSTRAINT fk_child_parent FOREIGN KEY(parent_id) REFERENCES parent(id)"
+ assert_raise(ActiveRecord::ActiveRecordError) { @connection.rename_table :child, :descendant }
+ ensure
+ @connection.drop_table :child rescue nil
+ @connection.drop_table :descendant rescue nil
+ @connection.drop_table :parent rescue nil
+ end
+
+ private
+ def boolean_domain_exists?
+ !@connection.select_one("SELECT 1 FROM rdb$fields WHERE rdb$field_name = 'D_BOOLEAN'").nil?
+ end
+
+ def sequence_exists?(sequence_name)
+ FireRuby::Generator.exists?(sequence_name, @fireruby_connection)
+ end
+end