This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Written by MattBrown found at https://gist.github.com/659188 | |
class BackgroundSessionProxy < Sunspot::SessionProxy::AbstractSessionProxy | |
class <<self | |
def async? | |
!!Thread.current[:background_session_proxy_async] | |
end | |
def with_async | |
self.async = true | |
begin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module RecognizePath | |
def recognize_path(path, options) | |
recognized_path = Rails.application.routes.recognize_path(path, options) | |
# We have a route that catches everything and sends it to 'errors#not_found', you might | |
# need to rescue ActionController::RoutingError | |
return recognized_path unless recognized_path.slice(:controller, :action) == {controller: 'errors', action: 'not_found'} | |
# The main app didn't recognize the path, try the engines... | |
Rails.application.railties.engines.each do |engine| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def print_table_contents(model_klass, columns=nil) | |
columns ||= model_klass.column_names | |
column_widths = {} | |
columns.each { |col| column_widths[col] = col.to_s.length } | |
objects = model_klass.all | |
objects.each do |obj| | |
columns.each do |col| | |
len = obj[col].to_s.length | |
column_widths[col] = len if len > column_widths[col] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TokenInputHelpers | |
def token_input(locator, options) | |
raise "Must pass a hash containing 'with'" unless options.is_a?(Hash) && options.has_key?(:with) | |
field = _find_fillable_field(locator) # find the field that will ultimately be sent to the server, the one the user intends to fill in | |
# Delete the existing token, if present | |
begin | |
# This xpath is finds a <ul class='token-input-list'/> followed by a <input id="ID"/> | |
within(:xpath, "//ul[@class='token-input-list' and following-sibling::input[@id='#{field[:id]}']]") do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'active_record' | |
require 'sinatra' | |
require 'models/user' | |
require 'logger' | |
env_index = ARGV.index("-e") | |
env_arg = ARGV[env_index+1] if env_index | |
env = env_arg || ENV["SINATRA_ENV"] || "development" | |
databases = YAML.load_file("config/database.yml") |