Skip to content

Instantly share code, notes, and snippets.

View using a login! method
# using machinist and Authlogic to crat
def login!(options = {})
user = User.make(options)
def set_session_for(user)
View gist:130073
def assert_methods(actual, methods = {})
methods.each do |method, value|
assert_equal(value, actual.send(method),
"For method #{method} expected <#{value}>, got <#{actual.send(method)}>")
## usage:
assert_methods(@user, :name => "Fred", :email => "", :comment_count => 12)
View sequence.rb
class Sequence
class << self
def sequences do |y|
sequence =
while sequence
sequence =
break unless sequence
View sequence_spec.rb
require 'rubygems'
require 'rspec'
require 'sequence'
describe Sequence do
describe "validation" do
it "should be able to sum its items" do
sequence =, 2, 3, 4)
View gist:847599
cap staging deploy:cold rvm:ruby-1.9.2-p180@new_futuro
* executing `staging'
triggering start callbacks for `deploy:cold'
* executing `multistage:ensure'
* executing `deploy:cold'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote master"
View gist:847607
set :stages, %w(staging production)
set :default_stage, 'staging'
require 'capistrano/ext/multistage' rescue 'YOU NEED TO INSTALL THE capistrano-ext GEM'
require "bundler/capistrano"
set :application, "new_futuro"
set :repository, ""
default_run_options[:pty] = true
set :scm, "git"
View Enumeration Support
# based on an idea by Gavin Mulligan
# this version differs because
# * it returns StringInquirers rather than symbols,
# because I'll take any excuse to use StringInquirers
# * It uses meta program methods directly rather than class_eval
# * It auto-loads itself into ActiveRecord::Base
# * It supports a default option that uses default_value_for to set a default
View gist:1072630
# from the erb2haml gem by David Leung
# copied to a gist for easier integration into our Rails 2 training
require 'find'
RED_FG ="\033[31m"
GREEN_FG = "\033[32m"
END_TEXT_STYLE = "\033[0m"
# Helper method to inject ASCII escape sequences for colorized output
View accepts_delimited_id_string_for.rb
module AcceptsDelimtedIdStringFor
# accepts_delimited_id_string_for :careers
# becomes
# def career_id_strings=(delimited_string)
# = Career.where(:id => delimited_string.split(",")).all
# end
View gist:1140408
class Restaurant
attr_accessor :ratings, :cuisine, :price
def initialize(cuisine = nil, price = 0)
@ratings = []
@cuisine = cuisine
@price = price