Skip to content

Instantly share code, notes, and snippets.

View codespectator's full-sized avatar

James MacLeod codespectator

View GitHub Profile
<% select_options = %w{Enrolled Redeem Social}.collect {|opt| [opt, opt.downcase] } %>
<%= select_tag :dynamic_select, options_for_select(select_options, :selected => params[:type]), :prompt => 'All' %>
rake aborted!
regexp buffer overflow
(in /Users/james/code/mynightuk/app/assets/stylesheets/application.css)
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
rake --trace assets:precompile RAILS_ENV=production 15.27s user 4.35s system 88% cpu 22.069 total
@codespectator
codespectator / gist:1780478
Created February 9, 2012 14:57
Failed test
# Cucumber test
Scenario: Sign up without entering Account name
When I navigate to the signup form
And I fill in every signup field except "Account name"
And I click the signup button
Then I should be shown an error message telling me to enter "Account name"
# Step definitions
<!DOCTYPE html>
<!-- Helpful things to keep in your <head/>
// Brian Blakely, 360i
// http://twitter.com/brianblakely/
-->
<head>
<!-- Disable automatic DNS prefetching.
## lib/test/test.rb
require 'lib/test/app/models/card'
require 'lib/test/exts/user'
## lib/test/exts/user.rb
module Test
module User
module ClassMethods
@codespectator
codespectator / gist:1336230
Created November 3, 2011 10:37
Reload instance variable
it "should save latlng in db" do
@venue = Fabricate(:venue)
expect { Venue.find_address(@venue.id) }.to change(@venue, :latlng).to([51.5339146, 0.7840745000000001])
end
# Example:
def example(class)
class.constantize.all
end
# Calling it:
example('person')
@codespectator
codespectator / gist:1111500
Created July 28, 2011 13:07
Method for calling via switch case
def manage_thing(args={})
args.each do |action, object|
case action
when :create
# create code
when :remove
# removal code
end
end
end
@codespectator
codespectator / gist:1069315
Created July 7, 2011 11:16
Newrelic output for deployment tracking
MacBook-Pro:turnstile-stable(1m|master) $ cap newrelic:notice_deployment -Snewrelic_desc="This is a test"
* executing `newrelic:notice_deployment'
* Getting log of changes for New Relic Deployment details
** Error creating New Relic deployment (undefined local variable or method `source' for #<Capistrano::Configuration::Namespaces::Namespace:0x0000010148e110>)
** /Users/james/.rvm/gems/ruby-1.9.2-p0@turnstile-stable/gems/capistrano-2.6.0/lib/capistrano/configuration/namespaces.rb:188:in `method_missing'
** /Users/james/.rvm/gems/ruby-1.9.2-p0@turnstile-stable/gems/newrelic_rpm-3.1.0/lib/new_relic/recipes.rb:28:in `block (3 levels) in <top (required)>'
** /Users/james/.rvm/gems/ruby-1.9.2-p0@turnstile-stable/gems/capistrano-2.6.0/lib/capistrano/configuration/execution.rb:139:in `instance_eval'
** /Users/james/.rvm/gems/ruby-1.9.2-p0@turnstile-stable/gems/capistrano-2.6.0/lib/capistrano/configuration/execution.rb:139:in `invoke_task_directly'
** /Users/james/.rvm/gems/ruby-1.9.2-p0@turnstile-stable/g
# Email model
class EmailAddress < ActiveRecord::Base
belongs_to :emailable, :polymorhpic => true
validates_presence_of :address
validates_format_of :address, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
attr_accessible :address, :location
end