1

我正在尝试为当用户访问提供者/计划和提供者/前景时重定向到特定路径的方法编写规范

我在前组中尝试了许多路径组合,我正在尝试这个。

before { get :provider_plans_index_path }
before { get :provider_index_plans_path}
before { get :provider_plans_path}
before { get :provider_index_path}
before { get :provider_plans_path}
before { get :provider_planes_path}

base_controller.rb

class Provider::BaseController < ActionController::Base
  layout 'provider'

  before_action :allowed_pages

  def allowed_pages    
    redirect_to financial_dashboard_path if  !requested_action?(params[:controller])
  end

  def requested_action?(data)
    regexp = %r{
      ^(provider/plans)|      
      (provider/prospects)$
    }x
    data.match?(regexp)
  end
end

base_controller_spec.rb

require 'rails_helper'

describe Provider::BaseController, type: :controller do
  let(:provider) { create(:provider) }
  let(:financial) { create(:financial, provider: provider) }
  let(:user) { provider.user }
  before { login_user user }

  describe 'GET plans' do
    context 'with not allowed url' do      
      before { get :provider_planes_path}
      it { should redirect_to financial_dashboard_path}
    end
  end
end

路线.rb

namespace :provider do
  get '', to: 'dashboard#index'
  get 'dashboard', to: 'dashboard#index'

  resources :plans, only: [:index, :create, :update], path: 'planes'
  resources :prospects,  only: [:index, :show, :create, :update], path: 'prospectos' do
    get 'diagnostico', to: 'prospects#show', on: :member, as: :general
    patch 'diagnostico', to: 'prospects#update', on: :member
    get 'configuracion', to: 'prospects#configuration', on: :member, as: :configuration
  end
end

所有组合都出现此错误

ActionController::UrlGenerationError:没有路由匹配

4

1 回答 1

0

对我来说,解决方案是通过另一个控制器调用规范中的操作

context 'with not allowed url' do
  before do
   @controller = Provider::PlansController.new
   get :index
  end
  it { should redirect_to financial_dashboard_path }
end
于 2019-09-13T20:14:41.397 回答