Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bug fix: Fixing overriding of the update method which was conflicting…

… with before_update callbacks
  • Loading branch information...
commit de0124fb90380aa292a0f00cee8d05218acf3a7e 1 parent 7121f21
@andrewtimberlake authored
View
2  Gemfile
@@ -1,7 +1,7 @@
source "http://rubygems.org"
gem "rake"
-gem "bundler", "~> 1.0.0"
+gem "bundler", "~> 1.1.0"
gem "mongo_mapper"
gem "i18n"
View
30 Gemfile.lock
@@ -1,23 +1,25 @@
GEM
remote: http://rubygems.org/
specs:
- activemodel (3.0.5)
- activesupport (= 3.0.5)
- builder (~> 2.1.2)
- i18n (~> 0.4)
- activesupport (3.0.5)
- bson (1.3.1)
- builder (2.1.2)
+ activemodel (3.2.3)
+ activesupport (= 3.2.3)
+ builder (~> 3.0.0)
+ activesupport (3.2.3)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ bson (1.6.2)
+ builder (3.0.0)
diff-lcs (1.1.2)
i18n (0.6.0)
- mongo (1.3.1)
- bson (>= 1.3.1)
- mongo_mapper (0.9.1)
+ mongo (1.6.2)
+ bson (~> 1.6.2)
+ mongo_mapper (0.11.1)
activemodel (~> 3.0)
activesupport (~> 3.0)
- plucky (~> 0.3.8)
- plucky (0.3.8)
- mongo (~> 1.3)
+ plucky (~> 0.4.0)
+ multi_json (1.3.6)
+ plucky (0.4.4)
+ mongo (~> 1.5)
rake (0.9.2)
rcov (0.9.9)
rspec (2.6.0)
@@ -33,7 +35,7 @@ PLATFORMS
ruby
DEPENDENCIES
- bundler (~> 1.0.0)
+ bundler (~> 1.1.0)
i18n
mongo_mapper
rake
View
16 lib/mongo_mapper/plugins/versioned_update.rb
@@ -12,18 +12,24 @@ def versioned_update
module OverriddenMethods
private
- def update(options={})
- version = self._version
+ # Overriding save_to_collection in lib/mongo_mapper/plugins/querying.rb
+ def save_to_collection(options={})
+ if persisted?
+ @_new = false
+ old_version = self._version
self._version += 1
- ret = collection.update({:_id => _id, :_version => version},
- to_mongo,
- :safe => true)
+ ret = collection.update({:_id => _id, :_version => old_version},
+ to_mongo,
+ :safe => true)
if ret['n'] == 0
self._version -= 1
raise InvalidVersion
end
ret['err'].nil?
+ else
+ super
end
+ end
end
class InvalidVersion < StandardError; end
Please sign in to comment.
Something went wrong with that request. Please try again.