Skip to content

Instantly share code, notes, and snippets.

@jtrupiano
jtrupiano / gist:290805
Created January 31, 2010 00:34
Latest addition to ~/.irbrc
# Will display dates in human readable format when returned in irb
class Date
def inspect
to_s
end
end
if (root = (defined?(Rails.root) && Rails.root) || RAILS_ROOT)
# load in the 3rd party macros from vendorized plugins and gems
Shoulda.autoload_macros root, File.join("vendor", "{plugins,gems}", "*")
end
@jtrupiano
jtrupiano / gist:279482
Created January 17, 2010 18:19
Gemfile sample
# Update :path for your local machine
gem "factory_girl", :path => '/Users/john/projects/factory_girl'
john-mbp:fg john$ gem bundle
Calculating dependencies...
/Users/john/.rvm/gems/ruby-1.8.7-p248/gems/bundler-0.8.1/lib/bundler/source.rb:231:in `locate_gemspecs': /Users/john/.rvm/rubies/ruby-1.8.7-p248/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- treetop/version (LoadError)
from /Users/john/.rvm/rubies/ruby-1.8.7-p248/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from (eval):1:in `locate_gemspecs'
from /Users/john/.rvm/rubies/ruby-1.8.7-p248/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:95:in `eval'
from /Users/john/.rvm/gems/ruby-1.8.7-p248/gems/bundler-0.8.1/lib/bundler/source.rb:231:in `locate_gemspecs'
from /Users/john/.rvm/rubies/ruby-1.8.7-p248/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:95:in `inject'
from /Users/john/.rvm/gems/ruby-1.8.7-p248/gems/bundler-0.8.1/lib/bundler/source.rb:229:in `each'
from /Users/john/.rvm/gems/ruby-1.8.7-p248/gems/bundler-0.8.1/lib/bundler/source.rb:229:in `inject'
# Edit this Gemfile to bundle your application's dependencies.
gem "rails", "3.0.pre"
## Bundle edge rails:
# gem "rails", :git => "git://github.com/rails/rails.git"
## Bundle the gems you use:
# gem "bj"
# gem "hpricot", "0.6"
From ff49afda3beb5bb20dd43f05e301bee7b3c57a06 Mon Sep 17 00:00:00 2001
From: John Trupiano <[email protected]>
Date: Sat, 16 Jan 2010 15:17:10 -0500
Subject: [PATCH 3/3] Don't allow database access in rails3
* Override Stub#class to return a dup'd class instance that mocks #active_relation
---
lib/factory_girl/proxy/stub.rb | 14 ++++++++++++--
1 files changed, 12 insertions(+), 2 deletions(-)
def initialize(klass)
@instance = klass.new
@instance.id = next_id
@instance.instance_eval do
def new_record?
id.nil?
end
def connection
raise "stubbed models are not allowed to access the database"
@jtrupiano
jtrupiano / gist:278941
Created January 16, 2010 18:34
rvm + ruby 1.8.7 giving me problems
john-mbp:rails john$ gem install timecop
/Users/john/.rvm/ruby-1.8.7-p248/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:232: warning: getc is obsolete; use STDIN.getc instead
^CERROR: Interrupted
john-mbp:rails john$ gem install timecop --no-rdoc --no-ri
Successfully installed timecop-0.3.4
1 gem installed
john-mbp:rails john$ gem install rails --no-rdoc --no-ri
/Users/john/.rvm/ruby-1.8.7-p248/lib/ruby/site_ruby/1.8/rubygems/spec_fetcher.rb:245: [BUG] Segmentation fault
ruby 1.8.7 (2009-12-24 patchlevel 248) [i686-darwin9.8.0]
@jtrupiano
jtrupiano / gist:278066
Created January 15, 2010 13:40
Demonstrate use of ENV['TZ'] to change time zone
john-mbp:playground john$ irb
irb(main):001:0> Time.now
=> Fri Jan 15 08:40:05 -0500 2010
irb(main):002:0> ENV['TZ'] = 'GMT'
=> "GMT"
irb(main):003:0> Time.now
=> Fri Jan 15 13:40:11 +0000 2010
Factory.define :icon do |i|
i.sequence(:name) {|n| "Icon #{n}"}
i.description "Icon description"
i.content "Icon content"
i.image File.new(File.join(RAILS_ROOT, "test", "fixtures", "smaller_cat.jpg"))
end