This file contains 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 Company < ActiveRecord::Base | |
has_many :relationships | |
has_many :users, :through => :relationships, :uniq => true, :dependent => :destroy | |
with_options :through => :relationships, :source => :user, :dependent => :destroy, | |
:extend => Associations::RelationshipExtension do |co| | |
co.has_many :advisors, :conditions => ["relationships.role = ?", ROLES[:advisor]] | |
co.has_many :incubators, :conditions => ["relationships.role = ?", ROLES[:incubator]] | |
co.has_many :past_investors, :conditions => ["relationships.role = ?", ROLES[:past_investor]] | |
co.has_many :referrers, :conditions => ["relationships.role = ?", ROLES[:referrer]] |
This file contains 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
namespace :db do | |
namespace :fixtures do | |
desc 'Create some dummy development data from factories' | |
task :create => :environment do | |
unless Rails.env.development? || Rails.env.test? | |
puts "This task generates random data and is not intended for use in production." | |
exit 1 | |
end | |
unless admin = User.first(:conditions => { :username => 'admin' }) |
This file contains 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
# This monkeypatches engineyard-serverside to specify `--without` options for | |
# `bundle install` on Engine Yard deployment. It supercedes the instructions in | |
# this doc, which are currently outdated: | |
# | |
# http://docs.engineyard.com/bundler-tips-for-cloud.html | |
# | |
# More helpful is this one, which leads us to where the code can be found to | |
# override: | |
# | |
# http://docs.engineyard.com/customize-your-deployment.html#second |
This file contains 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
# To run after the `key` declaration is added to the above User model | |
User.all.each do |user| | |
nu = user.dup | |
user.unset :username # clear unique index | |
nu.save | |
# Could we re-associate without duping? My attempts resulted in | |
# `dependent: :destroy` getting invoked when the original user is deleted | |
nu.notes << user.notes.clone |
This file contains 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
ruby-1.9.2-p290 :001 > require 'pathname' | |
=> true | |
ruby-1.9.2-p290 :002 > p = Pathname.new('/Users/ches') | |
=> #<Pathname:/Users/ches> | |
ruby-1.9.2-p290 :003 > ENV['foobar'] = p + 'src' | |
TypeError: can't convert Pathname into String | |
from (irb):3:in `[]=' | |
from (irb):3 | |
from /Users/ches/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>' |
This file contains 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
# Brandon Keepers' "click on any element with given text" Capybara selector/Cucumber | |
# step pairing, adapted for Capybara 1.0+. | |
# http://collectiveidea.com/blog/archives/2010/08/03/clicking-any-element-with-cucumber-and-capybara/ | |
Capybara.add_selector(:element) do | |
xpath { |locator| "//*[normalize-space(text())=#{XPath::Expression::StringLiteral.new(locator)}]" } | |
end | |
When 'I click "$locator"' do |locator| | |
msg = "No element found with the content of '#{locator}'" | |
find(:element, locator, :message => msg).click |
This file contains 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
ActionMailer::Base.class_eval do | |
def mail_with_prefix(headers={}, &block) | |
unless Rails.env.production? | |
headers[:subject] = "[#{Rails.env.upcase}] " + (headers[:subject] || '') | |
end | |
mail_without_prefix(headers, &block) | |
end | |
alias_method_chain :mail, :prefix | |
end |
This file contains 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
begin | |
require 'hirb' | |
rescue LoadError | |
# Missing goodies, bummer | |
end | |
if defined? Hirb | |
# Dirty hack to support in-session Hirb.disable/enable | |
Hirb::View.instance_eval do | |
def enable_output_method |
This file contains 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
# There are a couple minor quirks (see https://github.com/guard/guard/issues/118), | |
# but mostly this is delightfully straightforward: | |
require 'guard' | |
namespace :assets do | |
desc 'Generate CSS from all source LESS files' | |
task :less do | |
Guard.setup | |
Guard::Dsl.evaluate_guardfile(:guardfile => 'Guardfile', :group => ['frontend']) |