Skip to content

Instantly share code, notes, and snippets.

View airblade's full-sized avatar

Andy Stewart airblade

View GitHub Profile
# PaperTrail's version class (existing code omitted for clarity).
class Version < ActiveRecord::Base
before_update :before_update_hook
after_update :after_update_hook
def before_update_hook
end
def after_update_hook
end
class ApplicationController < ActionController::Base
include Intercession
before_filter :load_skin
before_filter :require_user
before_filter :require_matching_skin
before_filter :require_admin
def load_skin
session.skin = Skin.for_request(request)
@airblade
airblade / html.rb
Created May 12, 2010 09:02 — forked from mislav/html.rb
require 'nokogiri'
ugly = Nokogiri::HTML ARGF
tidy = Nokogiri::XSLT File.open('tidy.xsl')
nice = tidy.transform(ugly).to_html
puts nice
delete_all [prefix=mephisto_production/bin_logs, @name=airbladesoftware]...
size: 2
delete mephisto_production/bin_logs/mysql-bin.000001: true
size: 1
...done
# Rackup file for serving up a static site from a "public" directory
#
# Useful for chucking a static site on Heroku
class IndexRewriter
def initialize(app) @app = app end
def call(env)
env["PATH_INFO"].gsub! /\/$/, '/index.html'
@app.call(env)
end
Then /^(?:I|they) should see the email delivered from "([^"]*?)"$/ do |text|
#current_email.should be_delivered_from(text)
should_be_delivered_from(text)
end
$ rake test
(in /Users/andy/business/open_source/paper_trail)
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I"lib:lib:test" "/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb" "test/paper_trail_controller_test.rb" "test/paper_trail_model_test.rb" "test/paper_trail_schema_test.rb" "test/thread_safe_test.rb"
/Library/Ruby/Site/1.8/rubygems.rb:233:in `activate': can't activate actionpack (= 2.3.8, runtime) for [], already activated actionpack-3.0.0 for [] (Gem::LoadError)
from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:35:in `require'
from ./test/test_helper.rb:8
from ./test/paper_trail_controller_test.rb:1:in `require'
from ./test/paper_trail_controller_test.rb:1
from /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5:in `load'
from /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader.rb:5
keywords = [] # the keywords belonging to @publication at the time
keywords_versions = Version.all :item_type => 'Keyword', :publication_id => @publication.id
keywords_versions.group_by(&:item_id).each do |item_id, versions|
v = versions.first :conditions => ['created_at > ?', (@publication.created_at - 3.seconds)]
keywords << (v ? v.reify : Keyword.find(item_id))
end
variables = keywords.map do |keyword|
class PublicationsController < ActionController::Base
def show
@publication = Publication.find params[:id]
# If you need a specific version, get that from the URL.
version_id = ...
@publication = @publication.versions.find version_id
keywords = [] # the keywords belonging to @publication at the time
keywords_versions = Version.all :item_type => 'Keyword', :publication_id => @publication.id