Это тест по умолчанию, созданный с помощью созданного мной скаффолда.
describe "PUT update", focus: true do
describe "with valid params" do
it "updates the requested purchase_order" do
current_valid_attr = valid_attributes
purchase_order = PurchaseOrder.create! current_valid_attr
# Assuming there are no other purchase_orders in the database, this
# specifies that the PurchaseOrder created on the previous line
# receives the :update_attributes message with whatever params are
# submitted in the request.
# PurchaseOrder.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
# put :update, :id => purchase_order.id, :purchase_order => {'these' => 'params'}
PurchaseOrder.any_instance.should_receive(:update_attributes).with(current_valid_attr)
put :update, :id => purchase_order.id, :purchase_order => current_valid_attr
end
Проблема в том, что я не понимаю , что он должен делать , и я не могу заставить его передать с правильными атрибутами. Вот ошибка, когда я запустил тест
Failures:
1) PurchaseOrdersController PUT update with valid params updates the requested purchase_order
Failure/Error: put :update, :id => purchase_order.id, :purchase_order => current_valid_attr
#<PurchaseOrder:0x007fe3027521e0> received :update_attributes with unexpected arguments
expected: ({"id"=>nil, "supplier_id"=>1, "no"=>1305, "no_rujukan"=>"Guiseppe Abshire", "jenis"=>"P", "mula_on"=>Sat, 23 Aug 2003 14:11:42 MYT +08:00, "created_at"=>nil, "updated_at"=>nil})
got: ({"id"=>nil, "supplier_id"=>"1", "no"=>"1305", "no_rujukan"=>"Guiseppe Abshire", "jenis"=>"P", "mula_on"=>"2003-08-23 14:11:42 +0800", "created_at"=>nil, "updated_at"=>nil})
Заранее спасибо.
valid_attributes
def valid_attributes
Factory.build(:purchase_order).attributes
end
Фабрика
FactoryGirl.define do
factory :purchase_order do
association :supplier
sequence(:no) { |n| Random.rand(1000...9999) }
sequence(:no_rujukan) { |n| Faker::Name.name }
sequence(:jenis) { |n| PurchaseOrder::PEROLEHAN[Random.rand(0..3).to_i] }
sequence(:mula_on) { |n| Random.rand(10.year).ago }
end
end