This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)/ | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
OlderNewer