Skip to content

Instantly share code, notes, and snippets.

class Orders::Step1Controller < PublicController
def new
end
def create
end
protected
@tatey
tatey / gist:2441508
Created April 22, 2012 02:25
Idea for good defaults that are easy to opt-out of with John Leighton's Focus Controllers
class PostsController
# You could believe we have a FcousedAction module that gives us
# good defaults. It exposes things like +action+ for defining
# normal RESTful actions.
include FocusedActions
# Example 1:
# The default behaviour is enough.
action :index
action :create
@tatey
tatey / Test1.m
Created April 29, 2012 23:35
With and without branching
@implementation Test1
- (id)init {
self = [super init];
if (self) {
[self addObserver:self forKeyPath:@"property1" options:0 context:NULL];
[self addObserver:self forKeyPath:@"property2" options:0 context:NULL];
}
}
require 'test_helper'
class PayPalExpress::TransactionSearchTest < ActiveSupport::TestCase
test "#search returns a collection of transactions" do
account = MiniTest::Mock.new
period = MiniTest::Mock.new
requester = MiniTest::Mock.new
params = {}
params['ACK'] = 'Success'
params.default = []
uhoh({"response":{"id":465,"bytes":450036,"created_at":"2012-04-22T22:24:29Z","image":{"url":"http://assets.desktoppr.co/wallpapers/3684af1ebd0380eb6acd669cf87ef9eb1e31c122/20080502_3dz_wallpapers_ru_vtorzhenie_2_1280x1024__130529_wp.jpg","thumb":{"url":"http://assets.desktoppr.co/wallpapers/3684af1ebd0380eb6acd669cf87ef9eb1e31c122/thumb_20080502_3dz_wallpapers_ru_vtorzhenie_2_1280x1024__130529_wp.jpg"},"preview":{"url":"http://assets.desktoppr.co/wallpapers/3684af1ebd0380eb6acd669cf87ef9eb1e31c122/preview_20080502_3dz_wallpapers_ru_vtorzhenie_2_1280x1024__130529_wp.jpg"}},"height":1024,"width":1280,"user_id":26,"user_count":5,"views_count":8}})
@tatey
tatey / gist:2585725
Created May 3, 2012 13:41
Desktoppr
uhoh({"response":{"id":465,"bytes":450036,"created_at":"2012-04-22T22:24:29Z","image":{"url":"http://assets.desktoppr.co/wallpapers/3684af1ebd0380eb6acd669cf87ef9eb1e31c122/20080502_3dz_wallpapers_ru_vtorzhenie_2_1280x1024__130529_wp.jpg","thumb":{"url":"http://assets.desktoppr.co/wallpapers/3684af1ebd0380eb6acd669cf87ef9eb1e31c122/thumb_20080502_3dz_wallpapers_ru_vtorzhenie_2_1280x1024__130529_wp.jpg"},"preview":{"url":"http://assets.desktoppr.co/wallpapers/3684af1ebd0380eb6acd669cf87ef9eb1e31c122/preview_20080502_3dz_wallpapers_ru_vtorzhenie_2_1280x1024__130529_wp.jpg"}},"height":1024,"width":1280,"user_id":26,"user_count":5,"views_count
class AddressBook
attr_accessor :contacts
def initialize
@contacts = {}
end
def numbers *names
names.map do |name|
@contacts[name]
def store store, &block
begin
original = Thread.current[:store]
Thread.current[:store] = store
yield
ensure
Thread.current[:store] = original
end
end
# I've noticed we want to do two different things when something about a model
# changes. Typically you would use ActiveModel::Observers, but the callbacks you
# get only have limited context forcing us to save more state to get it back later.
#
# The idea of this is that we can craft our own callbacks using a pub/sub pattern
# and pass in as much transient context as we want. We also want to bring in our
# analytics (or kiss metrics) on some of these callbacks.
#
# We can make our tests faster because we only care that our controller published
# the notification. Other tests will catch who is subscribed and what they should
@tatey
tatey / after.rb
Created August 21, 2012 10:58 — forked from coop/after.rb
module Publishers
class HTTP
attr_accessor :key
attr_reader :hosts
def initialize attributes = nil
attributes ||= {}
self.event = attributes[:event]
self.hosts = attributes.fetch(:hosts) do