mongoid-history 0.0.3 → 0.0.4

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.0.3
1
+ 0.0.4
@@ -20,15 +20,19 @@ module Mongoid::History
20
20
  module ClassMethods
21
21
  end
22
22
 
23
- def undo!
23
+ def undo!(modifier)
24
24
  undo_hash = affected.easy_unmerge(modified)
25
25
  undo_hash.easy_merge!(original)
26
+ modifier_field = trackable.history_trackable_options[:modifier_field]
27
+ undo_hash[modifier_field] = modifier
26
28
  trackable.update_attributes!(undo_hash)
27
29
  end
28
30
 
29
- def redo!
31
+ def redo!(modifier)
30
32
  redo_hash = affected.easy_unmerge(original)
31
33
  redo_hash.easy_merge!(modified)
34
+ modifier_field = trackable.history_trackable_options[:modifier_field]
35
+ redo_hash[modifier_field] = modifier
32
36
  trackable.update_attributes!(redo_hash)
33
37
  end
34
38
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid-history}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Aaron Qian"]
@@ -206,23 +206,30 @@ describe Mongoid::History do
206
206
  describe "non-embedded" do
207
207
  it "should undo changes" do
208
208
  @post.update_attributes(:title => "Test2")
209
- @post.history_tracks.where(:version => 1).first.undo!
209
+ @post.history_tracks.where(:version => 1).first.undo!(@user)
210
210
  @post.reload
211
211
  @post.title.should == "Test"
212
212
  end
213
213
 
214
214
  it "should create a new history track after undo" do
215
215
  @post.update_attributes(:title => "Test2")
216
- @post.history_tracks.where(:version => 1).first.undo!
216
+ @post.history_tracks.where(:version => 1).first.undo!(@user)
217
217
  @post.reload
218
218
  @post.history_tracks.count.should == 2
219
219
  end
220
220
 
221
+ it "should assign @user as the modifier of the newly created history track" do
222
+ @post.update_attributes(:title => "Test2")
223
+ @post.history_tracks.where(:version => 1).first.undo!(@user)
224
+ @post.reload
225
+ @post.history_tracks.where(:version => 2).first.modifier.should == @user
226
+ end
227
+
221
228
  it "should stay the same after undo and redo" do
222
229
  @post.update_attributes(:title => "Test2")
223
230
  @track = @post.history_tracks.where(:version => 1).first
224
- @track.undo!
225
- @track.redo!
231
+ @track.undo!(@user)
232
+ @track.redo!(@user)
226
233
  @post2 = Post.where(:_id => @post.id).first
227
234
 
228
235
  @post.title.should == @post2.title
@@ -232,7 +239,7 @@ describe Mongoid::History do
232
239
  describe "embedded" do
233
240
  it "should undo changes" do
234
241
  @comment.update_attributes(:title => "Test2")
235
- @comment.history_tracks.where(:version => 2).first.undo!
242
+ @comment.history_tracks.where(:version => 2).first.undo!(@user)
236
243
  # reloading an embedded document === KAMIKAZE
237
244
  # at least for the current release of mongoid...
238
245
  @post.reload
@@ -242,17 +249,25 @@ describe Mongoid::History do
242
249
 
243
250
  it "should create a new history track after undo" do
244
251
  @comment.update_attributes(:title => "Test2")
245
- @comment.history_tracks.where(:version => 2).first.undo!
252
+ @comment.history_tracks.where(:version => 2).first.undo!(@user)
246
253
  @post.reload
247
254
  @comment = @post.comments.first
248
255
  @comment.history_tracks.count.should == 3
249
256
  end
250
257
 
258
+ it "should assign @user as the modifier of the newly created history track" do
259
+ @comment.update_attributes(:title => "Test2")
260
+ @comment.history_tracks.where(:version => 2).first.undo!(@user)
261
+ @post.reload
262
+ @comment = @post.comments.first
263
+ @comment.history_tracks.where(:version => 3).first.modifier.should == @user
264
+ end
265
+
251
266
  it "should stay the same after undo and redo" do
252
267
  @comment.update_attributes(:title => "Test2")
253
268
  @track = @comment.history_tracks.where(:version => 2).first
254
- @track.undo!
255
- @track.redo!
269
+ @track.undo!(@user)
270
+ @track.redo!(@user)
256
271
  @post2 = Post.where(:_id => @post.id).first
257
272
  @comment2 = @post2.comments.first
258
273
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mongoid-history
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Aaron Qian
@@ -167,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
167
  requirements:
168
168
  - - ">="
169
169
  - !ruby/object:Gem::Version
170
- hash: -4375760332682967457
170
+ hash: -4589189191115367559
171
171
  segments:
172
172
  - 0
173
173
  version: "0"