Skip to content

Instantly share code, notes, and snippets.

describe "copying" do
context "within a cabinet_template" do
let (:cabinet_template) { FactoryGirl.create :cabinet_template }
let!(:ports) do
FactoryGirl.create_list(:component,
:with_ports,
:number_of_ports => 1,
:cabinet => cabinet_template).collect(&:ports).reduce(&:+).tap do |ports|
FactoryGirl.create :cable, :connections => ports
end
@bill-transue
bill-transue / add_rotator.rb
Created October 26, 2012 16:58
Is this dumb?
def add_rotator_to(hash)
hash.define_singleton_method :rotator do
inject({}) do |rotated, key_value|
if key_value.first =~ /_rotate/
rotated.merge key_value.first[0..-8].to_sym => self[key_value.first].rotate!.first
else
rotated.merge key_value.first => key_value.last
end
end
end
module TouchMyScheme
after_save :touch_my_scheme
def touch_my_scheme
scheme.touch
end
end
include "lib/touch_my_scheme"
# Load plugins (only those I whitelist)
Pry.config.should_load_plugins = false
Pry.plugins["doc"].activate!
# Launch Pry with access to the entire Rails stack.
# If you have Pry in your Gemfile, you can pass: ./script/console --irb=pry instead.
# If you don't, you can load it through the lines below :)
rails = File.join Dir.getwd, 'config', 'environment.rb'
if File.exist?(rails) && ENV['SKIP_RAILS'].nil?
if application "Messages" is running then
tell application "Messages"
log in service "transue@gmail.com"
set status of service "transue@gmail.com" to available
set status message to "%Track - %Artist"
end tell
end if
def collect_options_for_select(collection, selected=nil, &block)
options_for_select collection.collect { |member| block.call member }, selected
end
def elevations_for_sub_component_select(sub_component)
collect_options_for_select sub_component.component.send(sub_component.class.name.underscore.pluralize).find_all_by_model_id(sub_component.model_id), url_for do |sub_component|
if sub_component.is_a? SubComponentTemplate
[ sub_component.location, edit_admin_component_sub_component_path(sub_component.component, sub_component) ]
else
[ sub_component.location, edit_component_sub_component_path(sub_component.component, sub_component) ]
@bill-transue
bill-transue / .bash_profile
Created February 15, 2013 18:54
.bash_profile to override read-only TMOUT variable
if [ ! -z "$TMOUT" ]; then
env -i bash --init-file ~/.bash_profile
fi
# .bash_profile
export SHELL='/bin/bash'
export HOME='/home/bill.transue'
# git bash prompt
export PS1='\u@\h:\W$(__git_ps1 " (\[\033[32m\]%s\[\033[m\])")$ '
shared_examples_for 'a contact' do |options={}|
it { should be_a(Contact) }
its(:first_name) { should ==(first_name) }
its(:last_name) { should ==(last_name) }
its(:email) { should ==(email) }
unless options[:except_a_phone_number]
it "should scrape the phone number" do
subject.extended_contact_data_attributes[:phone_numbers].first[:value].should ==(phone_number)
end
module Enumerable
def collect_if
collect { |e| yield e }.reject &:nil
end
end
LeadGeneration::Lead.stub(:scrape_contact_from) do |email, attributes={}|
FactoryGirl.build :contact, attributes
end