fake_arel 0.9.4 → 0.9.5

Sign up to get free protection for your applications and to get access to all the features.
data/fake_arel.gemspec CHANGED
@@ -6,7 +6,7 @@ require 'bundler/version'
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "fake_arel"
9
- s.version = "0.9.4"
9
+ s.version = "0.9.5"
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.author = "Grant Ammons"
12
12
  s.email = ["grant@pipelinedealsco.com"]
@@ -58,6 +58,16 @@ module Rails3Finders
58
58
  scoped.where(where.join(" OR "))
59
59
  end
60
60
  named_scope :or, __or_fn
61
+
62
+ def self.find_each(options = {:batch_size => 1000}, &block)
63
+ count = self.scoped.count
64
+ return self.scoped if count <= options[:batch_size]
65
+ offset = 0
66
+ while offset < count
67
+ self.scoped(:limit => options[:batch_size], :offset => offset).each { |entry| yield entry }
68
+ offset += options[:batch_size]
69
+ end
70
+ end
61
71
  end
62
72
  end
63
73
  end
data/lib/fake_arel.rb CHANGED
@@ -9,7 +9,7 @@ require 'fake_arel/rails_3_finders'
9
9
  require 'fake_arel/calculations'
10
10
 
11
11
  module FakeArel
12
- VERSION = '0.9.4'
12
+ VERSION = '0.9.5'
13
13
  ActiveRecord::Base.send :include, Rails3Finders
14
14
  ActiveRecord::Base.send :include, WithScopeReplacement
15
15
  end
@@ -187,6 +187,20 @@ describe "Fake Arel" do
187
187
  Reply.all.select {|r| r.id == 1 }.first.id.should == 1
188
188
  lambda { Reply.select(:id).first.content }.should raise_error(ActiveRecord::MissingAttributeError)
189
189
  end
190
+
191
+ it "should respond to batch_find" do
192
+ 10.times {|i| Reply.create(:content => "This is reply number #{i}") }
193
+
194
+ count = 0
195
+ entries = []
196
+ Reply.where("content LIKE('This is reply number%')").find_each(:batch_size => 5) do |reply|
197
+ count += 1
198
+ reply.class.should == Reply
199
+ entries << reply
200
+ end
201
+ count.should == 10
202
+ entries.should == Reply.where("content LIKE('This is reply number%')")
203
+ end
190
204
  end
191
205
 
192
206
  describe "NameScope bug" do
data/spec/test.db CHANGED
Binary file
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fake_arel
3
3
  version: !ruby/object:Gem::Version
4
- hash: 51
4
+ hash: 49
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 4
10
- version: 0.9.4
9
+ - 5
10
+ version: 0.9.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Grant Ammons