Skip to content

Instantly share code, notes, and snippets.

View semipermeable's full-sized avatar

Jay Moorthi semipermeable

View GitHub Profile
@semipermeable
semipermeable / tddium.rake
Created June 23, 2011 06:17
tddium:db_hook example
# lib/tasks/tddium.rake
namespace :tddium do
desc "tddium environment db setup task"
task :db_hook do
ENV['RAILS_ENV'] = 'test'
Rake::Task["db:create"].invoke
if File.exists?(File.join(Rails.root, "db", "schema.rb"))
Rake::Task['db:schema:load'].invoke
else
Rake::Task['db:migrate'].invoke
@semipermeable
semipermeable / data_migration_and_test.rb
Created July 14, 2011 19:18
Rails3 Data Migration and RSpec Test
# db/migrate/20110714024435_split_author.rb
class SplitAuthor < ActiveRecord::Migration
def self.up
Post.where(:author=>nil).each do |p|
author = Author.create!(:name => p.author_name,
:account_id => p.account_id)
p.author = author
p.save!
end
end
@semipermeable
semipermeable / pre-commit
Created July 18, 2011 02:14
tddium schema capture and load example
#!/bin/sh
set -e
bundle exec rake tddium:db:capture
@semipermeable
semipermeable / delayed_job
Created August 1, 2011 04:14
Sys-V init script for delayed job that plays well with capistrano and rvm
#! /bin/sh
### BEGIN INIT INFO
# Provides: delayed_job
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
### END INIT INFO
@semipermeable
semipermeable / tddium.yml
Created September 10, 2011 20:58
pgsuper tddium.yml config
#config/tddium.yml
:tddium:
:pgsuper: true
@semipermeable
semipermeable / tddium.yml
Created October 12, 2011 15:51
tddium.yml to disable mysql and use sqlite
# config/tddium.yml
:tddium:
:sqlite: true
:mysql: false
:mysqlsuper: false
@semipermeable
semipermeable / selenium_patch.rb
Created October 17, 2011 22:22
Monkeypatch to fix a race in Selenium-Webdriver
# features/support/selenium_patch.rb
# This patch attempts to fix a race condition in the selenium web driver
# Reference: https://code.google.com/p/selenium/issues/detail?id=2099
class Capybara::Selenium::Driver
def find(selector)
begin
browser.find_elements(:xpath, selector).map { |node| Capybara::Selenium::Node.new(self, node) }
rescue Selenium::WebDriver::Error::UnhandledError
@semipermeable
semipermeable / web_steps.rb
Created October 17, 2011 22:27
Replacement "When I select" step for old capybara and new selenium-webdriver
# features/step_definitions/web_steps.rb
# This replacement step works around an incompatibility between capybara-0.3.9 (or thereabouts) and selenium-webdriver >=2.5.0.
When /^(?:|I )select "([^"]*)" from "([^"]*)"(?: within "([^"]*)")?$/ do |value, field, selector|
with_scope(selector) do
# See https://github.com/jnicklas/capybara/issues/88
# page.find_by_id(field).select(value)
if Capybara.current_session.mode == :selenium
select_node = page.find_by_id(field)
@semipermeable
semipermeable / omniauth.rb
Created October 25, 2011 16:47
Tddium Omniauth Initializer
# config/initializers/omniauth.rb
require 'openid/store/filesystem'
use OmniAuth::Strategies::OpenID, OpenID::Store::Filesystem.new(Dir.tmpdir)
@semipermeable
semipermeable / test.rb
Created October 25, 2011 16:49
Rails FileStore cache initializer for Tddium
# config/environments/test.rb
require 'tmpdir'
config.cache_store = :file_store, File.join(Dir.tmpdir, "rails_cache") if ENV['TDDIUM']