Skip to content

Instantly share code, notes, and snippets.

describe "GET current" do
before do
@request.cookies['hidden_notices'] = "1,#{notices(:permanent).id}"
get :current, :format => 'js'
end
it { should respond_with(:success) }
it { should set_cookie(:hidden_notices).to("#{notices(:permanent).id}") }
it { should render_template('notices/current') }
end
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
class BuildStatusTest < ActiveSupport::TestCase
test "remove the old statii" do
assert_equal 2, BuildStatus.count
BuildStatus.expire_old
statii = BuildStatus.all
assert_equal 1, statii.size
assert statii[0].updated_at >= 30.days.ago
end
kendall :: git/rbx » ruby scratch/bm_either.rb
Rehearsal ---------------------------------------------
includes? 4.410000 0.000000 4.410000 ( 4.421223)
either? 6.450000 0.000000 6.450000 ( 6.478906)
compare 2.040000 0.010000 2.050000 ( 2.044516)
----------------------------------- total: 12.910000sec
user system total real
includes? 4.470000 0.000000 4.470000 ( 4.479386)
either? 6.520000 0.000000 6.520000 ( 6.542424)
@dhh
dhh / gist:965746
Created May 11, 2011 01:33
Pjax helper
module Pjax
extend ActiveSupport::Concern
included do
layout ->(c) { pjax_request? ? false : 'application' }
end
private
def redirect_pjax_to(action, url = nil)
new_url = url_for(url ? url : { action: action })
@dhh
dhh / gist:966575
Created May 11, 2011 14:43
Mailbag feature
class NotesController < ApplicationController
def create
@note = @project.notes.create params[:note].merge(
creator: current_user, subscribers: extract_subscribers(params[:note]))
@note.subscribers.each { |subscriber| Subscriptions.note(@note, subscriber).deliver }
end
end
class Subscriptions < ActionMailer::Base
@dhh
dhh / gist:966615
Created May 11, 2011 14:59
Database design snapshots
Designers need fleshed out pages to do properly design a screen.
In the past, we've loaded test fixtures in development to give them that.
But test fixtures are not a good fit for this.
They're designed to make testing easy, not designing.
What we need instead is a way for a designer to create a dataset
that'll work great for design and then save that as a snapshot.
This snapshot can be named and reloaded as often as desired.
I envision it'll work like this:
@dhh
dhh / gist:981520
Created May 19, 2011 19:27
bulk api
# Bulk API design
#
# resources :posts
class PostsController < ActiveController::Base
# GET /posts/1,4,50,90
# post_url([ @post, @post ])
def show_many
@posts = Post.find(params[:ids])
end
@dhh
dhh / gist:1014971
Created June 8, 2011 18:09
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
def revoke(user)
proxy_association.owner.tap do |project|
# You can't remove the last user with access (someone has to have access to the project!)
if project.users.many?
if user.pending? && user.projects.one?
user.destroy
else
project.users.delete(user)
user.touch
end
Hi David,
I came across your profile online and wanted to reach out about Development
Opportunities here at Groupon. The company is growing, and we're always
looking for folks with solid skills that can make positive contribution to
our continued success. Any chance you'd be open to a quick conversation
about opportunities, or for any possible networking potential? If so, let me
know when you're free and we can set up a time to chat. Also, if you are
interested, it would be great if you could forward a current resume over
that I can take a look at. I look forward to hearing back from you! Please
let me know if you have any questions.