Skip to content

Instantly share code, notes, and snippets.

View jferris's full-sized avatar

Joe Ferris jferris

  • thoughtbot, inc.
  • Cambridge, MA
View GitHub Profile
User.admins # return all admins
User.editors # return all editors
User.admins.editors # return all users that are admins and editors
User.not.admins # return all users that are not admins
User.admins.or.editors # return all users that are admins or editors
class Job < ActiveRecord::Base
def search(options)
Job.
active.unless { options[:include_inactive] }.
#!/usr/bin/env ruby
require 'fileutils'
class TestFinder
attr_reader :prefix
def initialize(prefix)
@prefix = prefix
end
@jferris
jferris / gist:134582
Created June 23, 2009 15:13
should_delegate
class Test::Unit::TestCase
# call-seq:
# should_delegate(method, :to => member)
#
# Generates a test asserting that +method+ returns the value of that method
# on +member+.
#
# Example:
# should_deleate :full_name, :to => :user
def self.should_delegate(method, opts)
#!/usr/bin/env ruby
require 'fileutils'
def usage
puts "Usage: schema -l [partial_model_name] OR schema <model_name>"
end
if ARGV.first == '-l'
def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
# completion for schema
_rails_tables() {
if [[ -n $words[2] ]]; then
compadd `schema -l ${words[2]}`
fi
}
compdef _rails_tables schema
---
notice:
api_key: api_key_value
session:
key: ""
data:
session_id: 12345
user_id: 2
flash:
notice: Logged in successfully
<?xml version="1.0"?>
<notice version="2.0">
<api-key>345263346</api-key>
<error>
<class>RuntimeError</class>
<message>RuntimeError: Example</message>
<backtrace>
<line file="app/models/groups.rb" number="3" method="find"/>
<line file="app/controller/groups_controller.rb" number="7" method="find"/>
</backtrace>
module ModelBuilder
def self.included(spec)
spec.before(:each) do
@created_tables = []
@defined_constants = []
end
spec.after(:each) { undefine_constants }
spec.after(:each) { drop_created_tables }
spec.send(:include, Helpers)
end
class UsersControllerTest
# With context
context "on GET show, given the user exists" do
setup do
@user = Factory.stub(:user)
User.stubs(:find => @user)
get :show, :id => @user.to_param
end
should_respond_with :success
describe PostsController do
it "should show the given post on GET show" do
post = stub('a post', :to_param => '1')
Post.stubs(:find => post)
get :show, :id => post.to_param
Post.should have_received(:find).with(post.to_param)
should render_template(:show)
should assign_to(:post).with(post)