Skip to content

Instantly share code, notes, and snippets.

View bcardarella's full-sized avatar
Out sailing

Brian Cardarella bcardarella

Out sailing
View GitHub Profile
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
namespace :myapp do
task :renew => %w{db:drop db:create db:migrate}
end
require 'spec_helper'
describe User do
describe "Object Attributes" do
before(:each) { @obj = User.new }
specify { @obj.should respond_to(:first_name) }
specify { @obj.should respond_to(:last_name) }
specify { @obj.should respond_to(:login) }
end
class Hour < ActiveRecord::Base
belongs_to :user
validates_with PunchclockValidator #defined in config/initializers/punchclock_validator.rb
validates_presence_of :role, :message => "can't be blank"
validates_associated :user
validates_numericality_of :manual, :allow_nil => true
validates_presence_of :start_time, :if => :punchcard?
validates_presence_of :manual, :if => :manual?
end
Feature: A user can punch in and out
In order to log hours
As an employee
I want to be able to punch in and punch out
Background:
Given the following user exists:
| name | email | password | role |
| foo | [email protected] | please | Employee |
And I log in as "[email protected]/please"
@bcardarella
bcardarella / hour.rb
Created June 10, 2011 05:07
User and hour model
class Hour < ActiveRecord::Base
belongs_to :user
validates_with PunchcardValidator #defined in config/initializers/punchclock_validator.rb
validates_presence_of :role, :message => "can't be blank"
validates_associated :user
validates_numericality_of :manual, :allow_nil => true
validates_presence_of :start_time, :if => :punchcard?
validates_presence_of :manual, :if => :manual?
@bcardarella
bcardarella / gist:1040967
Created June 22, 2011 19:43 — forked from theflowglenn/gist:1040942
Snippet from Rails 3 Client Side Validations JS to allow for AJAX spinner
// Set up the events for the form
form
.submit(function() { return form.isValid(settings.validators); })
// added loading toggle to handle the feedback spinner image (and changed 'beforeSend' to just 'before')
.bind('ajax:before', function() { $("#loading").toggle(); return form.isValid(settings.validators); })
.bind('ajax:success', function() { $("#loading").toggle(); })
// Callbacks
.bind('form:validate:after', function(eventData) { clientSideValidations.callbacks.form.after( form, eventData); })
.bind('form:validate:before', function(eventData) { clientSideValidations.callbacks.form.before(form, eventData); })
@bcardarella
bcardarella / gist:1161159
Created August 21, 2011 20:59 — forked from jasonm/gist:1161101
Links from #rcne 2011 backbone.js on rails fireside chat
require 'benchmark'
def ifelse
if true
1
else
2
end
end
require 'uri'
class IoraBot::Hangout < IoraBot::Observer
def matcher
/^(hangout|standup)(.*)$/mi
end
def handle(message, match_data)
person = message[:user][:name].split(' ')[0]
command = match_data[1]
if command == 'standup'
reply = "All: time for standup: #{link('iora_standup')}"