Sha256: 6b9aeb129b8818dbfd4271477faa4b6189b857aa251b3488adfb8b5c25d582a1

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

require "rails"
require "action_controller"
require "timber"
require "stringio"

# Helper methods
module Support
  module Rails
    def self.dispatch_rails_request(path)
      application = ::Rails.application
      env = application.respond_to?(:env_config) ? application.env_config.clone : application.env_defaults.clone
      env["rack.request.cookie_hash"] = {}.with_indifferent_access
      ::Rack::MockRequest.new(application).get(path, env)
    end

    def self.set_logger(log_dev)
      ::Rails.logger = Timber::Frameworks::Rails.logger(log_dev)
      ::Rails.logger.level = ::Logger::DEBUG # log everything
    end

    def self.set_timber_logger(log_dev)
      ::Rails.logger = Timber::Logger.new(Timber::LogDevices::IO.new(log_dev))
      ::Rails.logger.level = ::Logger::DEBUG # log everything
    end
  end
end

# Disable by default
Timber::Config.enabled = false

# Setup default rails logger with StringIO.
# This ensures that the log data isn't output, but the level is sufficient
# to be logged.
Support::Rails.set_logger(StringIO.new)

# Base rails app
class RailsApp < Rails::Application
  if ::Rails.version =~ /^3\./
    config.secret_token = '1e05af2b349457936a41427e63450937'
  else
    config.secret_key_base = '1e05af2b349457936a41427e63450937'
  end
  config.active_support.deprecation = :stderr
  config.eager_load = false
end

# Start the app to get initialization out of the way
RailsApp.initialize!

# Setup a controller
class PagesController < ActionController::Base
  layout nil

  def index
    render json: {}
  end

  def method_for_action(action_name)
    action_name
  end
end

# Some routes
::RailsApp.routes.draw do
  get '/' => 'pages#index'
end

# Dispatch a request to get the initial caching / loading out of the way
Support::Rails.dispatch_rails_request("/")

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
timberio-1.0.0.beta1 benchmark/support/rails.rb