传递参数更新动作rspec rails测试

时间:2015-04-23 12:54:37

标签: ruby-on-rails ruby rspec

以这种方式传递params会返回与更新前相同的信息。

it "PUT Update updates client" do 
    client = FactoryGirl.create(:client)
    put :update, :id => client, :client => { :name => "Rostyk", :email => "new@email.com" }
    expect(client.email).to eq("new@email.com")
    expect(client.name).to eq("Rostyk")
end

1 个答案:

答案 0 :(得分:1)

:id => client应为:id => client.id

也许您需要重新加载对象客户端才能看到更新:

client.reload
expect(client.email).to eq("new@email.com")
expect(client.name).to eq("Rostyk")