Sometimes relationships need to be flexible, and that's where we look to polymorphism. Say we want to implement:
- A
Person
- A
Company
- A
PhoneNumber
that can connect to aPerson
or aCompany
# Functional test just to demonstrate that everything is hooked up | |
describe UsersController, "POST create", :type => :controller do | |
before(:each) do | |
UsersController.dispatcher = DefaultDispatcher | |
end | |
context "successful" do | |
it "should create a user" do | |
lambda { |
/** | |
Sample Propane caveatPatchor.js file based on tmm1's avatar hack. | |
You'll need at least version 1.1.1 to experiment with this: | |
http://propaneapp.com/appcast/Propane.1.1.1.zip | |
Once I'm sure exposing this hack-injection point doesn't cause problems | |
I'll do an official auto-updating version. | |
As of version 1.1.1, Propane will load and execute the contents of |
rvm use @$(basename `pwd`) --create |
def maybe_a_sandwich | |
nil | |
end | |
# Methods that might return nil are annoying. We want to write a nice | |
# confident chain: | |
result = nil | |
result = maybe_a_sandwich.add_horseradish.get_into_my_belly! rescue $! | |
result # => #<NoMethodError: undefined method `add_horseradish' for nil:NilClass> |
$('#products').append('<%= j render(@products) %>'); | |
<% if @products.next_page %> | |
$('.pagination').replaceWith('<%= j will_paginate(@products) %>'); | |
<% else %> | |
$('.pagination').remove(); | |
<% end %> |
def output name=((default=true); "caius") | |
puts "name: #{name.inspect}" | |
puts "default: #{default.inspect}" | |
end | |
output | |
# >> name: "caius" | |
# >> default: true | |
output "avdi" |
SiloRackApp = Rack::Builder.new do | |
use Rack::Runtime # add X-Runtime header | |
use E20::Ops::Middleware::RevisionMiddleware, logger: Silo.logger | |
use E20::Ops::Middleware::TransactionIdMiddleware, logger: Silo.logger | |
use E20::Ops::Middleware::HostnameMiddleware, logger: Silo.logger | |
use Clogger, | |
format: Clogger::Format::Combined, | |
path: File.join(Silo::ROOT, 'log', 'silo.access.log'), | |
reentrant: true |
def stub_model(model_name) | |
stub_class model_name, ActiveRecord::Base | |
end | |
def stub_class(class_name, super_class = Object) | |
stub_module class_name, Class.new(super_class) | |
end | |
def stub_module(module_name, object = Module.new) | |
module_name = module_name.to_s.camelize |
This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.
You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf
using homebrew.