![](/img/trans.png)
[英]Integration test with Cucumber + Guard + Spork: Can I access my REST entry point?
[英]Rails integration test: my test posts a new entry to the controller, how do I retrieve this entry?
我在知道如何檢索我的測試剛剛發布的新條目時遇到問題。 這是我的代碼:
post admin_bundles_path, params: { bundle: {
title: "New bundle",
sku: "ASD-FESTA-00001-XM",
} }, xhr: true
assert_response :ok
到現在為止還挺好。 現在,我如何檢查這個新條目的屬性? 較舊的條目在我的裝置上,因此我可以通過bundles(:some_bundle)
訪問它們,例如。 我如何為新的做到這一點?
你可以試試這個:
Bundle.last
這將獲得您剛剛發布的最后一個條目。 被警告! 如果由於某種原因您的 post 請求失敗,那么您實際上將在您的裝置中檢索較舊的條目。
如果您想絕對確定,那么您可以執行以下操作:
Bundle.where(title: "New bundle", sku: "ASD-FESTA-00001-XM").first
如果由於某種原因發布請求失敗,這將產生錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.