Skip to content

Instantly share code, notes, and snippets.

View gsmendoza's full-sized avatar

George Mendoza gsmendoza

View GitHub Profile
ActionController::Routing::Routes.routes.collect{|r| r.requirements}.uniq
class GenericMailer < ActionMailer::Base
def email(object, template_name, options = {})
@from = options[:from] || 'default@email.com'
@from = @from.respond_to?(:email) ? @from.email : @from
@recipients = options[:recipients] || options[:to]
@recipients = @recipients.collect{|item| item.respond_to?(:email) ? item.email : item}.sort if @recipients.is_a? Array
@subject = "[App Name] " + (options[:subject] || I18n.t(template_name.to_s))
@gsmendoza
gsmendoza / gist:174494
Created August 25, 2009 05:23
Poor man's micronaut
def todo_describe(object, &block)
describe object do
it "is pending"
end
end
def todo_it(string, &block)
it string
end
@gsmendoza
gsmendoza / Leo Kottke - Standing on the Outside
Created October 24, 2010 05:44
This is a simplified version of Eric Lugosch's interpretation of the song, which you can find at http://www.youtube.com/watch?v=DIlFKw0oxUs.
Intro
E-|---------------------------------|-10--12--14------12--10----------|---------------------0-----------|-------------0---2-------0-------|-
B-|---------------------------------|-10----------------------10------|---------0-----------------------|---------3-------------------3---|-
G-|---------------------------------|-11------------------------------|---------0---6-------------------|---------2-----------------------|-
D-|---------------------------------|---------------------------------|-----0-------7-----------0-------|-----0---------------0-----------|-
A-|---------------------------------|---------------------------------|-------------7-------------------|---------------------------------|-
D-|---------------------------------|---------------------------------|-3s5-------------0---------------|-0-------------------------------|-
@gsmendoza
gsmendoza / Rakefile
Created March 1, 2011 03:08
Rakefile
# require 'rake'
require 'bundler'
Bundler::GemHelper.install_tasks
dir = File.dirname(File.expand_path(__FILE__))
# $LOAD_PATH.unshift dir + '/lib/fcg-service-servers'
require 'lib/fcg-service-servers/version'
require 'rspec/core/rake_task'
Feature: Google Apps authentication
As a user I want to be able to register baweb account using my google account.
@selenium
Scenario: An customer creates account using GoogleID # features/307_google_apps_authentication.feature:5
Given I am anonymous # features/step_definitions/user_steps.rb:1
When I go to the signup page # features/step_definitions/web_steps.rb:23
And I follow "Sign up with your Google Apps Account" # features/step_definitions/web_steps.rb:33
And I fill in "Google Apps Domain:" with "gmail.com" # features/step_definitions/web_steps.rb:39
WARNING: making https request to https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=llya694le36z&scc=1&ltmpl=default&ltmplcache=2 without verifying server certificate; no CA path was specified.
@gsmendoza
gsmendoza / gist:1292230
Created October 17, 2011 08:57
RestClient request when putting a page to unfuddle's notebooks
#<RestClient::Request:0xb72c53a0
@args=
{:password=>"********",
:method=>:put,
:payload=>
{:page=>
{:message=>"Minor fixes",
:title=>"title",
:body=>
"body"}},
@gsmendoza
gsmendoza / 2012-08-24-isolated-cucumber-tests-with-local-steps.markdown
Created August 8, 2012 06:16
A workaround for isolated tests with local steps in Cucumber

A workaround for isolated tests with local steps in Cucumber

I've always wanted to write tests using Spinach. Unlike Cucumber, steps in Spinach are local to the feature they are defined. Therefore, they do not conflict with step definitions in other features.

However, we're using Cucumber in our project. The Cucumber way doesn't allow steps local to a scenario. In fact, it even considers it an anti-pattern.

Last week though, I had an idea: why not stamp each step with a scenario ID so that the step is local to the scenario? Using the spinach example, I ended with something like this:

features/1_greetings.feature

PageObject + SimpleDelegator = Awesome Capybara Helpers

I've always liked using the Page Object pattern to write concise, namespaced, and composeable capybara helpers:

When /^I register as a new user$/ do
  NewUserPage.new(self).tap do |page|
    page.visit!
    page.form.fill

page.form.submit!

@gsmendoza
gsmendoza / pre-commit
Created October 5, 2013 07:13
Git pre-commit hook for image optimization.
#!/usr/bin/env ruby
require 'image_optim'
staged_files = `git diff --cached --name-only --diff-filter=ACM`.split("\n")
staged_files.select! { |f| f =~ %r{/images/} }
if staged_files.any?
image_optim = ImageOptim.new(pngout: false)