class ActiveRecord::Migration::ReferencesStatementsTest
Public Instance Methods
setup()
click to toggle source
Calls superclass method
ActiveRecord::Migration::TestHelper#setup
# File activerecord/test/cases/migration/references_statements_test.rb, line 12 def setup super @table_name = :test_models add_column table_name, :supplier_id, :integer add_index table_name, :supplier_id end
test_add_belongs_to_alias()
click to toggle source
# File activerecord/test/cases/migration/references_statements_test.rb, line 118 def test_add_belongs_to_alias add_belongs_to table_name, :user assert column_exists?(table_name, :user_id, :integer) end
test_create_reference_id_index_even_if_index_option_is_not_passed()
click to toggle source
# File activerecord/test/cases/migration/references_statements_test.rb, line 40 def test_create_reference_id_index_even_if_index_option_is_not_passed add_reference table_name, :user assert index_exists?(table_name, :user_id) end
test_creates_named_index()
click to toggle source
# File activerecord/test/cases/migration/references_statements_test.rb, line 70 def test_creates_named_index add_reference table_name, :tag, index: { name: "index_taggings_on_tag_id" } assert index_exists?(table_name, :tag_id, name: "index_taggings_on_tag_id") end
test_creates_named_unique_index()
click to toggle source
# File activerecord/test/cases/migration/references_statements_test.rb, line 75 def test_creates_named_unique_index add_reference table_name, :tag, index: { name: "index_taggings_on_tag_id", unique: true } assert index_exists?(table_name, :tag_id, name: "index_taggings_on_tag_id", unique: true) end
test_creates_polymorphic_index()
click to toggle source
# File activerecord/test/cases/migration/references_statements_test.rb, line 45 def test_creates_polymorphic_index add_reference table_name, :taggable, polymorphic: true, index: true assert index_exists?(table_name, [:taggable_type, :taggable_id]) end
test_creates_reference_id_column()
click to toggle source
# File activerecord/test/cases/migration/references_statements_test.rb, line 20 def test_creates_reference_id_column add_reference table_name, :user assert column_exists?(table_name, :user_id, :integer) end
test_creates_reference_id_with_specified_type()
click to toggle source
# File activerecord/test/cases/migration/references_statements_test.rb, line 80 def test_creates_reference_id_with_specified_type add_reference table_name, :user, type: :string assert column_exists?(table_name, :user_id, :string) end
test_creates_reference_type_column()
click to toggle source
# File activerecord/test/cases/migration/references_statements_test.rb, line 30 def test_creates_reference_type_column add_reference table_name, :taggable, polymorphic: true assert column_exists?(table_name, :taggable_type, :string) end
test_creates_reference_type_column_with_default()
click to toggle source
# File activerecord/test/cases/migration/references_statements_test.rb, line 50 def test_creates_reference_type_column_with_default add_reference table_name, :taggable, polymorphic: { default: "Photo" }, index: true assert column_exists?(table_name, :taggable_type, :string, default: "Photo") end
test_creates_reference_type_column_with_not_null()
click to toggle source
# File activerecord/test/cases/migration/references_statements_test.rb, line 55 def test_creates_reference_type_column_with_not_null connection.create_table table_name, force: true do |t| t.references :taggable, null: false, polymorphic: true end assert column_exists?(table_name, :taggable_id, :integer, null: false) assert column_exists?(table_name, :taggable_type, :string, null: false) end
test_deletes_polymorphic_index()
click to toggle source
# File activerecord/test/cases/migration/references_statements_test.rb, line 111 def test_deletes_polymorphic_index with_polymorphic_column do remove_reference table_name, :supplier, polymorphic: true assert_not index_exists?(table_name, [:supplier_id, :supplier_type]) end end
test_deletes_reference_id_column()
click to toggle source
# File activerecord/test/cases/migration/references_statements_test.rb, line 85 def test_deletes_reference_id_column remove_reference table_name, :supplier assert_not column_exists?(table_name, :supplier_id, :integer) end
test_deletes_reference_id_index()
click to toggle source
# File activerecord/test/cases/migration/references_statements_test.rb, line 90 def test_deletes_reference_id_index remove_reference table_name, :supplier assert_not index_exists?(table_name, :supplier_id) end
test_deletes_reference_type_column()
click to toggle source
# File activerecord/test/cases/migration/references_statements_test.rb, line 104 def test_deletes_reference_type_column with_polymorphic_column do remove_reference table_name, :supplier, polymorphic: true assert_not column_exists?(table_name, :supplier_type, :string) end end
test_does_not_create_reference_id_index_if_index_is_false()
click to toggle source
# File activerecord/test/cases/migration/references_statements_test.rb, line 35 def test_does_not_create_reference_id_index_if_index_is_false add_reference table_name, :user, index: false assert_not index_exists?(table_name, :user_id) end
test_does_not_create_reference_type_column()
click to toggle source
# File activerecord/test/cases/migration/references_statements_test.rb, line 25 def test_does_not_create_reference_type_column add_reference table_name, :taggable assert_not column_exists?(table_name, :taggable_type, :string) end
test_does_not_delete_reference_type_column()
click to toggle source
# File activerecord/test/cases/migration/references_statements_test.rb, line 95 def test_does_not_delete_reference_type_column with_polymorphic_column do remove_reference table_name, :supplier assert_not column_exists?(table_name, :supplier_id, :integer) assert column_exists?(table_name, :supplier_type, :string) end end
test_remove_belongs_to_alias()
click to toggle source
# File activerecord/test/cases/migration/references_statements_test.rb, line 123 def test_remove_belongs_to_alias remove_belongs_to table_name, :supplier assert_not column_exists?(table_name, :supplier_id, :integer) end
Private Instance Methods
with_polymorphic_column() { || ... }
click to toggle source
# File activerecord/test/cases/migration/references_statements_test.rb, line 130 def with_polymorphic_column add_column table_name, :supplier_type, :string add_index table_name, [:supplier_id, :supplier_type] yield end