Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

module Publisher
def self.included(base)
base.instance_eval do
def republish(*messages)
messages.each do |message|
define_method(message) do |args|
publish(message, *args)
end
end
end
// The query that (in the Sense console) produced the contents of results.js
// GET planner_development/_search?search_type=count
{
"query": {
"terms": {
"tag_ngrams": [
"fo"
]
}
@gma
gma / gist:3b24e28bde2dfe3c2d02
Last active August 29, 2015 14:19
Commit message for email delivery race condition fix

When running code in a thread ActiveRecord uses a separate database connection, which can't see the results of any queries run by the main thread until they're committed. But Rails doesn't commit transactions in the test environment, making this difficult to test.

The fix for this was in two parts, either of which should be enough to solve the problem on their own.

  1. Load the ActiveRecord objects before entering the thread, as the database connection that we'll be using inside the thread may not be able to access the (freshly created) database records yet.

  2. Commit the transaction that wraps the creation of the database records before publishing the :message_created message (that triggers the thread to run). This ought to mean that code with a separate database connection will be able to load the subscribers anyway.

module SpecHelper
def session_data
cookies = @response.headers["Set-Cookie"]
serialised = Rack::Utils::parse_query(cookies)["rack.session"]
Marshal.load(serialised.unpack('m*').first)
end
end
poncho (sinatra-09)% ruby spec/sitemap_spec.rb -e 'should have a urlset tag'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31: warning: The :env option is deprecated; use :environment instead.
F
1)
ArgumentError in 'sitemap XML should have a urlset tag'
tried to create Proc object without a block
/Library/Ruby/Gems/1.8/gems/sinatra-0.9.0.2/lib/sinatra/base.rb:589:in `define_method'
/Library/Ruby/Gems/1.8/gems/sinatra-0.9.0.2/lib/sinatra/base.rb:589:in `route'
/Library/Ruby/Gems/1.8/gems/sinatra-0.9.0.2/lib/sinatra/base.rb:569:in `get'
# This isn't as elegant as some of the other solutions for running multiple versions
# of Ruby but it's simple, straight-forward and has worked well for me so far. I'm
# currently running the most recent stable versions of 1.8.5, 1.8.6, 1.8.7, and
# 1.9.1 and plan to experiment with some patched versions as well.
# pull one of the tarballs down and extract:
$ cd /tmp
$ curl ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.1-p0.tar.gz |
tar xvzf -
$ cd ruby-1.9.1-p0
class Show < ActiveRecord::Base
has_many :episodes
has_many :users, :through => :episodes
end
class User < ActiveRecord::Base
has_many :episodes
has_many :shows, :through => :episodes
end
module RequireBodyCopyMacros
def should_require_body_copy
context "create" do
should_display_error_if_body_not_set :post_create
end
context "update" do
should_display_error_if_body_not_set :put_update
end
@gma
gma / gist:234446
Created November 14, 2009 08:43 — forked from jc00ke/gist:234265
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
module UserSpecHelper
def valid_user_attributes
{ :username => 'jc00ke',
:email => 'jc00ke@example.com',
:password => 'p@ssw0rd' }
end
def invalid_usernames
module ActionController
module Assertions
module SelectorAssertions
protected
def response_from_page_or_rjs
HTML::Document.new(body, strict = false, xml = false).root
end
end
end
end