1

テストのどこが悪いのか理解に苦しんでいますが、コントローラーの更新メソッドをテストすると、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>'

ヒントはありますか?

4

2 に答える 2

3

idテストを正しく実行するには、ユーザーのを渡す必要があります。

これを試して:

put :update, id: user.id, merchant_user: {}

ルーターが を予期しているため、このエラーが表示されresource/:idますが、ID が渡されていません。

Users#updateID が必要なメンバー アクションです。ルーターはユーザー ID パラメータを予期しています: /users/:id/update。ID がないと、メソッドは更新するユーザーを見つける方法がありません。

于 2013-07-11T23:19:23.103 に答える