Skip to content

Commit 91103fa

Browse files
authored
Merge pull request #989 from yellowspot/coerce-test-using-blob
[Rails 7] Coerce test using blob
2 parents d527384 + 5e0ff4a commit 91103fa

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/cases/coerced_tests.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,36 @@ class MigrationTest < ActiveRecord::TestCase
603603
# For some reason our tests set Rails.@_env which breaks test env switching.
604604
coerce_tests! :test_internal_metadata_stores_environment_when_other_data_exists
605605
coerce_tests! :test_internal_metadata_stores_environment
606+
607+
# Same as original but using binary type instead of blob
608+
coerce_tests! :test_add_column_with_casted_type_if_not_exists_set_to_true
609+
def test_add_column_with_casted_type_if_not_exists_set_to_true_coerced
610+
migration_a = Class.new(ActiveRecord::Migration::Current) {
611+
def version; 100 end
612+
def migrate(x)
613+
add_column "people", "last_name", :binary
614+
end
615+
}.new
616+
617+
migration_b = Class.new(ActiveRecord::Migration::Current) {
618+
def version; 101 end
619+
def migrate(x)
620+
add_column "people", "last_name", :binary, if_not_exists: true
621+
end
622+
}.new
623+
624+
ActiveRecord::Migrator.new(:up, [migration_a], @schema_migration, 100).migrate
625+
assert_column Person, :last_name, "migration_a should have created the last_name column on people"
626+
627+
assert_nothing_raised do
628+
ActiveRecord::Migrator.new(:up, [migration_b], @schema_migration, 101).migrate
629+
end
630+
ensure
631+
Person.reset_column_information
632+
if Person.column_names.include?("last_name")
633+
Person.connection.remove_column("people", "last_name")
634+
end
635+
end
606636
end
607637

608638
class CoreTest < ActiveRecord::TestCase

0 commit comments

Comments
 (0)