Skip to content

Instantly share code, notes, and snippets.

@slowjud
slowjud / string.rb
Created February 26, 2009 02:12 — forked from chrislloyd/string.rb
require 'singleton'
class String
class TextHelperSingleton
include Singleton
include ActionView::Helpers::TextHelper
end
def method_missing(method, *args)
Scenario: Visit the local conditions page for a location where conditions are available
Given I have a demonstration site
And the web service knows about "Sydney, NSW"
When I visit "/weather/local-conditions/nsw/sydney"
Then I should see "Sydney current conditions"
And I should see a "Dew point" value of "14"
def change_play_game
@game = Game.find(params[:game_id])
respond_to do |format|
format.js do
render(:update) do |page|
page[:game_display].replace_html(:partial => '/students/display_for_play', :locals => {:game => @game})
end
end
end
end
controllers = ActionController::Routing::Routes.routes.collect {|r| "#{r.defaults[:controller]}_controller".classify}
non_existent = []
controllers.uniq.each do |c|
begin
c.constantize
rescue
non_existent << c
end
end
missing_actions = []
ActionController::Routing::Routes.routes.each do |route|
begin
unless "#{route.defaults[:controller]}_controller".classify.constantize.instance_methods.include? route.defaults[:action]
missing_actions << route.defaults
end
rescue
end
end
foo = {}
basenames = ActionController::Routing::Routes.named_routes.routes.keys
basenames.each {|name| foo[name] = false}
Dir.glob(File.join(RAILS_ROOT, '/app', '**', '*.rb')).each do |file|
data = File.read(file)
basenames.each do |basename|
reg = Regexp.new(basename.to_s+"_(?=url|path)")
if reg.match data
foo[basename] = true
end
def alert_log
AlertLog.find(:all, :joins => [:want, :alert],
:conditions => ['wants.user_id = ? OR alerts.user_id = ?', id, id])
end
@slowjud
slowjud / bike.rb
Created March 10, 2014 23:55
Good Bike models for my mongoid talk at RORO
class Bike
include Mongoid::Document
field :brand_name
validates :brand_name, presence: true
STYLES = %w(CARBON_MONSTROSITY DUALIE FIXIE TOURER)
field :style
validates :style, inclusion: STYLES
@slowjud
slowjud / bike.rb
Last active August 29, 2015 13:57
Dodgy Bike models for my mogoid talk at RORO
class Bike
include Mongoid::Document
field :brand_name
validates :brand_name, presence: true
STYLES = %w(CARBON_MONSTROSITY DUALIE FIXIE TOURER)
field :style
validates :style, inclusion: STYLES
@slowjud
slowjud / queries.rb
Last active August 29, 2015 13:57
All the commands and seed data for my mongoid talk at RORO
# Indexes
Bike.where(style: 'FIXIE').explain['indexBounds']
Bike.where(brand_name: 'Genesis').explain['indexBounds']
Bike.where(style: 'FIXIE', brand_name: 'Genesis').explain['indexBounds']
# Nil and unset
chinarello = Bike.first
chinarello.colour = nil
chinarello.save
chinarello.reload