Skip to content

Instantly share code, notes, and snippets.

View BenEddy's full-sized avatar
💭
🍂

Ben Eddy BenEddy

💭
🍂
  • Seattle
View GitHub Profile
@BenEddy
BenEddy / gist:1127814
Created August 5, 2011 15:48
Test Gist
More Codez
@BenEddy
BenEddy / eleven
Created August 5, 2011 15:56
Scrrrrrript.
activty stream
@BenEddy
BenEddy / encode-test
Created November 4, 2012 21:01 — forked from reagent/encode-test
Test harness for David's encode.c program
#!/usr/bin/env ruby
# Usage: ./encode-test /path/to/encode.c
require 'fileutils'
def directory(path)
path = File.expand_path(path)
if File.directory?(path)
path
class User < ActiveRecord::Base
has_many :tasks
def self.with_flagged_comments
includes(:task).merge(Task.with_flagged_comments)
end
end
class Task < ActiveRecord::Base
belongs_to :user
isFunction = (obj) ->
toString.call(obj) == '[object Function]'
Object.prototype.delegate = () ->
args = Array.prototype.slice.call(arguments);
[methods, options] = [args[0..(args.length - 2)], args[(args.length - 1)]]
for method in methods
delegation = (method, delegatedMethod) ->
@[method] = ->
class UserSearch
attr_reader :name, :email
def initialize(options = {})
@name = options[:name]
@email = options[:email]
end
def results
scope = User.scoped
describe UserSearch do
describe "#results" do
it "returns all Users" do
user = User.create!
expect(described_class.new.results).to eq([user])
end
context "a :name option is provided" do
it "returns Users with a matching first name" do
user = User.create!(first_name: "William")
class User < ActiveRecord::Base
attr_accessible :email, :first_name, :last_name
def self.name_matching(name)
where("lower(first_name) LIKE lower(:name)
OR lower(last_name) LIKE lower(:name)", name: name + "%")
end
def self.email_matching(email)
where("lower(email) LIKE lower(?)", email + "%")
describe User do
describe ".name_matching" do
let!(:user) { User.create!(first_name: "Gaius", last_name: "Baltar") }
it "scopes to Users with matching first names" do
expect(User.name_matching("Gaius")).to eq([user])
end
it "scopes to Users with matching last names" do
expect(User.name_matching("Baltar")).to eq([user])
class UserSearch
attr_reader :name, :email
def initialize(options = {})
@name = options[:name]
@email = options[:email]
end
def results
scope = User.scoped