我有一些自定义代码,覆盖了gem的activity_notification
NotificationsWithDeviseController#index
方法,当我尝试在rspec中测试该方法时,出现“没有路由匹配错误”。我正在使用与测试其他控制器相同的测试流程。
这是我的简化控制器:
class Users::NotificationsWithDeviseController < ActivityNotification::NotificationsWithDeviseController
before_action :set_notification, except: [:index, :open_all, :count]
def index
set_index_options
load_index if params[:reload].to_s.to_boolean(true)
# do some business logic
respond_to do |format|
format.html
format.json
end
end
end
简化测试:
require 'rails_helper'
RSpec.describe Users::NotificationsWithDeviseController do
include Devise::Test::ControllerHelpers
describe 'when listing notifications' do
render_views
it 'returns a single notification' do
sign_in user # user is target
notifiable = # create notifiable
notifiable.notify :users, key: 'key'
get :index, format: :json, params: { filter: 'unopened'}
assert_response :success
end
end
end
这是我的相关路线:
scope :users, as: :users do
notify_to :users, with_devise: :users, devise_default_routes: true, routing_scope: :users, controller: 'users/notifications_with_devise'
end
这是我得到的错误: