如何测试gem的activity_notification控制器?

时间:2020-01-03 13:14:22

标签: ruby-on-rails ruby rspec rubygems

我有一些自定义代码,覆盖了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

这是我得到的错误:

error log

0 个答案:

没有答案
相关问题