ユーザーがパスワードを変更できるようにするカスタムアクションをDeviseの登録コントローラーに追加しようとしています(registrations#edit
メール/ユーザー名ではなくパスワードのみを変更するためのフォームが必要なため、デフォルトを使用できません)。以下に記述した実装は開発モードで動作しますが、コントローラーをテストするとこのエラーが発生します。
Failure/Error: get 'password'
ActionController::RoutingError:
No route matches {:controller=>"registrations", :action=>"password"}
私のコードがあります(無関係な部分をスキップしようとしました)
spec/controllers/registrations_controller_spec.rb
describe RegistrationsController do
include Devise::TestHelpers
before :each do
request.env["devise.mapping"] = Devise.mappings[:users]
end
describe "GET 'password'" do
it "..." do
# The problem is here,
get 'password' # it raises ActionController::RoutingError
end
end
end
app/controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
# ...
def password
end
end
config/routes.rb
devise_for :users, path: 'account',
controllers: { registrations: 'registartions' },
skip: [:registartions, :sessions]
devise_scope :user do
# ...
scope '/account' do
get 'password' => 'devise/registartions#password', as: "change_password
do
end
spec_helper.rb
# ...
RSpec.configure do |config|
# ...
config.include Devise::TestHelpers, :type => :controller
end