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
# Dynamically create a subclass in rails. | |
def create_subclass(class_name, subclass=nil) | |
name = class_name.to_s.camelize | |
Object.const_set(name, Class.new(CryptedAttribute)) | |
end | |
create_subclass(:username, CryptedAttribute) | |
=> Username | |
Username.superclass |
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 Test::Unit::TestCase | |
private | |
def reload_activerecord_instances | |
self.instance_variables.each do |ivar| | |
if ivar.is_a?(ActiveRecord::Base) && ivar.respond_to?(:reload) | |
ivar.reload | |
end | |
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
context "A new group" do | |
setup do | |
@group = Factory(:group) | |
end | |
context "with an added entry" do | |
setup do | |
@entry = Factory(:entry, :title => "WEB", :group => @group) | |
@group.reload | |
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
validates_presence_if :description, :if => :should_validate_description? | |
validates_numericality_of :age, :if => :should_validate_age? |
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 SelectiveAttributeValidatable | |
def self.included(base) | |
base.send(:include, InstanceMethods) | |
base.class_eval do | |
alias_method_chain :update_attributes, :check | |
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
System: Macbook Pro, 2.4 GHz Intel Core 2 Duo, 3GB, OSX 10.6 | |
MongoDB 1.1.1 | |
Using mongo 0.15.1 | |
user system total real | |
init 0.000000 0.000000 0.000000 ( 0.001954) | |
create 28.930000 0.790000 29.720000 ( 32.836103) | |
query 0.130000 0.010000 0.140000 ( 0.182142) | |
delete 0.000000 0.000000 0.000000 ( 2.282025) |
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
Using MongoMapper 0.5.4 with mongo-0.15.1 and mongo_ext-0.15.1 | |
require 'rubygems' | |
require 'mongo_mapper' | |
MongoMapper.connection = Mongo::Connection.new('localhost', 27017) | |
MongoMapper.database = 'dupes' | |
class Doc | |
include MongoMapper::Document |
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
Using mongo-0.15.1 with mongo_ext-0.15.1 | |
require 'rubygems' | |
require 'mongo' | |
db = Mongo::Connection.new('localhost', 27017).db('stuff') | |
coll = db['stuff'] | |
coll.remove |
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
equire 'benchmark' | |
class String | |
def ending | |
length = self.length | |
self[length-2].chr + self[length-1].chr | |
end | |
def base | |
self[0..(self.length-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
Reducing batch size to 500 and using Benchmark with rehearsal (bmbm): | |
see http://github.com/mperham/docdb_shootout | |
MongoDB 1.1.1 | |
Using latest mongo 0.16 | |
user system total real | |
init 0.000000 0.000000 0.000000 ( 0.002115) | |
create 16.470000 0.760000 17.230000 ( 21.946121) | |
query 0.060000 0.000000 0.060000 ( 0.093965) | |
delete 0.000000 0.000000 0.000000 ( 2.927984) |
OlderNewer