1

我正在开发一个与 Alchemy CMS 并排的 Rails 4.1 应用程序。我不希望管理部分使用 Alchemy 的管理界面。(我正在与 ZURB 基金会建立我自己的。)

当我想在 RSpec 中运行我自己的规范时,麻烦开始酝酿。虽然应用程序在开发模式下运行良好,但我在测试中收到此错误:

Failure/Error: visit new_staff_program_path
     Alchemy::DefaultLanguageNotFoundError:
       No default language found. Have you run the rake alchemy:db:seed task?

控制器似乎正在运行一些期望数据到位的过滤器。有没有办法让我对我的应用程序的某些部分“选择退出”?

目前,这是我的解决方案...

我有一个单独的管理员正在扩展的基本控制器。在其中,我指示它跳过before_actionAlchemy 引擎添加到控制器层的调用:

class Staff::Base < ApplicationController
  # Filters
  skip_before_action :set_current_alchemy_site, :set_alchemy_language

  # Layout
  layout 'admin'
end

如果有人有更好的解决方案,请告诉我。

4

2 回答 2

5

是的,确实很简单;)

在您的每次运行测试套件时,spec_helper您都可以添加一个Rspec.config块来播种 Alchemy 的基本数据:

# spec/spec_helper.rb
require 'alchemy/seeder'

RSpec.configure do |config|
  config.before type: :feature do
    Alchemy::Seeder.seed!
  end
end
于 2014-10-23T12:07:11.470 回答
0

和蛮力的方式:

# 'spec/support/alchemy_stub'    
# Make tests run faster by stubbing Alchemy controller before actions

module Alchemy
  module ControllerActions
    def set_current_alchemy_site
    end
    def set_alchemy_language
    end
  end
end

如果您不自动要求 spec/support 中的所有内容,则在您的 spec_helper 中要求它

# spec/spec_helper.rb
require 'support/alchemy_stub'
于 2014-12-30T11:30:10.497 回答