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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30b980a129f46230b7ca6453cb803dfcf48db7af
4
- data.tar.gz: f62d6aa6d055683ddcd299649ed49d2537d37d36
3
+ metadata.gz: 99b4d5504b95020c7d616f966f833a2021736630
4
+ data.tar.gz: 66e9e4b9c642fa774f9997f52be7cea12167a0e5
5
5
  SHA512:
6
- metadata.gz: 7843f4fd5e9943e057d98fd39dd57edcd7e69bb8f923f9a05e5b55f505dd9be6a9e6d19f1b65cb24d7db25a82c6c4f3730b8ac57fe1a0d99e2802355b601ae4e
7
- data.tar.gz: 0ea7585c3b92096b7b98cfc84f6ae5999e1bc2ca56f1714102f31528ab82174b7f5d6c07d4fb9f4d29581fb5e929ad1eb4f72e1b7051de5d6669127c6e76b06f
6
+ metadata.gz: 9c250c1d3e79b7652d073217e37d828d999315de4a31fe77f75f565595777720bb6cea411cde2d96ae3ae7f14b4ff733559a8190c95cd6563307da7214b2c2ca
7
+ data.tar.gz: 798e6dc80ec23e116f56adadc6bad83bf97c8954a6cf82d27fcc04a8a74ee3adb0bf39172a8c2b8d4b0b627bdcaea5416362dd1a25f776a86a303d609448da4e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- toughguy (0.2.0)
4
+ toughguy (0.2.2)
5
5
  assistance (= 0.1.5)
6
6
  bson_ext (= 1.11.1)
7
7
  mongo (= 1.11.1)
@@ -122,11 +122,12 @@ module ToughGuy
122
122
 
123
123
  class << self
124
124
  def bulk(&block)
125
- @bulk = collection.initialize_ordered_bulk_op
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={})
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module ToughGuy
3
- Version = '0.2.1'
3
+ Version = '0.2.3'
4
4
  end
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toughguy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner