How to run RSpec for application sitting alongside Alchemy CMS

315 Views Asked by At

I am developing a Rails 4.1 application that sits alongside Alchemy CMS. I do not want the admin portion to use Alchemy's admin interface. (I am building my own with ZURB Foundation.)

Trouble starts brewing when I want to run my own specs in RSpec. While the application runs fine in development mode, I get this error in my tests:

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

It appears that the controller is running some filters that expect data to be in place. Is there a way that I can "opt out" of this for certain parts of my application?

For now, this is my solution...

I have a base controller that the separate admin is extending. Within that, I instruct it to skip before_action calls that the Alchemy engine adds to the controller layer:

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

  # Layout
  layout 'admin'
end

If anyone has any better solutions, let me know.

2

There are 2 best solutions below

5
tvdeyen On BEST ANSWER

Yes, it is indeed very simple ;)

In your spec_helper you can add a Rspec.config block that will seed the base data of Alchemy everytime you run your test suite:

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

RSpec.configure do |config|
  config.before type: :feature do
    Alchemy::Seeder.seed!
  end
end
1
Martin Tomov On

And the brute-force way:

# '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

Require it in your spec_helper if you don't auto-require everything in spec/support

# spec/spec_helper.rb
require 'support/alchemy_stub'