Skip to content

Instantly share code, notes, and snippets.

View damncabbage's full-sized avatar
🙅‍♀️
permanent omnishambles

Robin Howard damncabbage

🙅‍♀️
permanent omnishambles
View GitHub Profile
@damncabbage
damncabbage / account.rb
Created November 24, 2011 00:41
RSpec, yo.
# Dummy models that look and act like the real thing.
FactoryGirl.define do
# Basic account
factory :account do
password { "testtest" }.ignore
first_name { Faker::Name.first_name }
last_name { Faker::Name.last_name }
email { Faker::Internet.email }
@damncabbage
damncabbage / crud_helper.rb
Created December 9, 2011 05:29
Helpers and ERB
module CrudHelper
def buttons(content=nil)
content ||= yield if block_given?
content_tag(:ul, content)
end
def button(text, url)
content_tag(:li, :class => "button") do
link_to text, url, options
@damncabbage
damncabbage / gist:1470270
Last active January 19, 2019 05:31
Quick & Dirty: unbreak delicious.html bookmarks files with stuck-together tags.
# WARNING WARNING WARNING WARNING WARNING WARNING
#
# This is only useful if you have tags that DON'T INCLUDE SPACES.
#
# If you have tags in your http://delicious.com/<yourusername> list that
# include spaces (such as "underwater basket weaving"), then this is NOT
# for you.
#
# If you just have tags like "underwater-basket-weaving", then this'll work fine.
#
@damncabbage
damncabbage / gist:1499613
Created December 20, 2011 00:35
Sample before()-centric spec.
require 'spec_helper'
describe "FAQs" do
let(:account) { Factory(:account, :password => "password") }
before(:each) { sign_in account, "password" }
context "when creating a FAQ" do
let(:faq) { FactoryGirl.build(:faq) }
before(:each) do
require 'spec_helper'
describe "Articles" do
let(:account) { Factory(:account, :password => "password") }
let(:business) { account.businesses.first }
let(:index_path) { polymorphic_url([business, Article]) }
before(:each) { sign_in(account, "password") } # Everything needs authentication.
context "when creating an Article" do
@damncabbage
damncabbage / payment_methods_spec.rb
Created January 5, 2012 06:28
Confusing Spec Error
require 'spec_helper'
describe "Payment Methods" do
let(:account) { Factory(:account, :password => "password") }
let(:business) { account.businesses.first }
before(:each) { sign_in(account, "password") } # Everything needs authentication.
context "when editing a Business' Payment Methods" do
let!(:subject) { Factory(:payment_method, :business => business) }
$ be rake spec:models --trace
** Invoke spec:models (first_time)
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
@damncabbage
damncabbage / Gemfile
Created January 16, 2012 05:36
Ruby Debugger with Ruby 1.9.3 / Rails 3.1
gem 'linecache19', :git => 'git://github.com/mark-moseley/linecache'
gem 'ruby-debug-base19x', '~> 0.11.30.pre4'
gem 'ruby-debug19'
@damncabbage
damncabbage / gist:1682806
Created January 26, 2012 13:37
DocumentUp Bookmarklet
javascript:var m = document.location.href.match(new RegExp('(?:(?:www\.)?github.com)/([^/?%]+/[^/?%]+)','i')); if(!!m[1]) { var repo = m[1]; document.write('<!doctype html><title>'+repo+' | DocumentUp</title><script src="https://cdnjs.cloudflare.com/ajax/libs/documentup/latest.min.js"></script><script>DocumentUp.document("'+repo+'");</script>'); } else { alert("This is not a GitHub repo!"); }
@damncabbage
damncabbage / region.rb
Created January 26, 2012 23:46
Retrieving non-AR columns with an AR query
class Region < ActiveRecord::Base
acts_as_nested_set :left_column => 'left', :right_column => 'right'
attr_accessible :parent_id, :postcode, :name, :region_type
attr_accessor :area
def self.suburb_search(terms, options={})
options = {
:limit => 20