Skip to content

Instantly share code, notes, and snippets.

@bf4
Forked from thegrubbsian/rails_engine_test.rb
Created January 31, 2014 22:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bf4/8744473 to your computer and use it in GitHub Desktop.
Save bf4/8744473 to your computer and use it in GitHub Desktop.
include ActiveSupport
["app/**/", "lib/**/"].each do |glob|
Dir.glob(glob).each do |dir|
Dependencies.autoload_paths << File.join(File.dirname(__FILE__), dir)
end
end
@bf4
Copy link
Author

bf4 commented Jan 31, 2014

@bf4
Copy link
Author

bf4 commented Feb 3, 2014

Or some gobbley gook pastiche of the above

require 'pathname'
require 'rails/railtie'
require 'active_record/railtie'
require 'active_support/railtie'
require 'active_support/all'
# see https://github.com/rails/rails/tree/master/activesupport/lib/active_support/
# require 'active_support/core_ext'
# require 'active_support/inflections'
# require 'active_support/inflector'
require 'active_support/dependencies'
require "bundler/setup"
# Bundler.require

begin
  module RailsApp
    class Application < Rails::Application
      config.secret_token = routes.append {
        root to: proc {
          [200, {"Content-Type" => "text/html"}, []]
        }
      }.to_s
      config.root = Pathname(File.expand_path('../..', __FILE__))
      config.active_support.deprecation = :log
      config.eager_load = false

    end
  end
  include ActiveSupport
  ["app/**/", "lib/**/"].each do |glob|
    Dir.glob(glob).each do |dir|
      Dependencies.autoload_paths << File.join(File.dirname(__FILE__), dir)
    end
  end
end unless defined?(RailsApp::Application)
db_config  = File.read(Rails.root.join('config/database.yml'))
db_config = ERB.new(db_config).result(binding)
db_settings = YAML::load(db_config)['test']
ActiveRecord::Base.establish_connection(db_settings)
def ensure_model_loaded(model_name, &block)
  @tries = 1
  begin
    block.call
  rescue NameError => e
    @tries -= 1
    if model_path = Rails.configuration.autoload_paths.detect do |path|
        filename = path.basename.ext('')
        model_name == filename
      end
      require model_path
      retry if @tries.zero?
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment