Skip to content

Instantly share code, notes, and snippets.

@andrewpthorp
andrewpthorp / books_controller.rb
Created June 16, 2011 19:31
Books Controller Test
class BooksController < ApplicationController
before_filter :authorize, :only => [:new, :create, :edit, :update, :destroy]
load_and_authorize_resource
# GET /books
# GET /books.xml
def index
@title = "Books"
respond_to do |format|
@andrewpthorp
andrewpthorp / authorization_matcher.rb
Created June 17, 2011 15:08
Authorization Matcher
def responds_with_success_when_authenticated
@context.sign_in
do_request
@context.response.code == '200'
end
private :responds_with_success_when_authenticated
I am a jerk
@andrewpthorp
andrewpthorp / book.rb
Created June 20, 2011 03:44
Book Spec
STATES = %w(reading pending completed wishlist)
STATES.each do |state|
define_method "#{state}?" do
self.state == state
end
end
ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS.merge!({
:month_and_year => "%B %Y"
})
source 'http://rubygems.org'
gem 'rails', '3.1.0.rc4'
gem 'mysql2'
gem "clearance", :git => "git://github.com/thoughtbot/clearance.git"
gem 'cancan'
gem 'heroku'
gem 'paperclip', '~> 2.3'
gem 'aws-s3', :require => 'aws/s3'
gem 'formtastic'
select * from orders join order_statuses on orders.id=order_statuses.order_id where order_statuses.status not in ('test', 'test_failed', 'test_sent', 'test_queued');
@andrewpthorp
andrewpthorp / something.html
Created August 19, 2011 01:45
HTML markup
<header>
<h1>Test</h1>
<nav>
<a href="#">Test Link</a>
<a href="#">Test Link</a>
<a href="#">Test Link</a>
</nav>
<img />
</header>
class BrandIdentity < ActiveRecord::Base
has_one :library_asset, :dependent => :destroy, :as => :asset
end
@andrewpthorp
andrewpthorp / gist:1200961
Created September 7, 2011 15:57
Nesting tags
emails = []
recipient.contact.emails.each do |email|
emails << content_tag(:li) do
form.radio_button(:email, email.address, :class => "radio-button")
form.label(:email, nil, :value => email.address) do
"<span>#{email.location}</span>"
end
end
end
emails.join