Skip to content

Instantly share code, notes, and snippets.

$ time rake test:parallel
(in /Users/jasonmorrison/dev/myapp/trunk)
2 processes for 49 tests, ~ 24 tests per process
Loaded suite -e
Started
.................................. (abbreviated)
29.32s user 3.31s system 143% cpu 22.669 total
$ time rake test:units test:functionals
Started
.......... (abbreviated... FOR BLOG READING SPEED!!)
415 tests, 898 assertions, 0 failures, 0 errors
29.14s user 3.74s system 87% cpu 37.614 total
$ script/plugin install git://github.com/jasonm/parallel_specs.git
$ rake db:structure:dump
$ echo "create database myapp_test2;" | mysql -uroot
$ mysql -uroot -Dmyapp_test2 < db/development_structure.sql
$ vim config/database.yml # add some ERB to config/database.yml
test:
adapter: mysql
encoding: utf8
database: myapp_test<%= ENV['TEST_ENV_NUMBER'] %>
username: root
$ time rake test:parallel
(in /Users/jasonmorrison/dev/myapp/trunk)
2 processes for 49 tests, ~ 24 tests per process
Loaded suite -e
Started
.................................. (abbreviated)
29.32s user 3.31s system 143% cpu 22.669 total
posts = Post.find do
user.email =~ "%thoughtbot%"
tags.name === %w( ruby rails )
created_on <=> [ 2.weeks.ago, 1.week.ago ]
end
query = User.find do
company.name = cname?
order_by created_on
end
users = query.find(:cname => "thoughtbot")
</code></pre>
Now, what's tricky is that you could pass any syntax-changing value to that and you'd get the right SQL in the executed query.
<filter:code lang="ruby">
query.find :cname => "thoughtbot" # => company.name = "thoughtbot"
query.find :cname => nil # => company.name IS NULL
query.find :cname => ["Google", "37 Signals"] # => company.name IN ("Google", "37 Signals")
class Person < ActiveRecord::Base
has_one :address, :as => :addressable
end
class Company < ActiveRecord::Base
has_one :address, :as => :addressable
class Address < ActiveRecord::Base
belongs_to :person
belongs_to :company
end