133c21b801
Update to Rails 2.3.1. (Actually, not quite. Doesn't look like 2.3.1 will be released today, but I REALLY want to push these bugfixes out.) Removed bundled Rack (Rails 2.3.1 comes bundled with Rack 1.0). Add config.action_view.cache_template_loading = true to production environment. Fix FastCGI bug (http://rubyforge.org/tracker/index.php?func=detail&aid=24191&group_id=186&atid=783). Fix WikiWords bug (http://rubyforge.org/pipermail/instiki-users/2009-February/001181.html).
49 lines
1.2 KiB
Ruby
49 lines
1.2 KiB
Ruby
require 'cases/helper'
|
|
require 'models/post'
|
|
|
|
class EachTest < ActiveRecord::TestCase
|
|
fixtures :posts
|
|
|
|
def setup
|
|
@posts = Post.all(:order => "id asc")
|
|
@total = Post.count
|
|
end
|
|
|
|
def test_each_should_excecute_one_query_per_batch
|
|
assert_queries(Post.count + 1) do
|
|
Post.each(:batch_size => 1) do |post|
|
|
assert_kind_of Post, post
|
|
end
|
|
end
|
|
end
|
|
|
|
def test_each_should_raise_if_the_order_is_set
|
|
assert_raise(RuntimeError) do
|
|
Post.each(:order => "title") { |post| post }
|
|
end
|
|
end
|
|
|
|
def test_each_should_raise_if_the_limit_is_set
|
|
assert_raise(RuntimeError) do
|
|
Post.each(:limit => 1) { |post| post }
|
|
end
|
|
end
|
|
|
|
def test_find_in_batches_should_return_batches
|
|
assert_queries(Post.count + 1) do
|
|
Post.find_in_batches(:batch_size => 1) do |batch|
|
|
assert_kind_of Array, batch
|
|
assert_kind_of Post, batch.first
|
|
end
|
|
end
|
|
end
|
|
|
|
def test_find_in_batches_should_start_from_the_start_option
|
|
assert_queries(Post.count) do
|
|
Post.find_in_batches(:batch_size => 1, :start => 2) do |batch|
|
|
assert_kind_of Array, batch
|
|
assert_kind_of Post, batch.first
|
|
end
|
|
end
|
|
end
|
|
end |