我是 ruby on rails 的新手,我一直在阅读 Agile web development with rails 书。我正在研究迭代 B1:验证,当我进行测试时,我对符号 :product 感到非常困惑。问题是关于 ":product => @update" 我真的不知道这是什么意思以及 :product 符号来自哪里。我知道它是一个散列,但它散列到哪个表?它到底在这里做什么?代码如下。先感谢您。
require 'test_helper'
class ProductsControllerTest < ActionController::TestCase
setup do
@product = products(:one)
@update = {
:title => 'Lorem Ipsum',
:description => 'Wibbles are fun!',
:image_url => 'lorem.jpg',
:price => 19.95
}
end
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:products)
end
test "should get new" do
get :new
assert_response :success
end
test "should create product" do
assert_difference('Product.count') do
***post :create, :product => @update***
end
assert_redirected_to product_path(assigns(:product))
end
# ...
test "should show product" do
get :show, :id => @product.to_param
assert_response :success
end
test "should get edit" do
get :edit, :id => @product.to_param
assert_response :success
end
test "should update product" do
put :update, :id => @product.to_param, :product => @update
assert_redirected_to product_path(assigns(:product))
end
# ...
test "should destroy product" do
assert_difference('Product.count', -1) do
delete :destroy, :id => @product.to_param
end
assert_redirected_to products_path
end
end