Skip to content

Instantly share code, notes, and snippets.

View jasonswett's full-sized avatar

Jason Swett jasonswett

View GitHub Profile
@jasonswett
jasonswett / appointment.rb
Created November 24, 2013 18:25
A fat model
class Appointment < ActiveRecord::Base
include ActionView::Helpers::NumberHelper
default_scope :order => "start_time asc"
scope :in_date_range, lambda { |start_date, end_date| self.in_date_range(start_date, end_date) }
scope :for_day, lambda { |date| in_date_range(date, date) }
scope :for_today, lambda { for_day(Time.zone.today) }
scope :for_tomorrow, lambda { for_day(Time.zone.today + 1.day) }
scope :not_time_blocks, joins(:time_block_type).where("code = 'APPOINTMENT'")
scope :checked_out, joins(:payments)
@jasonswett
jasonswett / Gemfile
Created November 24, 2013 17:16
Perpetuity Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.1'
# Use postgresql as the database for Active Record
gem 'pg'
gem 'perpetuity', git: 'git://github.com/jgaskins/perpetuity.git', ref: '82cad54d7226ad17ce25d74c751faf8f2c2c4eb2'
gem 'perpetuity-postgres', git: 'git://github.com/jgaskins/perpetuity-postgres.git', ref: 'c167d338edc05da582ff3856e86f7fb7693df0bb'
FactoryGirl.define do
factory :employee do
# Your callback can be either for :build or :create, whichever
# makes the most sense for your situation.
after(:build) { |instance| instance.skills << create_list(:skill, 5) }
end
end
@jasonswett
jasonswett / gist:3388090
Created August 18, 2012 16:17
test cases
# single tag
find recipe
1 chicken alfredo
2 chicken pot pie
3 meatloaf
4 pasta primavera
5 spaghetti
# recipe AND chicken
find recipe chicken
<%= form_for(@client) do |f| %>
<% if @client.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@client.errors.count, "error") %> prohibited this client from being saved:</h2>
<ul>
<% @client.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>