Skip to content
Browse files

Fix test_find_in_batches_should_use_any_column_as_primary_key

  • Loading branch information...
1 parent 7be8809 commit 19fa8fa3c436ed5b25e7ed0005f128487a7d1f0b @spastorino spastorino committed Sep 22, 2012
Showing with 8 additions and 11 deletions.
  1. +8 −11 activerecord/test/cases/batches_test.rb
View
19 activerecord/test/cases/batches_test.rb
@@ -1,8 +1,9 @@
require 'cases/helper'
require 'models/post'
+require 'models/subscriber'
class EachTest < ActiveRecord::TestCase
- fixtures :posts
+ fixtures :posts, :subscribers
def setup
@posts = Post.order("id asc")
@@ -125,18 +126,14 @@ def test_find_in_batches_should_not_ignore_the_default_scope_if_it_is_other_then
end
def test_find_in_batches_should_use_any_column_as_primary_key
- old_primary_key = Post.primary_key
- Post.primary_key = :title
- title_order_posts = Post.order('title asc')
- start_title = title_order_posts.second.title
+ nick_order_subscribers = Subscriber.order('nick asc')
+ start_nick = nick_order_subscribers.second.nick
- posts = []
- Post.find_in_batches(:batch_size => 1, :start => start_title) do |batch|
- posts.concat(batch)
+ subscribers = []
+ Subscriber.find_in_batches(:batch_size => 1, :start => start_nick) do |batch|
+ subscribers.concat(batch)
end
- assert_equal title_order_posts[1..-1].map(&:id), posts.map(&:id)
- ensure
- Post.primary_key = old_primary_key
+ assert_equal nick_order_subscribers[1..-1].map(&:id), subscribers.map(&:id)
end
end

0 comments on commit 19fa8fa

Please sign in to comment.
Something went wrong with that request. Please try again.