Skip to content

Instantly share code, notes, and snippets.

@cmaitchison
cmaitchison / seqeul.rake
Created May 13, 2011 12:42 — forked from tommeier/seqeul.rake
Close postgres open connections before running test suite
task 'db:test:prepare' => :close_postgres_connections
task :close_postgres_connections => :environment do
#Kill any other open connections on the test db
db_adapter = defined?(::ActiveRecord::Base) ? ActiveRecord::Base.connection : nil
db_adapter ||= defined?(::Sequel::Model) ? ::Sequel::Model.db : nil
if Rails.env.test? && db_adapter
db_config = Rails.configuration.database_configuration[Rails.env].symbolize_keys
begin
@cmaitchison
cmaitchison / valid.rb
Created October 11, 2012 13:10 — forked from notahat/valid.rb
Testing fail?
# By leaning hard on the declarative nature of let(), you get to use
# a pattern where there is a single shared example whose
# expected result is defined at a lower level in the code.
# It is not really a pattern that is intuitive to everyone when
# they read this sort of code for the first time, so I am not about
# to claim it is better than other approaches, only different.
# There is no need for explicit tests to assert that the correct
# arguments are passed to the validators in this example, because
# if the arguments are not correct the doubles will not return the
@cmaitchison
cmaitchison / after_commit_with_transactional_fixtures.rb
Last active August 4, 2016 03:30 — forked from charleseff/after_commit_with_transactional_fixtures.rb
testing after_commit hooks with transactional fixtures in Rails 4
require 'active_record/connection_adapters/abstract/transaction'
module ActiveRecord
module ConnectionAdapters
class SavepointTransaction < OpenTransaction
def perform_commit_with_transactional_fixtures
commit_records if number == 1
perform_commit_without_transactional_fixtures
end
alias_method_chain :perform_commit, :transactional_fixtures
@cmaitchison
cmaitchison / git-multi-status.sh
Created June 5, 2013 08:58 — forked from aroberts/git-multi-status.sh
git-multi-status == git-status for all subdirectories
#!/bin/bash
# usage: $0 source_dir [source_dir] ...
# where source_dir args are directories containing git repositories
red="\033[00;31m"
green="\033[00;32m"
yellow="\033[00;33m"
blue="\033[00;34m"
purple="\033[00;35m"