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
Dir[File.dirname(__FILE__) + '/factories/*.rb'].each { |file| require file } | |
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 AVCacheTTL | |
def self.included(base) | |
base.alias_method_chain :cache, :ttl | |
end | |
def cache_with_ttl(name = {}, options = nil, &block) | |
options = (options || {}).dup | |
return block.call if options.delete(:ignore_cache) | |
time = options.delete(:ttl) | |
time = time.from_now if time.respond_to?(:from_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
#!/usr/bin/env ruby | |
if ARGV.any? {|arg| %w[--drb -X --generate-options -G --help -h --version -v].include?(arg)} | |
require 'rubygems' unless ENV['NO_RUBYGEMS'] | |
else | |
ENV["RAILS_ENV"] ||= 'test' | |
require File.expand_path(File.dirname(__FILE__) + "/../config/environment") unless defined?(RAILS_ROOT) | |
end | |
start_time = Time.now | |
puts "Starting MongoDB Benchmark..." | |
100000.times do |n| |
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 | |
ENV["RAILS_ENV"] ||= 'test' | |
require File.expand_path(File.dirname(__FILE__) + "/../config/environment") unless defined?(RAILS_ROOT) | |
start_time = Time.now | |
puts "Starting CouchDB Benchmark..." | |
100000.times do |n| | |
Person.new(:first_name => "Couch_#{n}", :last_name => "Man_#{n}").save | |
end | |
puts (Time.now - start_time) |
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
class Hash | |
def intersection_equal?(other) | |
all? {|k, v| other.has_key?(k) ? other[k] == v : true } | |
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
# require 'webrat_ext' | |
module Webrat | |
module Methods | |
delegate_to_session :current_path | |
end | |
class Session | |
def current_path | |
URI.parse(current_url).path | |
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
# Ryan, the hits in the db approach is flawed (not currently atomic, and | |
# probably not really performant for high rates) -- but you knew that. | |
# So in the spirit of gets it done, I have followed along. | |
# | |
# API Example | |
## User Model | |
require 'digest/md5' | |
class User < ActiveRecord::Base | |
API_RATE_LIMIT_WINDOW = 2.minutes |
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
def javascript_confirm(answer) | |
page.evaluate_script 'window._confirm = window.confirm' | |
page.evaluate_script "window.confirm = function(x) { return #{answer} }" | |
yield | |
page.evaluate_script 'window._confirm && (window.confirm = window._confirm)' | |
page.evaluate_script 'window._confirm = null' | |
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
class Array | |
def method_missing(method, *args, &block) | |
if key_value = dynamic_mapper?(method) | |
map_dynamically(key_value[1], key_value[2]) | |
else | |
super | |
end | |
end | |
def dynamic_mapper?(method) |
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
# place in features/support | |
require 'ephemeral_response' | |
EphemeralResponse.configure do |config| | |
config.expiration = lambda { one_day * 30 } | |
config.white_list = ['localhost', '127.0.0.1'] | |
config.register('api.twitter.com') do |request| | |
if oauth_token_match = request['authorization'].match(/oauth_token=\"\d+-\w+"/) | |
"#{request.uri.to_s}#{request.method}#{oauth_token_match[0]}" | |
else |
OlderNewer