Skip to content

Instantly share code, notes, and snippets.

info: Extracting ruby-enterprise-1.8.7-2010.02 ...
++ [[ -n '' ]]
+++ dirname /Users/thomasmpack/.rvm/log/ree-1.8.7-2010.02/extract.log
++ mkdir -p /Users/thomasmpack/.rvm/log/ree-1.8.7-2010.02
++ touch /Users/thomasmpack/.rvm/log/ree-1.8.7-2010.02/extract.log /Users/thomasmpack/.rvm/log/ree-1.8.7-2010.02/extract.error.log
++ tee /Users/thomasmpack/.rvm/log/ree-1.8.7-2010.02/extract.log
+++ date '+%Y-%m-%d %H:%M:%S'
++ echo '[2010-08-10 10:22:28] cat /Users/thomasmpack/.rvm/archives/ruby-enterprise-1.8.7-2010.02.tar.gz | gunzip | tar xf - -C /Users/thomasmpack/.rvm/src'
++ [[ -z '' ]]
++ eval 'cat /Users/thomasmpack/.rvm/archives/ruby-enterprise-1.8.7-2010.02.tar.gz | gunzip | tar xf - -C /Users/thomasmpack/.rvm/src'
describe "POST create" do
describe "with valid params" do
it "assigns a newly created attending as @attending" do
Attending.stub(:new).with({'event_id' => 1}) { mock_attending(:save => true) }
post :create, :event_id => 1
assigns(:attending).should be(mock_attending)
end
end
end
namespace :wtp do
namespace :jsroutes do
desc "Regenerate routes for users"
task :users do
puts "Recreating routes for users..."
JsRoutes.generate!({})
end
end
end
@mikepack
mikepack / gist:1222505
Created September 16, 2011 16:38
Subdoamin Helper
module UrlHelper
def with_subdomain(subdomain)
subdomain = (subdomain || "")
subdomain += "." unless subdomain.empty?
[subdomain, request.domain, request.port_string].join
end
def url_for(options = nil)
if options.kind_of?(Hash) && options.has_key?(:subdomain)
options[:host] = with_subdomain(options.delete(:subdomain))
@mikepack
mikepack / dci-rest-creation.rb
Created January 26, 2012 20:50 — forked from justinwiley/dci-rest-creation.rb
DCI + Rails new and create
# ---role
module BookManager
def create_book(attrs)
self.books.create! attrs
end
def update_book(book_id,attrs)
book = self.books.find(book_id)
book.update_attributes attrs
@mikepack
mikepack / interest_spec.rb
Created February 12, 2012 20:01
interest_spec.rb
require 'services/user'
require 'services/artist'
describe 'POST /interests' do
# Use User and Artist Ruby wrappers to call services
let(:user) { Services::User.create(:name => 'Mike Pack') }
let(:artist) { Services::Artist.create(:name => 'Cool Band', :genres => ['Jazz', 'R&B']) }
it 'registers a users interest in an artist' do
# Initiate POST request
post '/interests' do
# Connect to Redis
uri = URI.parse(ENV["REDIS_URL"] || 'redis://localhost:6379')
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
# Parse the JSON body
join = JSON.parse(request.body.read)
# Register the user's interest in an artist
REDIS.sadd("artists:#{join['artist_id']}", join['user_id'])
REDIS.smembers('artists:1') #=> ["1","2","3"] where 1, 2 and 3 are user IDs
REDIS.smembers('users:1') #=> ["1","2","3"] where 1, 2 and 3 are artist IDs
artist_keys = REDIS.smembers('users:1')
artist_keys.map!{ |artist_id| "artists:#{artist_id}" } #=> ["artists:1", "artists:2", "artists:3"]
REDIS.sinter(*artist_keys) #=> ["2","3"] where 2 and 3 are user IDs
@mikepack
mikepack / gist:1854515
Created February 17, 2012 17:34
Test Nomenclature