Skip to content

Instantly share code, notes, and snippets.

View jtanium's full-sized avatar

Jason Edwards jtanium

  • Salt Lake City, Utah
View GitHub Profile
# 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
@jtanium
jtanium / recognize_path.rb
Last active August 25, 2020 09:28
Ruby module that can recognize paths of the main Rails application as well as the engines.
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|
@jtanium
jtanium / gist:4599448
Last active December 11, 2015 12:18
Method to print the contents of a table. While running tests, I regularly find myself wondering what the contents of certain tables are during a test -- here's a function that prints the contents of a table to stdout.
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
@jtanium
jtanium / token_input_helpers.rb
Created September 20, 2011 17:11
TokenInput Cucumber Helper
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
@jtanium
jtanium / Rakefile
Created November 29, 2010 20:55
Service Oriented Design with Ruby and Rails (examples that actually work)
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")