Skip to content

Instantly share code, notes, and snippets.

View jamesbebbington's full-sized avatar

James Bebbington jamesbebbington

View GitHub Profile
@jamesbebbington
jamesbebbington / application_controller.rb
Created August 4, 2011 11:16 — forked from robertsosinski/caching_with_request_forgery_protection.rb
Rack middleware and form tag patch to insert csrf tokens into cached pages
class ApplicationController < ActionController::Base
TOKEN_PLACEHOLDER = "__CROSS_SITE_REQUEST_FORGERY_PROTECTION_TOKEN__"
after_filter :inject_csrf_token
private
def inject_csrf_token
if protect_against_forgery? && token = session['_csrf_token']
if body_with_token = response.body.gsub!(TOKEN_PLACEHOLDER, token)
class Test::Unit::TestCase
# Assert that the model accepts nested attributes for the given +associations+
#
# Example:
# should_accept_nested_attributes_for :orders
#
def self.should_accept_nested_attributes_for(*associations)
associations.each do |association|
should "accept nested attributes for #{association}" do