Skip to content

Instantly share code, notes, and snippets.

@afcapel
afcapel / assets.rake
Last active August 29, 2015 14:01
rake assets:precompile_if_needed
# lib/tasks/assets.rake
namespace :assets do
task :precompile_if_needed do
require_relative '../assets_version'
next unless AssetsVersion.needs_precompile?
Rake::Task["assets:precompile"].invoke
AssetsVersion.current.save_to_yaml
end
@mislav
mislav / Gemfile.rb
Created February 22, 2010 20:54
Bundler setup for Rails 2.3.x apps
## example Gemfile
source :rubygems
group :rails do
gem 'rake', '< 0.9', :require => nil
gem 'rails', '~> 2.3.5', :require => nil
gem 'builder', '~> 2.1.2'
gem 'memcache-client', '>= 1.7.4', :require => nil
gem 'tzinfo', '~> 0.3.12'
gem 'i18n', '>= 0.1.3'
@jdhollis
jdhollis / resque_async_handling.rb
Created June 9, 2010 21:43
handle_asynchronously for Resque
module Resque
module AsyncHandling
# To disable (in config.after_initialize):
# Resque::AsyncHandling.enabled = false
mattr_accessor :enabled
self.enabled = true
def handle_asynchronously(original_method, params = { })
if enabled
now_method = "#{ original_method }_now"
# Copy this to features/support/ssl_fix.rb to make Capybara work with sites that switch between HTTP and HTTPS
module Capybara::Driver::RackTest::SslFix
[:get, :post, :put, :delete].each do |method|
define_method method do |*args|
args[0] = path_to_ssl_aware_url(args[0])
super(*args)
end
end
# Rails developers have long had bad experiences with fixtures for
# several reasons, including misuse.
#
# Misuse of fixtures is characterized by having a huge number of them,
# requiring the developer to maintain a lot of data and creating dependencies
# between tests. In my experience working (and rescuing) many applications, 80%
# of fixtures are only used by 20% of tests.
#
# An example of such tests is one assuring that a given SQL query with
# GROUP BY and ORDER BY conditions returns the correct result set. As expected,
@pairing
pairing / active_model_lint.rb
Created October 21, 2010 19:03
RSpec ActiveModel Lint shared example
# adapted from rspec-rails http://github.com/rspec/rspec-rails/blob/master/spec/rspec/rails/mocks/mock_model_spec.rb
shared_examples_for "ActiveModel" do
require 'test/unit/assertions'
require 'active_model/lint'
include Test::Unit::Assertions
include ActiveModel::Lint::Tests
# to_s is to support ruby-1.9
ActiveModel::Lint::Tests.public_instance_methods.map{|m| m.to_s}.grep(/^test/).each do |m|
@dchelimsky
dchelimsky / gist:669112
Created November 9, 2010 14:07
swinger_without_rspec_monkey_patch.rb
RSpec.configure do |c|
c.around do |example|
Capybara.using_driver(example.metadata[:driver], &example)
end
end
module Capybara
def self.using_driver(driver)
Capybara.current_driver = driver
yield
RSpec.configure do |config|
# RSpec automatically cleans stuff out of backtraces;
# sometimes this is annoying when trying to debug something e.g. a gem
config.backtrace_clean_patterns = [
/\/lib\d*\/ruby\//,
/bin\//,
/gems/,
/spec\/spec_helper\.rb/,
/lib\/rspec\/(core|expectations|matchers|mocks)/
]
@paneq
paneq / capc.rb
Created January 27, 2011 18:50
Creating an object with Capybara api and jumping into it.
#!/usr/bin/env ruby
require 'bundler'
Bundler.setup(:default, :test) if defined?(Bundler)
require "selenium-webdriver"
require 'capybara/dsl'
Capybara.default_driver = :selenium
Capybara.default_selector = :css
Capybara.default_wait_time = 5
@javier
javier / gist:827358
Created February 15, 2011 10:21
kaminari ultrasphinx
#kaminari uses different method names than will:paginate, but with a small add-on
#we can use it for paginating thinking sphinx results
ThinkingSphinx::Search.class_eval do
def num_pages
total_pages
end
def limit_value
per_page
end