Skip to content

Commit

Permalink
Improved tests [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Nov 7, 2024
1 parent 4047974 commit a1f0ad4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions test/migrations/add_index.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
class AddIndex < TestMigration
def change
add_index :users, :name
end
end

class AddIndexes < TestMigration
def change
add_index :users, :name
add_index :users, :city
Expand Down
10 changes: 5 additions & 5 deletions test/safe_by_default_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def teardown
end

def test_add_index
assert_safe AddIndex
assert_safe AddIndexes
end

def test_add_index_invalid
Expand All @@ -19,7 +19,7 @@ def test_add_index_invalid
with_locked_table("users") do
with_lock_timeout(0.1) do
assert_raises(ActiveRecord::LockWaitTimeout) do
migrate AddIndex
migrate AddIndexes
end
end
end
Expand All @@ -36,15 +36,15 @@ def test_add_index_invalid
end
assert_kind_of PG::DuplicateTable, error.cause

migrate AddIndex
migrate AddIndexes

# fail if trying to add the same index in a future migration
error = assert_raises(ActiveRecord::StatementInvalid) do
migrate AddIndex
migrate AddIndexes
end
assert_kind_of PG::DuplicateTable, error.cause

migrate AddIndex, direction: :down
migrate AddIndexes, direction: :down
end

def test_add_index_extra_arguments
Expand Down

0 comments on commit a1f0ad4

Please sign in to comment.