ruby-on-rails – NoMethodError:rspec测试中未定义的方法`symb
发布时间:2020-12-17 03:45:39 所属栏目:百科 来源:网络整理
导读:以下是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_controlle
以下是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 changedn' + @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. (请注意,此代码假定您的客户存在于测试数据库中,因此您的工厂必须创建它.) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |