This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def summer_monthly_usage | |
@summer_monthly_usage ||= rates.summer_months_nbr.inject(0) { |sum, m| sum + monthly_usage[m - 1] } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# == Schema Information | |
# | |
# Table name: users | |
# | |
# id :integer not null, primary key | |
# active :boolean | |
# created_at :datetime | |
# updated_at :datetime | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def email | |
@emails = [] | |
ContactImport.transaction do | |
emailed_association_requests.to_send.each do |ear| | |
ear.create_association_with(user.business) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Here are a couple of alternative suggestions for PSpec (see http://gist.github.com/305174). | |
# I'm not in love with any of these ideas, but hopefully they'll provide some food for thought. | |
# | |
# I like using strings for test names, so I like the 'with xxx' syntax, but I think that | |
# the 'with describe' doesn't makke sense - how about 'with subject': | |
with subject('calculator'): | |
with expectation('adds positive integers'): | |
expect(Calculator.add(1, 1)) == 2 | |
with expectation('adds negative integers'): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Spec::Matchers.define :have_a_machinist_blueprint do | |
match do |model| | |
model.class.respond_to?(:make) | |
end | |
description do | |
"works if there's a valid blueprint" | |
end | |
failure_message_for_should do |model| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Photo | |
belongs_to :photo_album | |
def set_cover(cover) | |
if cover | |
photo_album.cover = self | |
elsif photo_album.cover.nil? | |
# set album cover to first photo album if no cover has been set. | |
photo_album.cover = photo_album.photos.first |