Skip to content

Instantly share code, notes, and snippets.

def jobs
Job.where(user_id: self.id)
end
@pjc
pjc / tdd.rb
Created July 24, 2013 14:59
TDD by example chapter 5/6 equality / privacy
require 'minitest/autorun'
# WE NEED TO BE ABLE TO ... AND ... GIVEN ...
# WE NEED TO BE ABLE TO add amounts in different currencies AND convert the result GIVEN a set of exchange rates
# $5 + 10 CHF = $10 if CHF:USD rate is 2:1
# WE NEED TO BE ABLE TO multiply a number (of shares) with an amount (price per share) AND receive an amount
# $5 * 2 = $10
# money rounding, make amount private, equals(), hashCode(), equal null, equal object?
class Dollar
require 'minitest/autorun'
class Dollar
def initialize(amount)
@amount = amount
end
def times(multiplier)
Dollar.new(@amount * multiplier)
end
def equals?(object)
FACTUAL_KEY = #omitted
FACTUAL_SECRET_KEY = #omitted
LOB_TEST_API_KEY = #omitted
require 'factual'
require 'lob'
factual = Factual.new(FACTUAL_KEY, FACTUAL_SECRET_KEY)
hotels = factual.table("hotels-us").limit(20).rows
module Tutorials
def the_best_one_out_there
"PJ Celis' tutorial on getting to know a code base"
end
end
class RecommendationsController < ApplicationController
def tweet_out_the_best
recommended_tutorial = Tutorials.the_best_one_out_there
Tweeter.send(tweet(recommended_tutorial))