![](/img/trans.png)
[英]NoMethodError: undefined method `symbolize_keys!' for Hash
[英]NoMethodError:undefined method `symbolize_keys' in rspec test
以下是rspec中更新的錯誤:
4) CustomersController GET customer page 'update' should be successful
Failure/Error: post 'update', customer
NoMethodError:
undefined method `symbolize_keys' for "1":String
# ./spec/controllers/customers_controller_spec.rb:38:in `block (3 levels) in <top (required)>'
rspec代碼:
it "'update' should be successful" do
customer = Factory(:customer)
post 'update', customer
response.should be_success
end
客戶控制器中的更新:
def update
@customer = Customer.find(params[:id])
if @customer.update_attributes(params[:customer], :as => :roles_new_update)
if @customer.changed
@message = 'The following info have been changed\n' + @customer.changes.to_s
@subject ='Customer info was changed BY' + session[:user_name]
notify_all_in_sales_eng(@message,@subject)
end
redirect_to session[('page'+session[:page_step].to_s).to_sym], :notice => 'Customer was updated successfaully!'
else
render 'edit', :notice => 'Customer was not updated!'
end
end
有關錯誤的任何想法? 謝謝。
我不會詳細介紹RSpec,但我遇到了同樣的錯誤,這就是我為你的代碼糾正它的方法:
it "'update' should be successful" do
customer = Factory(:customer)
post 'update', :id => customer.id
response.should be_success
end
我認為你不能直接將你的對象提供給post
方法,你必須在Hash
傳遞它的id
。
(請注意,此代碼假定您的客戶存在於測試數據庫中,因此您的工廠必須create
它。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.