我正在开发一个Rails 4.1应用程序,它与炼金术CMS并排。我不希望管理部分使用炼金术的管理界面。(我正在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_action调用:
class Staff::Base < ApplicationController
# Filters
skip_before_action :set_current_alchemy_site, :set_alchemy_language
# Layout
layout 'admin'
end如果有人有更好的解决办法,请告诉我。
发布于 2014-10-23 12:07:11
是的,这确实很简单;)
在您的spec_helper中,您可以在每次运行测试套件时添加一个Rspec.config块,该块将为炼金术的基本数据注入种子:
# spec/spec_helper.rb
require 'alchemy/seeder'
RSpec.configure do |config|
config.before type: :feature do
Alchemy::Seeder.seed!
end
end发布于 2014-12-30 11:30:10
用暴力的方式:
# '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_helper中需要它-需要规范/支持中的所有东西
# spec/spec_helper.rb
require 'support/alchemy_stub'https://stackoverflow.com/questions/26527336
复制相似问题