2011-12-24 5 views
2

これは私が作成した足場で生成されたデフォルトテストです。このデフォルトのrspecコントローラテストを明確にし、合格させる

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 

工場要求がPurchaseOrderモデルの一つのためのPurchaseOrdersController#updateアクションupdate_attributes方法に来るときに呼び出され、リクエストパラメータが適切に渡されること

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 
+0

'valid_attributes'の定義を表示できますか? –

+0

@ KL-7:質問を更新しました – amree

答えて

関連する問題