Permalink
Browse files

Merge remote branch 'miloops/master'

  • Loading branch information...
2 parents 0d6f97e + 7006aa1 commit 4072adf9ca0f2b6a81f3eab98168a504973b7049 @jeremy jeremy committed Mar 29, 2010
@@ -50,6 +50,10 @@ def find_each(options = {})
def find_in_batches(options = {})
relation = self
+ if orders.present? || taken.present?
+ ActiveRecord::Base.logger.warn("Scoped order and limit are ignored, it's forced to be batch order and batch size")
+ end
+
if (finder_options = options.except(:start, :batch_size)).present?
raise "You can't specify an order, it's forced to be #{batch_order}" if options[:order].present?
raise "You can't specify a limit, it's forced to be the batch_size" if options[:limit].present?
@@ -77,4 +81,4 @@ def batch_order
"#{@klass.table_name}.#{@klass.primary_key} ASC"
end
end
-end
+end
@@ -27,12 +27,7 @@ def build_from_hash(attributes, default_table)
values = value.to_a
attribute.in(values)
when Range
- # TODO : Arel should handle ranges with excluded end.
- if value.exclude_end?
- [attribute.gteq(value.begin), attribute.lt(value.end)]
- else
- attribute.in(value)
- end
+ attribute.in(value)
else
attribute.eq(value)
end
@@ -8,7 +8,7 @@ def setup
@posts = Post.order("id asc")
@total = Post.count
end
-
+
def test_each_should_excecute_one_query_per_batch
assert_queries(Post.count + 1) do
Post.find_each(:batch_size => 1) do |post|
@@ -28,7 +28,17 @@ def test_each_should_raise_if_the_limit_is_set
Post.find_each(:limit => 1) { |post| post }
end
end
-
+
+ def test_warn_if_limit_scope_is_set
+ ActiveRecord::Base.logger.expects(:warn)
+ Post.limit(1).find_each { |post| post }
+ end
+
+ def test_warn_if_order_scope_is_set
+ ActiveRecord::Base.logger.expects(:warn)
+ Post.order("title").find_each { |post| post }
+ end
+
def test_find_in_batches_should_return_batches
assert_queries(Post.count + 1) do
Post.find_in_batches(:batch_size => 1) do |batch|
@@ -58,4 +68,4 @@ def test_find_in_batches_shouldnt_excute_query_unless_needed
Post.find_in_batches(:batch_size => post_count + 1) {|batch| assert_kind_of Array, batch }
end
end
-end
+end

0 comments on commit 4072adf

Please sign in to comment.