Skip to content

Instantly share code, notes, and snippets.

View garybernhardt's full-sized avatar

Gary Bernhardt garybernhardt

View GitHub Profile
# I don't really see any services here. What I see is:
# - Normal HTTP boundary stuff (params flash, redirect).
# - Model creation and retrieval.
# - Warden manipulation, which is an odd done but smells like boundary.
#
# I left all of the HTTP boundary stuff in the controller (and only the
# controller). I moved the model creation/retrieval into simple class methods
# in the models. I moved the warden manipulation stuff into
# ApplicationController (with caveats that I'll discuss inline).
#
# Hash form:
{
:current_user => "CurrentUser.current_user"
}
# Discovery form with inverted app structure:
module Injectables
def current_user(session)
User.find(:id => session['current_user_id'])
end
# Rails controller
def create
@profile = ProfileManager.create(params[:profile])
rescue ProfileManager::CreationFailed => e
render :new, :errors => e.errors
end
# Raptor route
create :to => "ProfileManager#create", ProfileManager::CreationFailed => render(:new)
@garybernhardt
garybernhardt / lightning.txt
Created October 7, 2011 19:00 — forked from pycodeconf/lightning.txt
PyCodeConf 2011 Lightning Talk Signup
I want to give a lightning talk about:
"Wat?"
I need the projector: yes / no
Yes
# mock-based (interaction)
# db independent, but tied to implementation (I can change the AR call without affecting the behavior and this will fail)
context "data gathering" do
it "finds all indicators associated with the given sector and includes indicators not associated with any sectors" do
sector = stub_model(Sector, :id => 6)
Indicator.should_receive(:where).with("sector_id is null or sector_id = ?", sector.id)
Indicator.for_sector(sector)
end