Skip to content

Instantly share code, notes, and snippets.

@devpuppy
devpuppy / factory.rb
Created December 12, 2010 21:26
trick to load factories from subdirectories of test/factories
# will go three levels deep to find Factory definitions within subdirectories of test/factories
path = Rails.root.join('test/factories')
levels = 3
subdirectories = Dir[File.join(path, '*')].select {|name| File.directory?(name) }
(levels - 1).times do
subdirectories.each do |subdirectory|
subdirectories += Dir[File.join(subdirectory, '*')].select {|name| File.directory?(name) }
end
@devpuppy
devpuppy / .bash_profile
Created March 14, 2010 21:19
.bash_profile
PATH=$PATH:/opt/local/bin
export PATH
alias be='mate -w ~/.bash_profile;source ~/.bash_profile'
# alias ss='script/server'
# alias sc='script/console'
alias rdm='rake db:migrate'
alias glg='gem list |grep'
alias rrg='rake routes |grep'
@devpuppy
devpuppy / .autotest
Created March 12, 2010 21:04 — forked from dust3d/gist:330740
.autotest
# on Ruby 1.9.1...
# gem install test-unit -v 1.2.3
# gem install autotest redgreen autotest-fsevent autotest-rails ZenTest autotest-growl
require 'redgreen'
Autotest.send(:alias_method, :real_ruby, :ruby)
Autotest.send(:define_method, :ruby) do |*args|
real_ruby + %[ -rrubygems -e "require 'redgreen'" ]
end
def disable_rubygems; nil; end
def source(s); $src = s unless s[/gemcutter/] end
def gem(n, v)
if Hash === v
$stderr.puts "ignoring git gem #{n}"
return
end
puts "#{n} --version '#{v}' #{$src ? " -s#{$src}": ""}"
end
load ARGV[0] || "Gemfile"
@devpuppy
devpuppy / helper.rb
Created December 8, 2009 17:20
Per-template javascript include tag
# useful for organizing unobtrusive javascript per template
# assumes layout has yield :javascripts
# need to figure out how to invoke from the template without explicitly having to call it
def javascript_template_include_tag
javascript_path = "views/#{@template.template.path_without_format_and_extension}.js"
if File.exist?(File.join(RAILS_ROOT, 'public', 'javascripts', javascript_path))
content_for :javascripts do
javascript_include_tag javascript_path
end
end
@devpuppy
devpuppy / test_helper.rb
Created December 7, 2009 19:26
[deprecated] hackish way to use Test::Unit with Devise
# very basic test_helper.rb addition to work with devise
def login_as(user)
if user.is_a?(Symbol)
user = Factory(user)
user.save
end
@request.session[:user] = user
end
@devpuppy
devpuppy / gist:67390
Created February 20, 2009 09:20
The basics of the gist.github.com API
@gists = YAML::load Net::HTTP.get(URI.parse(GIST_URL))