Rails測試中清空資料表 載入空fixtures

2022-02-16 09:28:04 字數 607 閱讀 6933

使用spec框架測試,其他測試框架雷同

建立spec/test/empty,其中放入空的yml夾具檔案

code

fixtures.reset_cache

fixtures.create_fixtures(file.join(rails_root,

"spec/fixtures/empty"),

"students

")

以此載入空的students表

當然在執行大量測試時也會存在問題,就是需要將使用的空夾具刪除,來載入有效夾具進行其他測試

code

fixtures.reset_cachef =

fixtures.create_fixtures(file.join(rails_root,

"spec/fixtures/empty"),

"teachers

")

teacher.latest_index.should

==""

f.delete_existing_fixtures

fixtures.reset_cache

清空資料表(實則更改狀態)

業務需求 後台資料清除成功後,頁面提示操作成功 設計到的類和表名如下 類 表 頁面 頁面 對文章資料進行清空 clearcontentbtn click function function var url content operation clearcontent rest get url,fun...

Sql Server中清空所有資料表中的記錄

sql server中清空所有資料表中的記錄 清空所有資料表中的記錄 如下 exec sp msforeachtable command1 truncate table 刪除所有資料表 如下 exec sp msforeachtable delete n 清空sql server資料庫中所有表資料的...

Sql Server中清空所有資料表中的記錄

我這裡介紹的是刪除資料庫的所有資料,因為資料之間可能形成相互約束關係,刪除操作可能陷入死迴圈,二是這裡使用了微軟未正式公開的sp msforeachtable儲存過程 sql server中清空所有資料表中的記錄 清空所有資料表中的記錄 如下 exec sp msforeachtable comma...