toughguy 0.2.1 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/toughguy/model.rb +4 -3
- data/lib/toughguy/version.rb +1 -1
- data/spec/toughguy_spec.rb +24 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99b4d5504b95020c7d616f966f833a2021736630
|
4
|
+
data.tar.gz: 66e9e4b9c642fa774f9997f52be7cea12167a0e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c250c1d3e79b7652d073217e37d828d999315de4a31fe77f75f565595777720bb6cea411cde2d96ae3ae7f14b4ff733559a8190c95cd6563307da7214b2c2ca
|
7
|
+
data.tar.gz: 798e6dc80ec23e116f56adadc6bad83bf97c8954a6cf82d27fcc04a8a74ee3adb0bf39172a8c2b8d4b0b627bdcaea5416362dd1a25f776a86a303d609448da4e
|
data/Gemfile.lock
CHANGED
data/lib/toughguy/model.rb
CHANGED
@@ -122,11 +122,12 @@ module ToughGuy
|
|
122
122
|
|
123
123
|
class << self
|
124
124
|
def bulk(&block)
|
125
|
-
|
125
|
+
reentered = @bulk
|
126
|
+
@bulk = collection.initialize_ordered_bulk_op unless reentered
|
126
127
|
block.call
|
127
|
-
@bulk.execute
|
128
|
+
@bulk.execute unless reentered || @bulk.ops.empty?
|
128
129
|
ensure
|
129
|
-
@bulk = nil
|
130
|
+
@bulk = nil unless reentered
|
130
131
|
end
|
131
132
|
|
132
133
|
def add_index(spec, opts={})
|
data/lib/toughguy/version.rb
CHANGED
data/spec/toughguy_spec.rb
CHANGED
@@ -34,6 +34,30 @@ describe "Model#update" do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
describe "Model.bulk" do
|
38
|
+
it "should not freak out on empty bulk ops" do
|
39
|
+
lambda {Mau.bulk {}}.should_not raise_error
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should be reentrant" do
|
43
|
+
m1 = Mau.create(a: 1, b: 2)
|
44
|
+
m2 = Mau.create(a: 3, b: 4)
|
45
|
+
|
46
|
+
m1.bulk do
|
47
|
+
m1.set(a: 5, c: 6)
|
48
|
+
m2.bulk do
|
49
|
+
m2.set(b: 7, c: 8)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
m1.refresh
|
54
|
+
m2.refresh
|
55
|
+
|
56
|
+
m1.values.should == {a: 5, b: 2, c: 6, _id: m1.id}
|
57
|
+
m2.values.should == {a: 3, b: 7, c: 8, _id: m2.id}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
37
61
|
describe "Model#set" do
|
38
62
|
before do
|
39
63
|
Mau.drop
|