mongoid 0.7.7 → 0.7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.7
1
+ 0.7.8
@@ -205,6 +205,12 @@ module Mongoid #:nodoc:
205
205
  other.attributes.except(:modified_at).except(:created_at)
206
206
  end
207
207
 
208
+ # Clone the current +Document+. This will return all attributes with the
209
+ # exception of the document's id and versions.
210
+ def clone
211
+ self.class.new(@attributes.except(:_id).except(:versions).dup)
212
+ end
213
+
208
214
  # Get the Mongo::Collection associated with this Document.
209
215
  def collection
210
216
  self.class.collection
@@ -16,9 +16,9 @@ module Mongoid #:nodoc:
16
16
  # document from the database and set it as the next version before saving
17
17
  # the current document. It then increments the version number.
18
18
  def revise
19
- last_version = self.class.find(id)
19
+ last_version = self.class.first(:conditions => { :_id => id, :version => version })
20
20
  if last_version
21
- self.versions << last_version
21
+ self.versions << last_version.clone
22
22
  self.version = version + 1
23
23
  end
24
24
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid}
8
- s.version = "0.7.7"
8
+ s.version = "0.7.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Durran Jordan"]
@@ -252,12 +252,35 @@ describe Mongoid::Document do
252
252
  @comment.save
253
253
  end
254
254
 
255
- it "versions on save" do
256
- @from_db = Comment.find(@comment.id)
257
- @from_db.text = "New"
258
- @from_db.save
259
- @from_db.versions.size.should == 1
260
- @from_db.version.should == 2
255
+ context "first save" do
256
+
257
+ it "creates a new version" do
258
+ @from_db = Comment.find(@comment.id)
259
+ @from_db.text = "New"
260
+ @from_db.save
261
+ @from_db.versions.size.should == 1
262
+ @from_db.version.should == 2
263
+ end
264
+
265
+ end
266
+
267
+ context "multiple saves" do
268
+
269
+ before do
270
+ 5.times do |n|
271
+ @comment.text = "#{n}"
272
+ @comment.save
273
+ end
274
+ end
275
+
276
+ it "creates new versions" do
277
+ p @comment
278
+ @from_db = Comment.find(@comment.id)
279
+ @from_db.version.should == 6
280
+ p @from_db
281
+ @from_db.versions.size.should == 5
282
+ end
283
+
261
284
  end
262
285
 
263
286
  end
@@ -85,6 +85,20 @@ describe Mongoid::Document do
85
85
 
86
86
  end
87
87
 
88
+ describe "#clone" do
89
+
90
+ before do
91
+ @comment = Comment.new(:text => "Woooooo")
92
+ @clone = @comment.clone
93
+ end
94
+
95
+ it "returns a new document sans id and versions" do
96
+ @clone.id.should_not == @comment.id
97
+ @clone.versions.should be_empty
98
+ end
99
+
100
+ end
101
+
88
102
  describe "#collection" do
89
103
 
90
104
  before do
@@ -17,7 +17,7 @@ describe Mongoid::Versioning do
17
17
  before do
18
18
  @post.title = "New"
19
19
  @version = Post.new(:title => "Test")
20
- Post.expects(:find).at_least(1).with(@post.id).returns(@version)
20
+ Post.expects(:first).at_least(1).with(:conditions => { :_id => @post.id, :version => 1 }).returns(@version)
21
21
  @post.revise
22
22
  end
23
23
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.7
4
+ version: 0.7.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Durran Jordan