Skip to content

Instantly share code, notes, and snippets.

# https://rails.lighthouseapp.com/projects/8994/tickets/4743-session-cookie-breaks-if-used-with-custom-cookie-in-rails-238
# http://gist.github.com/431811
if Rails.version == '2.3.8'
class RackRailsCookieHeaderHack
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
# https://rspec.lighthouseapp.com/projects/16211/tickets/305
require 'singleton'
module NegativeExpectationsHelper
class State
include Singleton
def is_negative?
@negative === true
Given %r`a guest(?: user)? named "([^\"]+)" for the "([^\"]+)" store$` do |login, uri|
store = Store.find_by_slug!(uri)
User.make(:guest, :login => login, :store => store)
end
Given %r`not logged in$` do
s = UserSession.destroy
end
Given %r`(?:log|am logged) in as "([^\"]+)"$` do |login|
gem 'ruby-debug', :group => [:test, :cucumber, :development]
gem 'email_spec', :group => [:test, :cucumber], :require => 'email_spec'
group :test do
gem 'rspec-rails', '>= 1.3.2'
end
group :cucumber do
gem 'cucumber-rails', '>=0.3.1'
gem 'database_cleaner', '>=0.5.0'
# an example of composition using value classes
class Person < ActiveRecord::Base
# "gender" (string) column will use Gender value class
# to represent it instead of string
composed_of :gender
end
ErrorDocument 503 /system/maintenance.html
RewriteCond %{REQUEST_URI} !.(css|gif|jpg|png)$
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ - [redirect=503,last]
<?php
$revcaptcha = md5($_SERVER['REMOTE_ADDR'] . 'random_salt');
function check_revcaptcha($key1, $key2, $revcaptcha) {
if ($_POST[$key1] == '' && $_POST[$key2] == $revcaptcha) {
unset( $_POST[$key1] );
unset( $_POST[$key2] );
return true;
} else {
return false;
# usage:
# field_labeled('Select your address').should have_option("Home Address")
Spec::Matchers.define :have_option do |expected|
def options_for(select_field)
select_field.options.map(&:inner_text)
end
match do |select_field|
raise "Field is not a SelectField" unless select_field.kind_of?(Webrat::SelectField)
options_for(select_field).include?(expected)
SELECT @old_domain:='stage.example.com';
SELECT @new_domain:='www.example.com';
UPDATE wp_postmeta SET
meta_value=REPLACE(meta_value, @old_domain, @new_domain);
UPDATE wp_posts SET
post_content=REPLACE(post_content, @old_domain, @new_domain),
post_excerpt=REPLACE(post_excerpt, @old_domain, @new_domain),
guid=REPLACE(guid, @old_domain, @new_domain);
# Use an instance for the top-level form_for
form_for @parent do |f|
# Always use a symbol to access the nested association from f.object
f.fields_for :child do |fc|
# generates: params[:parent][:child_attributes][:field]
end
# Optionally, provide an instance as a *second* argument
f.fields_for :relative, (@other_parent or Person.new) do |fr|