Skip to content

Instantly share code, notes, and snippets.

# This class wraps an ActiveRecord database transaction, and contains a workaround
# for a memory bloat issue that happens when you create a large number of ActiveRecord
# model instances within a database transaction, and those model classes use the
# paper_trail gem for versioning.
#
# This workaround temporarily removes transaction callbacks registered on ActiveRecord
# classes by paper_trail, and then manually calls these callbacks once the transaction
# has finished. The precense of the transaction callbacks is what causes ActiveRecord
# to hold onto the model instances until the transaction finishes. ActiveRecord will
# not hold onto the model instances if no transaction callbacks are defined.
@denisahearn
denisahearn / test_http_digest_rails3_patch.rb
Created October 12, 2011 19:31
Testing HTTP Digest Authentication in Rails 3
# Adds support for http digest authentication in Rails 3
# Inspired by: http://lightyearsoftware.com/2009/04/testing-http-digest-authentication-in-rails/
# Place this code in test/test_helper.rb
# In your test, call authenticate_with_http_digest prior to calling get, post, put or delete
# Tested with Rails 3.0.7
class ActionController::TestCase
require 'digest/md5'
def authenticate_with_http_digest(user = API_USERNAME, password = API_PASSWORD, realm = API_REALM)