Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/mongoid/versioning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def revise
# @since 2.2.1
def revise!
versions.build(
(previous_revision || self).versioned_attributes, without_protection: true
(previous_revision || self).versioned_attributes
)
versions.shift if version_max.present? && versions.length > version_max
self.version = (version || 1 ) + 1
Expand Down Expand Up @@ -127,6 +127,7 @@ def versionless
def previous_revision
_loading_revision do
self.class.unscoped.
with(self.mongo_session.options).
where(_id: id).
any_of({ version: version }, { version: nil }).first
end
Expand Down
26 changes: 0 additions & 26 deletions lib/mongoid/versioning/monkey_patches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,29 +322,3 @@ def instantiate(attrs = nil, criteria_instance_id = nil)
end
end
end

module Mongoid
module Sessions
module ClassMethods
# Get the collection for this model from the session. Will check for an
# overridden collection name from the store_in macro or the collection
# with a pluralized model name.
#
# @example Get the model's collection.
# Model.collection
#
# @return [ Moped::Collection ] The collection.
#
# @since 3.0.0
def collection
if opts = persistence_options
coll = mongo_session.with(opts)[opts[:collection] || collection_name]
clear_persistence_options unless validating_with_query? || _loading_revision?
coll
else
mongo_session[collection_name]
end
end
end
end
end
14 changes: 14 additions & 0 deletions spec/mongoid/versioning_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,20 @@ class WikiPage
it "does not create a new version" do
version.should be_nil
end

context "and revision is forced" do
before do
page.revise!
end

it "creates a new version" do
version.should_not be_nil
end

it "page version should be valid" do
page.version.should eq(2)
end
end
end

context "when saving over the number of maximum versions" do
Expand Down