Skip to content

Instantly share code, notes, and snippets.

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
@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
@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
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 / 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')
@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 / spec_helper.rb
Created April 5, 2011 13:36
Padrino Rspec 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.
require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
@diago
diago / Gemfile
Created April 5, 2011 13:31
Padrino Gemfile
source :rubygems
# Project requirements
gem 'rake'
gem 'rack-flash'
gem 'thin' # or mongrel
# Component requirements
gem 'bcrypt-ruby', :require => "bcrypt"
gem 'compass'
@diago
diago / ajax-extend.js
Created December 7, 2010 14:27
Extending Jquery functions
// jQuery Extended
var $ajax = $.ajax;
$.ajax = function(options){
var options = $.extend({cache: false}, options || {});
return $ajax(options);
}
var dispatch = {
events: {},
observe: function(action){
this.events[action] = {};
document.observe(action, function(ev){
for(var x in dispatch.events[action]){
if(ev.findElement(x)) return dispatch.events[action][x](ev);
}
});