Skip to content

Instantly share code, notes, and snippets.

View seth-macpherson's full-sized avatar

Seth MacPherson seth-macpherson

  • Appfolio
  • Hood River, OR
View GitHub Profile
@seth-macpherson
seth-macpherson / mobilehtml5.haml
Created October 14, 2011 06:18 — forked from minikomi/mobilehtml5.haml
mobile html5 boilerplate haml
<!doctype html>
/[if IEMobile 7 ] <html class="no-js iem7">
/ [if (gt IEMobile 7)|!(IEMobile)]><!
%html.no-js
/ <![endif]
%head
%meta{:charset => "utf-8"}
%title
%meta{:content => "", :name => "description"}
%meta{:content => "", :name => "author"}
@seth-macpherson
seth-macpherson / gist:2473961
Created April 23, 2012 21:24 — forked from scottburton11/gist:1479734
Ember.js tree
<html>
<head>
<script src="javascripts/jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="javascripts/ember.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
App = Ember.Application.extend();
App.Node = Ember.Object.extend({
name: null,
@seth-macpherson
seth-macpherson / rspec-syntax-cheat-sheet.rb
Created April 29, 2012 15:47 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
@seth-macpherson
seth-macpherson / gist:2709681
Created May 16, 2012 11:30 — forked from punund/gist:1034276
Proper exception handling in Rails 3
# coding: utf-8
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from Exception, :with => :handle_exceptions
private
def handle_exceptions(e)
case e
when CanCan::AccessDenied
@seth-macpherson
seth-macpherson / upgrade_homebrew_pg.sh
Created May 30, 2012 06:36 — forked from johnpaulashenfelter/upgrade_homebrew_pg.sh
Upgrading homebrew postgres from 9.0.x to 9.1
Upgrading to homebrew postgresql 9.1.1 from 9.0.x
* Copy the old data
mv -R /usr/local/var/postgres/ /usr/local/var/postgres-901
* Create a new database using 9.1.1
/usr/local/Cellar/postgresql/9.1.1/bin/initdb /usr/local/var/postgres
@seth-macpherson
seth-macpherson / example_admin_test.rb
Created September 13, 2012 23:49
Example Integration Test
require './test/selenium_test_helper'
class ExampleAdminTest < ActionController::IntegrationTest
# assemble basic test data via FactoryGirl, etc...
setup :prep_test_data, :visit_admin
test 'basic application operations' do
click_link "Show Archived Positions"
assert page.has_content?("Wooden Widget Maker")
@seth-macpherson
seth-macpherson / easy.rb
Created September 14, 2012 19:11
Capybara is easy when you've got ID's to reference
page.find('#applicant_viewer .notes-tab').click
@seth-macpherson
seth-macpherson / capybara_irb.rb
Created September 14, 2012 20:54
Interactive Capybara Instance
# Setup all the main constructs of a selenium/capybara instance
ENV["RAILS_ENV"] = "test"
require "#{Rails.root}/config/environment"
require 'rails/test_help'
require "capybara/rails"
require 'database_cleaner'
require 'capybara/dsl'
require 'factory_girl_rails'
require 'active_support/all'
require 'active_support/test_case'
@seth-macpherson
seth-macpherson / load_capybara.sh
Created September 14, 2012 21:01
Load Rails Console in TEST mode then load the capybara_irb.rb file
$ RAILS_ENV=test rails console
Loading test environment (Rails 3.2.8)
1.9.3p125 :001 > load 'test/capybara_irb.rb'
1.9.3p125 :002 > prep_test_data # this is typically run by my tests as setup :prep_test_data...
################################################################
Factory Girl pumps out all my required models to get rolling...
################################################################
1.9.3p125 :205 > visit '/admin' # this opens Firefox via the Selenium WebDriver
1.9.3p125 :206 > find('.x-some .y-selector').click # --> returns true if element is found, plus you can *see* happen