Skip to content

Instantly share code, notes, and snippets.

RSpec.configure do |config|
config.before(:all) do
clear_database
end
end
def clear_database
Mongoid.master.collections.select {|c| c.name !~ /system/ }.each(&:drop)
end
def access_token
@access_token ||= begin
twitter_request = session['twitter_request']
oauth.authorize_from_request(twitter_request.token, twitter_request.secret, params['oauth_verifier'])
oauth.access_token
end
end
def oauth(opts = {})
@oauth ||= ::Twitter::OAuth.new(config.twitter_api_keys['token'], config.twitter_api_keys['secret'], opts)
git log --all -M -C --name-only | grep -E '^(app|lib)/' | sort | uniq -c | sort
@leshill
leshill / gist:870866
Created March 15, 2011 15:17
Cucumber/Capybara JS alert handling
# Add this to more_web_steps.rb
# Selenium docs: http://code.google.com/p/selenium/wiki/RubyBindings#Javascript_Alert/Confirm today!
When /^I (accept|dismiss) the "([^"]*)" alert$/ do |action, text|
alert = page.driver.browser.switch_to.alert
alert.text.should eq(text)
alert.send(action)
end
@leshill
leshill / gist:882626
Created March 23, 2011 04:41
Using brew? Want git tab completion in bash? Add to your .bashrc (or .bashrc.local)
git_completion=`brew --prefix git`/etc/bash_completion.d/git-completion.bash
if [ -f $git_completion ] ; then source $git_completion; fi
# Setup the following in your heroku config vars:
# See http://blog.leshill.org/blog/2010/11/02/heroku-environment-variables.html for an idea on how to do it
HEROKU_APP: poh-dev
HEROKU_USER: heroku@infbio.com
HEROKU_PASSWORD: replace_me
# Gemfile
gem 'heroku', '>= 1.19.1'
gem 'resque'
# Use our fork until our fix is merged.
@leshill
leshill / .bashrc.local
Created April 14, 2011 21:58
Add this to the bottom of your .bashrc.local
# Git completion
git_completion=/usr/local/etc/bash_completion.d/git-completion.bash
if [ -f $git_completion ] ; then source $git_completion; fi
@leshill
leshill / mongoid.yml
Created April 27, 2011 15:16
Using mongoid with specjour
test: &test
<<: *defaults
database: app_test<%=ENV["TEST_ENV_NUMBER"]%>
@leshill
leshill / capybara.rb
Created May 2, 2011 05:41
Capybara example.org/example.com issue #36
class Capybara::RackTest::Browser
def build_rack_mock_session
Rack::MockSession.new(app, URI.parse(current_host).host)
end
end
@leshill
leshill / application_controller.rb
Created May 16, 2011 17:58
Work in progress...
#app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
before_filter :scheduler_redirect if ENV['SCHEDULER_REDIRECT']
# ...
private
def scheduler_redirect