Skip to content

Instantly share code, notes, and snippets.


This example is not my real app, but it's modeled pretty closely to it.

My mom schedules a couple hundred employees at a local warehouse. In their system, a worker can earn "points" for being late or missing shifts. Here we have a sort of summary screen for my mom, who may need to follow up with new employees or discipline employees with concerning levels of points.

Questions that arise as I code something like this:

  • Which objects deserve presenters?
ryanb / employees_controller_test.rb
Created Sep 30, 2011 — forked from noahhendrix/employees_controller_test.rb
Testing a regular user can not create a user
View employees_controller_test.rb
require 'test_helper'
require 'clearance/testing'
class EmployeesControllerTest < ActionController::TestCase
test "an ASM can not create a user" do
assert_raise CanCan::AccessDenied do
post :create, :employee => { :name => 'Feed Store' }

First install the required gems:

gem install octokit awesomeprint rainbow

Then run it to extract all of your open GitHub issues into files (with comments).

ruby my-gh-issues.rb
View morse.rb
def morse s;26.times{|i|s.gsub! /#{(97+i).chr}/i,("$be5 J8G#T6P'&9Sl/,!-H0cfk"[i]-31).to_s(3).tr("12",".-")};s;end
View beautiful.rb
orders = {}
all_orders.group_by(&:ItemCode).each do |item_code, code_orders|
orders[item_code] = {}
code_orders.group_by(&:year).each do |year, year_orders|
orders[item_code][year] = {}
year_orders.group_by(&:month).each do |month, month_orders|
orders[item_code][year][month] = month_orders.first.quantity
orders[item_code][year]["total"] = orders[item_code][year]
View gist:71618
class Tag
has_many :taggings
named_scope :important, :include => { :taggings => :important }
class Tagging
belongs_to :tag
belongs_to :posts
# uses a string 'flag' column but could be changed to a boolean important
View gist:4688
# AR Object dup vs marshal benchmarks
# re:
# user system total real
# string saved in hash 0.060000 0.000000 0.060000 ( 0.051861)
# string marshalling 0.630000 0.000000 0.630000 ( 0.643304)
# object saved in hash 0.060000 0.000000 0.060000 ( 0.052789)
# object marshalling 7.020000 0.030000 7.050000 ( 7.073463)