我有一個滑軌控制器,定義如下:如何在rails中測試嵌套屬性?
https://github.com/abonec/Simple-Store/blob/master/app/controllers/carts_controller.rb
在cart頁面,用戶可以通過發佈嵌套屬性指定line_items的數量。參數如下所示:
{ "cart" => {
"line_items_attributes" => {
"0" => {
"quantity" => "2",
"id" => "36" } } },
"commit" => "Update Cart",
"authenticity_token" => "UdtQ+lchSKaHHkN2E1bEX00KcdGIekGjzGKgKfH05So=",
"utf8"=>"\342\234\223" }
在我的控制器操作這些PARAMS保存這樣的:
@cart.update_attributes(params[:cart])
但我不知道如何在測試測試此行爲。 @cart.attributes
只生成模型屬性不嵌套的屬性。
我該如何測試這種行爲?如何在我的功能測試中使用嵌套屬性模擬post請求?
如何訪問到我知道嵌套的屬性,但我不知道如何在功能測試中模擬嵌套屬性的post請求。 – abonec 2011-03-13 09:02:01