Skip to content

Instantly share code, notes, and snippets.

@diago
diago / env.rb
Created April 5, 2011 13:37
Padrino Cucumber Config
PADRINO_ENV = 'test' unless defined?(PADRINO_ENV)
require 'rubygems'
require 'spork'
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
@diago
diago / capybara cheat sheet
Created April 5, 2011 14:42 — forked from zhengjia/capybara cheat sheet
Capybara Cheatsheet
=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_or_button('Link Text') # Click either a link or a button
click('Button Value')
class AcceptableQuantityValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if value.nil?
order = Order.find(record[:order_id])
currently_fulfilled = order.total_fulfilled
if record.new_record?
valid_fulfillment = order.quantity - currently_fulfilled
else
valid_fulfillment = order.quantity - (currently_fulfilled - record.quantity_was)
@diago
diago / dm-transactional_fixtures.rb
Created July 6, 2011 13:02
DataMapper Transactional Fixtures
# Transactional Fixtures Fix for DataMapper
#
# This prevents pooling limiting the db to one connection
# and allowing transactions to exist between different threads
# rack_test to selenium for example
module DataObjects
module Pooling
class Pool
alias orig_new new
def new
@diago
diago / ic.rb
Created July 29, 2011 09:58
Includes without the clobbering
class PadrinoHelpers
require 'padrino-helpers'
include Padrino::Helpers::AssetTagHelpers
include Padrino::Helpers::TagHelpers
include Padrino::Helpers::OutputHelpers
end
# Foo had a #render method defined that was getting
# clobbered by OutputHelpers
class Foo
it 'should not allow adding apps that the site does not have' do
site = Site.gen # made while @user = User.gen
app1 = App.gen
app2 = App.gen
app3 = App.gen
site.apps << app1
site.apps << app2
site.save
dojo.provide( 'outland.store.JsonRestTreeModel' );
dojo.require( 'dojo.store.JsonRest' );
dojo.declare
( 'outland.store.JsonRestTreeModel'
, [ dojo.store.JsonRest ]
, { idProperty : 'id'
# Instance Methods for ControlPanel::Resources
module ResourceInstanceMethods
def initialize( slug_params = {} )
@slug_params = slug_params
end
def slug
# TMP just for figuring out
post = post.collect do |k,v|
"%s=%s" % [k,v]
end.join('&')
# Converts a hash into a query string
#
# Hash keys can be underscored names
# @example
# { :service_type => 'rsemail' }
#
# Or the Rackspace API expected string
#
# @param [Hash, #to_hash] hash to convert
# @return [String] query param