Skip to content

Instantly share code, notes, and snippets.

@svs
svs / workflow_spec.rb
Created July 13, 2012 12:12
Unit Testing a Workflow
describe Document do
context "with a scan" do
subject {FactoryGirl.build(:scannable)}
it {should have_events([:scan])}
end
context "taggable" do
subject { FactoryGirl.build(:taggable) }
it {should have_events([:to_edit])}
@svs
svs / gist:2478214
Created April 24, 2012 09:23
Question about Rich Hickey's 'use hashes not classes' statement

So I don't have a model called Person, but I use hashes like {:name => "Siddharth", :sex => "Y"}. Great. Now I want to validate the presence of certain fields before persisting to the database. What do I do?

Module PersonValidation
  function validate_presence_of_name(person_hash)
    person_hash[:errors][:name] = "EEENKKK!" unless person_hash[:name]
  end
  
  ...
 ...
class LoanHistory
include DataMapper::Resource
property :loan_id, Integer, :key => true
property :date, Date, :key => true # the day that this record applies to
property :created_at, DateTime # automatic, nice for benchmarking runs
# some properties for similarly named methods of a loan:
property :scheduled_outstanding_total, Decimal, :nullable => false
@svs
svs / ruby-mode.el.diff
Created January 30, 2012 17:44
ruby-mode.el differentiate symbols from ordinary variables
git diff
diff --git a/ruby-mode.el b/ruby-mode.el
index b556e95..838d811 100644
--- a/ruby-mode.el
+++ b/ruby-mode.el
@@ -1169,7 +1169,7 @@ balanced expression is found."
2 font-lock-type-face)
;; symbols
'("\\(^\\|[^:]\\)\\(:\\([-+~]@?\\|[/%&|^`]\\|\\*\\*?\\|<\\(<\\|=>?\\)?\\|>[>=]?\\|===?\\|=~\\|\\[\\]=?\\|\\(\\w\\|_\\)+\\([!?=]\\|\\b_*\\)\\|#{[^}\n\\\\]*\\(\
- 2 font-lock-reference-face)
;; example rails like console for compojure showing params, etc. for each request
(ns bus.core
(:use compojure.core
ring.adapter.jetty
...
...
(:use ring.middleware.params))
#controllers/application.rb
...
class Hash
def diff(other)
keys = self.keys
keys.each.select{|k| self[k] != other[k]}
end
end
#config/init.rb