Skip to content

Instantly share code, notes, and snippets.

View mikegehard's full-sized avatar

Mike Gehard mikegehard

  • Chattanooga, TN
  • 02:21 (UTC -04:00)
View GitHub Profile
@mikegehard
mikegehard / code.scala
Created December 15, 2012 20:17
Problems with JSON API tests in Play2
object BetaInvitationRequestController extends Controller {
val successResponse = Map("success" -> true)
val betaInvitationRequestMapping = Forms.mapping(
"email" -> Forms.email
)(BetaInvitationRequest.apply)(BetaInvitationRequest.unapply)
val betaInvitationRequestForm = Form(betaInvitationRequestMapping)
def create = Action {
@mikegehard
mikegehard / sketch.rb
Created July 5, 2012 00:02 — forked from mattwynne/sketch.rb
Responders implemented using a block instead of another class
class Organization
def to_param
"42"
end
def saved?
rand > 0.5
end
end
@mikegehard
mikegehard / config.ru
Created March 5, 2012 20:05
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
# Run this file with `RAILS_ENV=production rackup -p 3000 -s thin`
# Be sure to have rails and thin installed.
require "rubygems"
# We are not loading Active Record, nor the Assets Pipeline, etc.
# This could also be in your Gemfile.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
# The following lines should come as no surprise. Except by
@mikegehard
mikegehard / gist:983110
Created May 20, 2011 15:08
Javascript Pattern for Namespacing javascript
// This is a good pattern to namespace javascript.
// Passing in jQuery assures that $ in our functions always refers to jquery
// Also a good pattern to pass in event to handers as that is the default for jQuery
// in a handler the "this" refers to the DOM element that caused the element.
window.Hello = {};
(function($, namespace){
namespace.Bar = {};
// Use jQuery to add your methods.
$.extend(namespace.Bar, {
@mikegehard
mikegehard / 0_README.md
Created May 5, 2011 02:39 — forked from netzpirat/0_README.md
Continuous CoffeeScript testing with Guard and Jasmine

Continuous CoffeeScript testing with Guard and Jasmine

This Gist shows how to set up a Rails project to practice BDD with CoffeeScript, Guard and Jasmine. You can see this setup in action on Vimeo

  • Install Gems with Bundler with bundle install
  • Define your guards with mate Guardfile
  • Initialize Jasmine with bundle exec jasmine init
  • Configure Jasmine with mate spec/support/yasmine.ym
  • Start Guard with bundle exec guard
@mikegehard
mikegehard / gist:954537
Created May 4, 2011 00:35
Waiting until all jquery ajax calls are done
//Useful if you have a slow CI server...
When /^I wait until all Ajax requests are complete$/ do
wait_until do
page.evaluate_script('$.active') == 0
end
end
@mikegehard
mikegehard / gist:935825
Created April 22, 2011 01:13
Mocking fog for use with carrierwave
# drop this into a file in spec/support or feature/support and you should be all set.
unless Kernel.const_defined?("S3_CONFIG")
S3_CONFIG = YAML.load_file("#{Rails.root}/config/s3.yml")[Rails.env].try(:symbolize_keys)
end
Fog.mock!
connection = ::Fog::Storage.new(
:aws_access_key_id => S3_CONFIG[:access_key_id],
@mikegehard
mikegehard / Setting longer HTTP timeout in capybara
Created April 15, 2011 19:20
Setting longer HTTP timeout in capybara
# We need this to fix the random timeout error that we were seeing in CI.
# May be related to: http://code.google.com/p/selenium/issues/detail?id=1439
Capybara.register_driver :selenium_with_long_timeout do |app|
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 120
Capybara::Driver::Selenium.new(app, :browser => :firefox, :http_client => client)
end
Capybara.javascript_driver = :selenium_with_long_timeout
@mikegehard
mikegehard / active_model_lint.rb
Created April 8, 2011 21:26 — forked from pairing/active_model_lint.rb
RSpec shared examples for ActiveModel::Lint
# adapted from rspec-rails http://github.com/rspec/rspec-rails/blob/master/spec/rspec/rails/mocks/mock_model_spec.rb
# put this in a file in your spec/support directory
# USAGE:
#
# let(:model) { ModelUnderTest.new(params) }
# it_behaves_like "ActiveModel"
shared_examples_for "ActiveModel" do
require 'test/unit/assertions'
require 'active_model/lint'
@mikegehard
mikegehard / gist:853253
Created March 3, 2011 18:41
Testing OmniAuth login via cucumber...
Before('@omniauth_test') do
OmniAuth.config.test_mode = true
# the symbol passed to mock_auth is the same as the name of the provider set up in the initializer
OmniAuth.config.mock_auth[:google] = {
"provider"=>"google",
"uid"=>"http://xxxx.com/openid?id=118181138998978630963",
"user_info"=>{"email"=>"test@xxxx.com", "first_name"=>"Test", "last_name"=>"User", "name"=>"Test User"}
}
end