mongoid_optimistic_locking 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -3,14 +3,14 @@ module Mongoid
|
|
3
3
|
module Operations
|
4
4
|
|
5
5
|
def insert(options = {})
|
6
|
-
return super unless optimistic_locking?
|
6
|
+
return super unless optimistic_locking? && valid?
|
7
7
|
increment_lock_version do
|
8
8
|
super
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
def update(options = {})
|
13
|
-
return super unless optimistic_locking?
|
13
|
+
return super unless optimistic_locking? && valid?
|
14
14
|
set_lock_version_for_selector do
|
15
15
|
increment_lock_version do
|
16
16
|
result = super
|
@@ -47,6 +47,15 @@ describe Mongoid::OptimisticLocking do
|
|
47
47
|
field :name
|
48
48
|
end
|
49
49
|
|
50
|
+
class Hamburger
|
51
|
+
include Mongoid::Document
|
52
|
+
include Mongoid::OptimisticLocking
|
53
|
+
field :patty
|
54
|
+
field :toppings
|
55
|
+
validates :patty, presence: true
|
56
|
+
validates :toppings, presence: true
|
57
|
+
end
|
58
|
+
|
50
59
|
end
|
51
60
|
|
52
61
|
after(:all) { COLLECTIONS.each { |n| Object.send(:remove_const, n) } }
|
@@ -180,6 +189,20 @@ describe Mongoid::OptimisticLocking do
|
|
180
189
|
|
181
190
|
end
|
182
191
|
|
192
|
+
context 'optimistic locking on a document with validation' do
|
193
|
+
it 'should not incremement lock version when validation fails' do
|
194
|
+
burger = Hamburger.new
|
195
|
+
burger._lock_version.should == 0
|
196
|
+
burger.save.should == false
|
197
|
+
burger._lock_version.should == 0
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'should allow creation when valid' do
|
201
|
+
burger = Hamburger.create({patty: 'beef', toppings: 'bacon'})
|
202
|
+
burger._lock_version.should == 1
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
183
206
|
context 'optimistic locking on an embeds_one document' do
|
184
207
|
|
185
208
|
let!(:state) { State.new(:name => 'California') }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_optimistic_locking
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-04-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: mongoid
|
@@ -102,12 +102,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
102
|
- - ! '>='
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
hash: 1302811903269459729
|
105
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
109
|
none: false
|
107
110
|
requirements:
|
108
111
|
- - ! '>='
|
109
112
|
- !ruby/object:Gem::Version
|
110
113
|
version: '0'
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
hash: 1302811903269459729
|
111
117
|
requirements: []
|
112
118
|
rubyforge_project: mongoid_optimistic_locking
|
113
119
|
rubygems_version: 1.8.24
|