Skip to content

Instantly share code, notes, and snippets.

# In your test_helper.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end
// 1: how could you rewrite the following to make it shorter?
if (foo) {
bar.doSomething(el);
} else {
bar.doSomethingElse(el);
}
@joshsusser
joshsusser / gist:998055
Created May 29, 2011 19:20
turn off 255 limit for string fields in postgresql
# in rails application.rb
initializer "postgresql.no_default_string_limit" do
ActiveSupport.on_load(:active_record) do
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:string].delete(:limit)
end
end

Ruby Debugger

Most of the time simple output statements using warn, raise, or a logger will help you find your issue. But sometimes you need the big guns, and that means ruby-debug.

Ruby-Debug

The ruby-debug package has had some rocky times during the transition from Ruby 1.8.7 to 1.9.2 and beyond. But now, finally, the debugger is reliable and usable.

Installation

@dcuddeback
dcuddeback / after_commit_with_transactional_fixtures.rb
Created August 25, 2011 01:36
Patch ActiveRecord to fire after_commit callbacks at the appropriate time during tests with transactional fixtures.
module ActiveRecord
module ConnectionAdapters
module DatabaseStatements
#
# Run the normal transaction method; when it's done, check to see if there
# is exactly one open transaction. If so, that's the transactional
# fixtures transaction; from the model's standpoint, the completed
# transaction is the real deal. Send commit callbacks to models.
#
# If the transaction block raises a Rollback, we need to know, so we don't
@steveklabnik
steveklabnik / after.rb
Created September 5, 2011 16:43
dont load rails!
require 'active_record'
require "#{Rails.root}/app/models/user"
describe User do
it "does something sweet"
it "does something cool"
end
@rsvp
rsvp / noise.sh
Last active April 18, 2024 14:18
noise : relaxing ambient Brown noise generator (cf. white noise) | Linux bash script using sox | CogSci notes
#!/usr/bin/env bash
# bash 4.1.5(1) Linux Ubuntu 10.04 Date : 2019-01-02
#
# _______________| noise : ambient Brown noise generator (cf. white noise).
#
# Usage: noise [minutes=59] [band-pass freq center=1786] [wave]
# ^minutes can be any positive integer.
# Command "noise 1" will display peak-level meter.
#
# Dependencies: play (from sox package)
@jcasimir
jcasimir / capybara_with_rack_test.markdown
Created September 16, 2011 00:19
Capybara with Rack::Test

Integration Testing with Capybara

Integration testing is awesome. Years ago, running integration tests was painful, slow, and they were so brittle that every change to the codebase broke the test suite.

Today it's a different story. We have amazing tools that make a tough job much easier. Let's check them out.

Background on Integration Testing

Integration tests are critically important because they exercise your application just like a real user. They therefore depend on the full stack from your models up through your controllers, helpers, view templates, web server, database, and middleware.

@dogenpunk
dogenpunk / consumer.rb
Created October 25, 2011 23:12 — forked from nragaz/consumer.rb
Consumer class to wrap Active Resource for OAuth
# Example usage:
#
# class Account < ActiveResource::Base
# self.site = "http://localhost:3000"
# end
#
# consumer = Consumer.new( user.access_token, Account )
# consumer.find(1) # => equivalent to Account.find(1), but with OAuth
class Consumer
@huynguyen
huynguyen / gist:1329273
Created October 31, 2011 22:42
ruby-1.9.3-p0 ruby-debug and rvm
#Need the latest version so it knows where to get ruby-1.9.3
rvm get head
curl -O https://github.com/ruby/ruby/pull/56.diff
rvm install ruby-1.9.3-p0 --patch 56.diff
cd ~/.rvm/src/ruby-1.9.3-p0
# Need to recompile because rvm doesn't force autoconf?