Skip to content

Instantly share code, notes, and snippets.

View thechrisoshow's full-sized avatar

Chris O'Sullivan thechrisoshow

View GitHub Profile
@thechrisoshow
thechrisoshow / Test::Unit assertion to detect a delete link
Created November 11, 2008 10:23
How do you detect a delete link in Rails?
@thechrisoshow
thechrisoshow / gist:29366
Created November 26, 2008 11:43
What's wrong with this?
> bits = [15.8, 8.0, 9.4, 3.0, 1.6, 2.0, 12.0, 4.8, 1.7, 6.0, 3.0, 17.7, 6.0, 4.0, 3.0, 2.0]
=> [15.8, 8.0, 9.4, 3.0, 1.6, 2.0, 12.0, 4.8, 1.7, 6.0, 3.0, 17.7, 6.0, 4.0, 3.0, 2.0]
> result = bits.inject(0.0) {|sum, v| sum += v}
=> 100.0
> result > 100.0
=> true
> # huh!? why is 100.0 > 100.0
> # Although admittedly this is in Ruby 1.8.4
validate :"that I don't have any balls"
define_method "that I don't have any balls" do
false
end
require 'rubygems'
require 'smqueue'
# This script shows how posting to separate queues with the same client id blows up
def default_config
# Change host to whatever activemq host you want to use
{:adapter => "StompAdapter", :host => "localhost", :reliable => false}
end
# You can use a param variable in another params default value, like this:
def get_name(firstname, lastname, error_message="You blew it #{firstname}, you messed up")
end
# Turns a fixture file name into a full path
def fixture_file(filename)
return '' if filename == ''
ERB.new(File.read(File.expand_path(RAILS_ROOT + '/spec/fixtures/' + filename))).result(binding)
end
Business value and MMF
======================
You should discuss the “In order to” part of the feature and pop the why
stack max 5 times (ask why recursively) until you end up with one of the
following business values:
* Protect revenue
* Increase revenue
* Manage cost
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Event do
it "should be refillable if the event is floating and not complete" do
event = Event.new(:complete => false)
event.stub!(:floating?).and_return true
event.should be_refillable
end
def schedule_task_to_next_available_worker(task)
@workers.each do |worker|
task_scheduler = TaskScheduler.new(worker.bucket)
if task_scheduler.task_valid_for_putting_into_buckets?(task)
task_scheduler.schedule_task(task)
if !worker.bucket.has_warning?(:overdue)
remove_task_from_workers_events(worker, task)
worker.bucket.clear_warnings!
def schedule_task_to_next_available_worker(task)
@workers.each do |worker|
task_scheduler = TaskScheduler.new(worker.bucket)
if task_scheduler.task_valid_for_putting_into_buckets?(task)
task_scheduler.schedule_task(task)
if !worker.bucket.has_warning?(:overdue)
if !any_workers_after_this_one_have_hat(task.hat)
@tasks_past_deadline << task