Skip to content

Instantly share code, notes, and snippets.

@voldy
voldy / gist:271377
Created January 7, 2010 17:15
Using Formtastic and JQuery DatePicker
##formtastic_datepicker_interface
module Formtastic
module DatePicker
protected
def datepicker_input(method, options = {})
format = options[:format] || ActiveSupport::CoreExtensions::Date::Conversions::DATE_FORMATS[:default] || '%d %b %Y'
string_input(method, datepicker_options(format, object.send(method)).merge(options))
end
@voldy
voldy / delayed_job
Created May 3, 2010 07:38 — forked from akmathur/delayed_job
script/delayed_job
#!/usr/bin/env ruby
# -*- ruby -*-
require 'rubygems'
require 'daemon-spawn'
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
class DelayedJobWorker < DaemonSpawn::Base
def start(args)
ENV['RAILS_ENV'] ||= args.first || 'development'
@voldy
voldy / deploy.rb
Created May 29, 2010 23:28 — forked from localshred/deploy.rb
Using bundler with capistrano
# ...
namespace :bundler do
task :create_symlink, :roles => :app do
shared_dir = File.join(shared_path, 'bundle')
release_dir = File.join(current_release, '.bundle')
run("mkdir -p #{shared_dir} && ln -s #{shared_dir} #{release_dir}")
end
task :bundle_new_release, :roles => :app do
@voldy
voldy / rakefile.rb
Created September 26, 2010 18:16
Sprockets Watch
#!/usr/bin/env ruby
#
# sprockets watch
# ------------------------------------------------------
# inspired by Compass from Chris Eppstein
# minify and concat code from Mark Story
# put together by Kjell Bublitz
# using Sprockets!
#
# sources:
user app;
worker_processes 2;
error_log /home/app/logs/nginx.error.log info;
events {
worker_connections 1024;
}
# Application Generator Template
# Devise, Cucumber, RSpec... for use with Rails 3
# http://gist.github.com/513564
# Based on the Mongoid/Devise template: http://github.com/fortuity/rails3-mongoid-devise/raw/master/template.rb
#
#
# Installs my js_lib rakefile, found: http://gist.github.com/raw/628715/js_lib.rake
# (to keep js libraries out of source control.)
#
# Usage:
@voldy
voldy / rspec-syntax-cheat-sheet.rb
Created November 27, 2010 16:03 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2.0 syntax Cheet Sheet
# 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")
@voldy
voldy / cookie_steps.rb
Created November 28, 2010 20:39 — forked from nruth/cookie_steps.rb
Testing login "remember me" feature with Capybara 1.0.0 (rack::test or selenium) - deleting the session cookie (only)
@voldy
voldy / cancan_mongoid.rb
Created December 17, 2010 16:35 — forked from bowsersenior/cancan_mongoid.rb
How to get CanCan to work with Mongoid 2
module CanCan
class Query
def sanitize_sql(conditions)
conditions
end
end
# customize to handle Mongoid queries in ability definitions conditions
class CanDefinition
def matches_conditions_hash?(subject, conditions = @conditions)
@voldy
voldy / mass_assigment.rb
Created December 18, 2010 21:21
Allow mass assignment RSpec matcher tested with Mongoid
# allow_mass_assignment_of matcher
# Extracted from Shoulda
# Works with Mongoid
module RSpec
module Matchers
# Ensures that the attribute can be set on mass update.
#
# it { should_not allow_mass_assignment_of(:password) }