mongo_mapper_versioned 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ module MongoMapper
|
|
7
7
|
configuration = { :ignored_keys => %w(_id version_number created_at updated_at creator_id updater_id) }
|
8
8
|
configuration.update(options) if options.is_a?(Hash)
|
9
9
|
|
10
|
-
key :version_number, Integer, :default =>
|
10
|
+
key :version_number, Integer, :default => 0, :index => true
|
11
11
|
many :versions, :class => MongoMapper::Plugins::Versioned::Version, :foreign_key => :versioned_id, :dependent => :destroy, :order => :version_number.asc
|
12
12
|
|
13
13
|
after_create :create_version
|
@@ -24,7 +24,7 @@ module MongoMapper
|
|
24
24
|
module InstanceMethods
|
25
25
|
|
26
26
|
def create_version
|
27
|
-
self.version_number = versions.last.version_number+1
|
27
|
+
self.version_number = (versions.empty? ? 1 : versions.last.version_number+1)
|
28
28
|
self.versions << current_version
|
29
29
|
end
|
30
30
|
|
@@ -23,8 +23,8 @@ class VersionedTest < ActiveSupport::TestCase
|
|
23
23
|
setup do
|
24
24
|
@doc = VersionedDoc.new
|
25
25
|
end
|
26
|
-
should "be on version
|
27
|
-
assert_equal
|
26
|
+
should "be on version 0" do
|
27
|
+
assert_equal 0, @doc.version_number
|
28
28
|
end
|
29
29
|
should "have 0 versions" do
|
30
30
|
assert_equal 0, @doc.versions.count
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_mapper_versioned
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tomas Celizna
|