我在理解我的测试有什么问题时遇到了一些麻烦,但是在测试控制器的更新方法时,我不断收到 No Route Match。不过,通过浏览器提交表单是可行的。
我的路线文件:
namespace :merchant do
resources :users
get '/signup', to: "users#new"
end
我的控制器:
def update
respond_to do |format|
if @merchant_user.update(user_params)
format.html { redirect_to @merchant_user, notice: 'User was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'show' }
format.json { render json: @merchant_user.errors, status: :unprocessable_entity }
end
end
end
我的测试:
test "should update user" do
user = users(:jon)
user.first_name="Jonas"
put :update, :merchant_user =>user.attributes
assert_response :success
结尾
结果:
1) Error:
Merchant::UsersControllerTest#test_should_update_user:
ActionController::UrlGenerationError: No route matches {:merchant_user=> {"id"=>"846114006", "email"=>"jon.sims@whatever.com", "first_name"=>"Jonas", "last_name"=>"Sims", "password_digest"=>"$2a$10$LVbV7pkd7li8sobYEauoS.4JVA2ZHzAXgPFbyiojYqgcDBHUE9bXW", "type"=>"Merchant::User", "created_at"=>"2013-07-11 22:59:41 UTC", "updated_at"=>"2013-07-11 22:59:41 UTC"}, :controller=>"merchant/users", :action=>"update"}
test/controllers/merchant/users_controller_test.rb:45:in `block in <class:UsersControllerTest>'
有什么提示吗?