gpt4 book ai didi

ruby-on-rails - 无方法错误 :undefined method `symbolize_keys' in rspec test

转载 作者:行者123 更新时间:2023-12-04 23:07:29 25 4
gpt4 key购买 nike

这是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

客户 Controller 中的更新:
  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方法,你必须通过它的 idHash反而。

(也请注意,此代码假定您的客户存在于测试数据库中,因此您的工厂必须 create 它。)

关于ruby-on-rails - 无方法错误 :undefined method `symbolize_keys' in rspec test,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7839227/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com