Skip to content

Instantly share code, notes, and snippets.

View moretea's full-sized avatar

Maarten Hoogendoorn moretea

View GitHub Profile
web: bundle exec unicorn_rails -c config/environments/unicorn-development.rb
worker: bundle exec rake jobs:work
sphinx: bundle exec rake ts:run_in_foreground
namespace :ts do
# Workaround to make Sphinx run in the foreground
task :run_in_foreground => [ 'ts:conf', 'ts:in' ] do
ts = ThinkingSphinx::Configuration.instance
$kill_sphinx_on_exit = false
unless pid = fork
exec "#{ts.bin_path}#{ts.searchd_binary_name} --pidfile --config #{ts.config_file} --nodetach"
end
@moretea
moretea / gist:1279763
Created October 11, 2011 23:14
~/bin/spec_and_remind_me
bundle exec spec $*
playsound --volume 2.0 ~/specs_finished.wav
# Use this to stub sphinx like this:
# Product.stub(:search).and_return(MockSphinx::ProductStubber.new(products))
module MockSphinx
class ProductStubber
def initialize products
@products = products
end
# Swallow all following scope calls
def method_missing name, *args, &block
@products = Product.search(params[:q], :page => paginate_page, :per_page => paginate_per_page).
without_hidden_members.
using_sort_mode(params[:sort]).
with_sphinx_state(:published)
feature "Image failures" do
background do
@category = Category.make
@product_ok = Product.make(:category => @category)
ensure_test_s3_files!
@product_not_ok = Product.make(:category => @category)
Product.stub(:search).and_return(MockSphinx::ProductStubber.new(Product.all))
end
require "guard/guard"
module ::Guard
class Precompile < ::Guard::Guard
def run_on_change(path)
puts "Precompiling assets for test env ...."
puts `bundle exec rake assets:precompile RAILS_ENV=test`
end
end
end
# Require the custom guard
require "./lib/guard/precompile"
guard 'spork', :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
# routes.rb
TestApp::Application.routes.draw do
resources :logins
resource :session
resources :accounts do
resources :things
end
end
# routes.rb is the same
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
include ApplicationHelper # Force it to be present in all controllers
before_filter :find_login_and_account
end
# app/helpers/application_helper.rb
module ApplicationHelper