Skip to content

Instantly share code, notes, and snippets.

View dchelimsky's full-sized avatar

David Chelimsky dchelimsky

  • Retired
  • Chicago, IL, USA
View GitHub Profile
module Kernel
def collate(*methods)
methods.inject({}) {|h,m| h[m] = send(m); h }
end
end
p [4, 3, 1, 5, 2].collate :max, :min
# => {:min=>1, :max=>5}
require 'spec_helper'
describe Admin::BaseController do
describe 'before_filter' do
it 'should respond to :require_admin' do
controller.should respond_to(:require_admin)
end
end
describe 'not redirecting when user is an admin' do
[carlhuda@Carlhudas-iMac bundler (env_bundle_refactor)]$ spec -c spec/bundler/directory_spec.rb -e 'Faking gems with directories with a simple directory structure stubbing out a gem with a directory -- 1 can bundle --cached'
F
1)
NoMethodError in 'Faking gems with directories with a simple directory structure stubbing out a gem with a directory -- 1 can bundle --cached'
undefined method `filename' for #<Bundler::Environment:0x1017309e0>
/Users/carlhuda/Developer/Source/bundler/lib/bundler/dsl.rb:135:in `_find_directory_source'
/Users/carlhuda/Developer/Source/bundler/lib/bundler/dsl.rb:117:in `_handle_vendored_option'
/Users/carlhuda/Developer/Source/bundler/lib/bundler/dsl.rb:104:in `gem'
/Users/carlhuda/Developer/Source/bundler/tmp/bundled_app/Gemfile:3:in `evaluate'
def email
@emails = []
ContactImport.transaction do
emailed_association_requests.to_send.each do |ear|
ear.create_association_with(user.business)
end
end
end
@dchelimsky
dchelimsky / user.rb
Created October 21, 2009 15:44 — forked from iain/user.rb
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# active :boolean
# created_at :datetime
# updated_at :datetime
#
def summer_monthly_usage
@summer_monthly_usage ||= rates.summer_months_nbr.inject(0) { |sum, m| sum + monthly_usage[m - 1] }
end
# how do I test this elegantly?
class Request < ActiveRecord::Base
named_scope :active, :conditions => {:status => 'active'}
named_scope :incomplete, :conditions => {:completed_at => nil}
named_scope :deliquent, lambda { {:conditions => 10.days.ago} }
def self.do_stuff_with_incomplete_requests
incomplete_requests = Request.active.incomplete.deliquent(:include => {:user})
incomplete_requests.each do |request|
class Game
attr_reader :teams
def initialize
@teams = Array.new
end
def started?
false
Scenario "has three steps" do
Given "one" do
end
When "two" do
end
Then "three" do
end
describe Customer, "last billing address" do
before do
@customer = Customer.generate!
@customer = Address.new
end
it "should be settable and gettable" do
@customer.last_billing_address = @account_address
@customer.last_billing_address.should == @account_address
end
...