Skip to content

Instantly share code, notes, and snippets.

View rubiety's full-sized avatar

Ben Hughes rubiety

View GitHub Profile
# MODEL
class Theater
named_scope :with_recent_comments,
:select => "*, recent_comments.created_at AS last_comment_at",
:joins => "INNER JOIN (SELECT id, entity_id, created_at FROM comments WHERE entity_type = 'Theater' LIMIT 100)
AS recent_comments ON recent_comments.entity_id = theaters.id",
:order => "recent_comments.created_at DESC"
end
@jc00ke
jc00ke / capybara-helpers.rb
Created January 28, 2012 07:47
Capybara helpers
def screenshot
require 'capybara/util/save_and_open_page'
now = Time.now
p = "/#{now.strftime('%Y-%m-%d-%H-%M-%S')}-#{rand}"
Capybara.save_page body, "#{p}.html"
path = Rails.root.join("#{Capybara.save_and_open_page_path}" "#{p}.png").to_s
page.driver.render path
Launchy.open path
end
@bensie
bensie / base.rb
Created December 6, 2012 17:53
Sinatra API Helpers
require "sinatra/base"
require "sinatra/namespace"
require "multi_json"
require "api/authentication"
require "api/error_handling"
require "api/pagination"
module Api
class Base < ::Sinatra::Base