Search code examples
ruby-on-railsrspecdeviserspec-rails

Testing Devise updating user registration info with Rspec and getting: ActionController::UnknownFormat: Error


I am simply attempting to use the code below to test updating a user's email through a Devise path in an Rspec Request spec and I wish to know why it is giving me the error: ActionController::UnknownFormat:

require 'rails_helper'

RSpec.describe "UsersEdits", type: :request do
  let(:user) { FactoryGirl.create(:user) }

  it "my test" do
    email = "new@email.com"

    params = { "user[email]" => email, "user[current_password]" => 'foobar' }
    put user_registration_path(user), params

    user.reload
    expect(user.email).to eq(email)
  end
end

here is the error:

Failure/Error: patch user_registration_path(user), params

 ActionController::UnknownFormat:
   ActionController::UnknownFormat

Any help would be greatly appreciated, thanks!


Solution

  • Just finished tracking this down myself.

    user_registration_path(user) will generate "/users.980190962" which causes that ActionController::UnknownFormat error. In some controller setups, you might patch "/users/980790962", but devise just patches "/users" directly. I'm guessing devise/warden patches whomever the signed-in user is and doesn't need the user id. So instead:

        patch user_registration_path, params: { user: {
          ....
          } }
    

    or for rspec:

        put user_registration_path, params