0
@@ -1077,7 +1077,7 @@ if ActiveRecord::Base.connection.supports_migrations?
0
- Person.connection.create_table :delete_me
do |t|
0
+ Person.connection.create_table :delete_me
, :force => true do |t|
0
@@ -1086,4 +1086,210 @@ if ActiveRecord::Base.connection.supports_migrations?
0
end # SexyMigrationsTest
0
+ uses_mocha 'ChangeTable migration tests' do
0
+ class ChangeTableMigrationsTest < ActiveRecord::TestCase
0
+ @connection = Person.connection
0
+ @connection.create_table :delete_me, :force => true do |t|
0
+ Person.connection.drop_table :delete_me rescue nil
0
+ def test_references_column_type_adds_id
0
+ with_change_table do |t|
0
+ @connection.expects(:add_column).with(:delete_me, 'customer_id', :integer, {})
0
+ t.references :customer
0
+ def test_remove_references_column_type_removes_id
0
+ with_change_table do |t|
0
+ @connection.expects(:remove_column).with(:delete_me, 'customer_id')
0
+ t.remove_references :customer
0
+ def test_add_belongs_to_works_like_add_references
0
+ with_change_table do |t|
0
+ @connection.expects(:add_column).with(:delete_me, 'customer_id', :integer, {})
0
+ t.belongs_to :customer
0
+ def test_remove_belongs_to_works_like_remove_references
0
+ with_change_table do |t|
0
+ @connection.expects(:remove_column).with(:delete_me, 'customer_id')
0
+ t.remove_belongs_to :customer
0
+ def test_references_column_type_with_polymorphic_adds_type
0
+ with_change_table do |t|
0
+ @connection.expects(:add_column).with(:delete_me, 'taggable_type', :string, {})
0
+ @connection.expects(:add_column).with(:delete_me, 'taggable_id', :integer, {})
0
+ t.references :taggable, :polymorphic => true
0
+ def test_remove_references_column_type_with_polymorphic_removes_type
0
+ with_change_table do |t|
0
+ @connection.expects(:remove_column).with(:delete_me, 'taggable_type')
0
+ @connection.expects(:remove_column).with(:delete_me, 'taggable_id')
0
+ t.remove_references :taggable, :polymorphic => true
0
+ def test_references_column_type_with_polymorphic_and_options_null_is_false_adds_table_flag
0
+ with_change_table do |t|
0
+ @connection.expects(:add_column).with(:delete_me, 'taggable_type', :string, {:null => false})
0
+ @connection.expects(:add_column).with(:delete_me, 'taggable_id', :integer, {:null => false})
0
+ t.references :taggable, :polymorphic => true, :null => false
0
+ def test_remove_references_column_type_with_polymorphic_and_options_null_is_false_removes_table_flag
0
+ with_change_table do |t|
0
+ @connection.expects(:remove_column).with(:delete_me, 'taggable_type')
0
+ @connection.expects(:remove_column).with(:delete_me, 'taggable_id')
0
+ t.remove_references :taggable, :polymorphic => true, :null => false
0
+ def test_timestamps_creates_updated_at_and_created_at
0
+ with_change_table do |t|
0
+ @connection.expects(:add_timestamps).with(:delete_me)
0
+ def test_remove_timestamps_creates_updated_at_and_created_at
0
+ with_change_table do |t|
0
+ @connection.expects(:remove_timestamps).with(:delete_me)
0
+ if current_adapter?(:PostgreSQLAdapter)
0
+ "character varying(255)"
0
+ if current_adapter?(:SQLite3Adapter) || current_adapter?(:SQLiteAdapter) || current_adapter?(:PostgreSQLAdapter)
0
+ def test_integer_creates_integer_column
0
+ with_change_table do |t|
0
+ @connection.expects(:add_column).with(:delete_me, :foo, integer_column, {})
0
+ @connection.expects(:add_column).with(:delete_me, :bar, integer_column, {})
0
+ def test_string_creates_string_column
0
+ with_change_table do |t|
0
+ @connection.expects(:add_column).with(:delete_me, :foo, string_column, {})
0
+ @connection.expects(:add_column).with(:delete_me, :bar, string_column, {})
0
+ def test_column_creates_column
0
+ with_change_table do |t|
0
+ @connection.expects(:add_column).with(:delete_me, :bar, :integer, {})
0
+ t.column :bar, :integer
0
+ def test_column_creates_column_with_options
0
+ with_change_table do |t|
0
+ @connection.expects(:add_column).with(:delete_me, :bar, :integer, {:null => false})
0
+ t.column :bar, :integer, :null => false
0
+ def test_index_creates_index
0
+ with_change_table do |t|
0
+ @connection.expects(:add_index).with(:delete_me, :bar, {})
0
+ def test_index_creates_index_with_options
0
+ with_change_table do |t|
0
+ @connection.expects(:add_index).with(:delete_me, :bar, {:unique => true})
0
+ t.index :bar, :unique => true
0
+ def test_change_changes_column
0
+ with_change_table do |t|
0
+ @connection.expects(:change_column).with(:delete_me, :bar, :string, {})
0
+ t.change :bar, :string
0
+ def test_change_changes_column_with_options
0
+ with_change_table do |t|
0
+ @connection.expects(:change_column).with(:delete_me, :bar, :string, {:null => true})
0
+ t.change :bar, :string, :null => true
0
+ def test_change_default_changes_column
0
+ with_change_table do |t|
0
+ @connection.expects(:change_column_default).with(:delete_me, :bar, :string)
0
+ t.change_default :bar, :string
0
+ def test_remove_drops_single_column
0
+ with_change_table do |t|
0
+ @connection.expects(:remove_column).with(:delete_me, [:bar])
0
+ def test_remove_drops_multiple_columns
0
+ with_change_table do |t|
0
+ @connection.expects(:remove_column).with(:delete_me, [:bar, :baz])
0
+ def test_remove_index_removes_index_with_options
0
+ with_change_table do |t|
0
+ @connection.expects(:remove_index).with(:delete_me, {:unique => true})
0
+ t.remove_index :unique => true
0
+ def test_rename_renames_column
0
+ with_change_table do |t|
0
+ @connection.expects(:rename_column).with(:delete_me, :bar, :baz)
0
+ Person.connection.change_table :delete_me do |t|
0
+ end # ChangeTable test
Comments
No one has commented yet.