Skip to content

Instantly share code, notes, and snippets.

View gsterndale's full-sized avatar

Greg Sterndale gsterndale

View GitHub Profile
@gsterndale
gsterndale / gist:4072722
Created November 14, 2012 15:21
Philly.rb mailing list question
# https://groups.google.com/forum/?fromgroups=#!topic/phillyrb/SwN1G2Ek158
class UserAddressesController
def create
@user_address = current_user.user_addresses.build(params[:user_address])
if @user_address.save
#...
end
end
end
@gsterndale
gsterndale / gist:4072686
Created November 14, 2012 15:13
Philly.rb mailing list question
# https://groups.google.com/forum/?fromgroups=#!topic/phillyrb/SwN1G2Ek158
class UserAddressesController
def create
@user_address = current_user.user_addresses.build(params[:user][:user_address])
if @user_address.save
#...
end
end
end
def auth_check
if logged_in?
redirect_to 'http://www.msn.com' and return
elsif params[:action] != 'login' && params[:action] != 'login_attempt'
redirect_to '/login' and return
end
end
@gsterndale
gsterndale / gist:1627280
Created January 17, 2012 16:15
Sample scope spec
describe Listing, ".smallish" do
let!(:tiny_listing) { create(:listing, :size => 'tiny') }
subject { Listing.smallish }
it { should include tiny_listing }
end
@gsterndale
gsterndale / gist:1474766
Created December 14, 2011 01:16 — forked from jgarber/gist:1474739
Example refactoring for Greg's Rspec talk
describe TournamentRegistration do
let(:registration) {
create(:tournament_registration, :team_name => "Mighty Badgers")
}
subject { registration }
its(:to_param) { should == "#{registration.id}-mighty-badgers" }
end
@gsterndale
gsterndale / symbol_to_proc.rb
Created November 14, 2011 19:53
Refactor using "Symbol to Proc"
(1..5).map{|number| number.to_s }
# => ["1", "2", "3", "4", "5"]
(1..5).map(&:to_s)
# => ["1", "2", "3", "4", "5"]
@gsterndale
gsterndale / foo_spec.rb
Created August 16, 2011 18:13
Contrived Rspec test double example
require 'spec_helper'
class Foo
def self.string(capitalize=false)
capitalize ? 'FOO' : 'foo'
end
def three_strings
[ self.class.string, self.class.string(true), self.class.string, self.class.string(true)]
end
@gsterndale
gsterndale / Intermittent couchrest_model spec failures
Created March 2, 2011 18:53
ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin9.8.0], MBARI 0x8770, Ruby Enterprise Edition 2009.10
[couchrest_model] $ rspec spec/couchrest/class_proxy_spec.rb
.............F......
Failures:
1) Proxy Class should get last
Failure/Error: u.title.should == "aaa"
expected: "aaa",
got: "bbb" (using ==)
# ./spec/couchrest/class_proxy_spec.rb:93
class DirectionsController < ApplicationController
def new
@direction = Direction.new
@venues = Venue.all
end
def create
@direction = Direction.new(params[:direction])
respond_to do |format|
format.html do
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.14
PassengerRuby /usr/bin/ruby
PassengerLogLevel 0
PassengerUseGlobalQueue On
PassengerUserSwitching On
PassengerDefaultUser rails
PassengerMaxPoolSize 30
PassengerMaxInstancesPerApp 0
PassengerPoolIdleTime 0