Skip to content

Commit

Permalink
Bug fix: Fixing overriding of the update method which was conflicting…
Browse files Browse the repository at this point in the history
… with before_update callbacks
  • Loading branch information
andrewtimberlake committed May 30, 2012
1 parent 7121f21 commit de0124f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,7 +1,7 @@
source "http://rubygems.org" source "http://rubygems.org"


gem "rake" gem "rake"
gem "bundler", "~> 1.0.0" gem "bundler", "~> 1.1.0"
gem "mongo_mapper" gem "mongo_mapper"
gem "i18n" gem "i18n"


Expand Down
30 changes: 16 additions & 14 deletions Gemfile.lock
@@ -1,23 +1,25 @@
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
activemodel (3.0.5) activemodel (3.2.3)
activesupport (= 3.0.5) activesupport (= 3.2.3)
builder (~> 2.1.2) builder (~> 3.0.0)
i18n (~> 0.4) activesupport (3.2.3)
activesupport (3.0.5) i18n (~> 0.6)
bson (1.3.1) multi_json (~> 1.0)
builder (2.1.2) bson (1.6.2)
builder (3.0.0)
diff-lcs (1.1.2) diff-lcs (1.1.2)
i18n (0.6.0) i18n (0.6.0)
mongo (1.3.1) mongo (1.6.2)
bson (>= 1.3.1) bson (~> 1.6.2)
mongo_mapper (0.9.1) mongo_mapper (0.11.1)
activemodel (~> 3.0) activemodel (~> 3.0)
activesupport (~> 3.0) activesupport (~> 3.0)
plucky (~> 0.3.8) plucky (~> 0.4.0)
plucky (0.3.8) multi_json (1.3.6)
mongo (~> 1.3) plucky (0.4.4)
mongo (~> 1.5)
rake (0.9.2) rake (0.9.2)
rcov (0.9.9) rcov (0.9.9)
rspec (2.6.0) rspec (2.6.0)
Expand All @@ -33,7 +35,7 @@ PLATFORMS
ruby ruby


DEPENDENCIES DEPENDENCIES
bundler (~> 1.0.0) bundler (~> 1.1.0)
i18n i18n
mongo_mapper mongo_mapper
rake rake
Expand Down
16 changes: 11 additions & 5 deletions lib/mongo_mapper/plugins/versioned_update.rb
Expand Up @@ -12,18 +12,24 @@ def versioned_update


module OverriddenMethods module OverriddenMethods
private private
def update(options={}) # Overriding save_to_collection in lib/mongo_mapper/plugins/querying.rb
version = self._version def save_to_collection(options={})
if persisted?
@_new = false
old_version = self._version
self._version += 1 self._version += 1
ret = collection.update({:_id => _id, :_version => version}, ret = collection.update({:_id => _id, :_version => old_version},
to_mongo, to_mongo,
:safe => true) :safe => true)
if ret['n'] == 0 if ret['n'] == 0
self._version -= 1 self._version -= 1
raise InvalidVersion raise InvalidVersion
end end
ret['err'].nil? ret['err'].nil?
else
super
end end
end
end end


class InvalidVersion < StandardError; end class InvalidVersion < StandardError; end
Expand Down

0 comments on commit de0124f

Please sign in to comment.