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 +1 -1
- data/lib/fake_arel/rails_3_finders.rb +10 -0
- data/lib/fake_arel.rb +1 -1
- data/spec/fake_arel_spec.rb +14 -0
- data/spec/test.db +0 -0
- metadata +3 -3
data/fake_arel.gemspec
CHANGED
@@ -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
data/spec/fake_arel_spec.rb
CHANGED
@@ -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:
|
4
|
+
hash: 49
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 5
|
10
|
+
version: 0.9.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Grant Ammons
|