mongoid-history 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,9 +1,10 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'easy_diff'
4
- gem 'mongoid', '>= 2.0.2'
3
+ gem "easy_diff"
4
+ gem "mongoid", "~> 2.0"
5
5
 
6
6
  group :development do
7
+ gem "bson_ext", ">= 1.3.1"
7
8
  gem "rspec", "~> 2.3.0"
8
9
  gem "yard", "~> 0.6.0"
9
10
  gem "bundler", "~> 1.0.0"
data/README.rdoc CHANGED
@@ -27,7 +27,7 @@ Here is a quick example on how to use this plugin. For more details, please look
27
27
  class Post
28
28
  include Mongoid::Document
29
29
  include Mongoid::Timestamps
30
-
30
+
31
31
  # History tracking all Post Documents
32
32
  # Note: Tracking will not work until #track_history is invoked
33
33
  include Mongoid::History::Trackable
@@ -36,26 +36,27 @@ Here is a quick example on how to use this plugin. For more details, please look
36
36
  field :body
37
37
  field :rating
38
38
  embeds_many :comments
39
-
39
+
40
40
  # Telling Mongoid::History how you want to track
41
41
  track_history :on => [:title, :body], # I want to track title and body fields only. Default is :all
42
42
  :modifier_field => :modifier, # Adds "referened_in :modifier" to track who made the change. Default is :modifier
43
43
  :version_field => :version, # Adds "field :version, :type => Integer" to track current version. Default is :version
44
44
  :track_create => false, # Do you want to track document creation? Default is false
45
+ :track_update => true, # Do you want to track document updates? Default is true
45
46
  :track_destroy => false, # Do you want to track document destruction? Default is false
46
47
  end
47
48
 
48
49
  class Comment
49
50
  include Mongoid::Document
50
51
  include Mongoid::Timestamps
51
-
52
+
52
53
  # Declare that we want to track comments
53
54
  include Mongoid::History::Trackable
54
55
 
55
56
  field :title
56
57
  field :body
57
58
  embedded_in :post, :inverse_of => :comments
58
-
59
+
59
60
  # Track title and body for all comments, scope it to post (the parent)
60
61
  # Also track creation and destruction
61
62
  track_history :on => [:title, :body], :scope => :post, :track_create => true, :track_destroy => true
@@ -68,49 +69,49 @@ Here is a quick example on how to use this plugin. For more details, please look
68
69
 
69
70
  field :name
70
71
  end
71
-
72
+
72
73
  user = User.create(:name => "Aaron")
73
74
  post = Post.create(:title => "Test", :body => "Post", :modifier => user)
74
75
  comment = post.comments.create(:title => "test", :body => "comment", :modifier => user)
75
76
  comment.history_tracks.count # should be 1
76
-
77
+
77
78
  comment.update_attributes(:title => "Test 2")
78
79
  comment.history_tracks.count # should be 2
79
-
80
+
80
81
  track = comment.history_tracks.last
81
82
 
82
83
  track.undo! # comment title should be "Test"
83
-
84
+
84
85
  track.redo! # comment title should be "Test 2"
85
-
86
+
86
87
  # undo last change
87
88
  comment.undo! @user
88
-
89
+
89
90
  # undo versions 1 - 4
90
91
  comment.undo! @user, :from => 4, :to => 1
91
-
92
+
92
93
  # undo last 3 versions
93
94
  comment.undo! @user, :last => 3
94
-
95
+
95
96
  # redo versions 1 - 4
96
97
  comment.redo! @user, :from => 1, :to => 4
97
-
98
+
98
99
  # redo last 3 versions
99
100
  comment.redo! @user, :last => 3
100
-
101
+
101
102
  # delete post
102
103
  post.destroy
103
-
104
+
104
105
  # undelete post
105
106
  post.undo! @user
106
-
107
+
107
108
  # disable tracking for comments within a block
108
109
  Comment.disable_tracking do
109
110
  comment.update_attributes(:title => "Test 3")
110
111
  end
111
112
 
112
113
  == Contributing to mongoid-history
113
-
114
+
114
115
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
115
116
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
116
117
  * Fork the project
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -4,7 +4,7 @@ module Mongoid
4
4
  mattr_accessor :trackable_classes
5
5
  mattr_accessor :trackable_class_options
6
6
  mattr_accessor :modifier_class_name
7
-
7
+
8
8
  def self.tracker_class
9
9
  @tracker_class ||= tracker_class_name.to_s.classify.constantize
10
10
  end
@@ -12,6 +12,7 @@ module Mongoid::History
12
12
  :version_field => :version,
13
13
  :scope => model_name,
14
14
  :track_create => false,
15
+ :track_update => true,
15
16
  :track_destroy => false,
16
17
  }
17
18
 
@@ -41,16 +42,16 @@ module Mongoid::History
41
42
  delegate :history_trackable_options, :to => 'self.class'
42
43
  delegate :track_history?, :to => 'self.class'
43
44
 
44
- before_update :track_update
45
+ before_update :track_update if options[:track_update]
45
46
  before_create :track_create if options[:track_create]
46
- after_destroy :track_destroy if options[:track_destroy]
47
+ before_destroy :track_destroy if options[:track_destroy]
47
48
 
48
49
  Mongoid::History.trackable_classes ||= []
49
50
  Mongoid::History.trackable_classes << self
50
51
  Mongoid::History.trackable_class_options ||= {}
51
52
  Mongoid::History.trackable_class_options[model_name] = options
52
53
  end
53
-
54
+
54
55
  def track_history?
55
56
  enabled = Thread.current[track_history_flag]
56
57
  enabled.nil? ? true : enabled
@@ -64,7 +65,7 @@ module Mongoid::History
64
65
  Thread.current[track_history_flag] = true
65
66
  end
66
67
  end
67
-
68
+
68
69
  def track_history_flag
69
70
  "mongoid_history_#{self.name.underscore}_trackable_enabled".to_sym
70
71
  end
@@ -72,7 +73,7 @@ module Mongoid::History
72
73
 
73
74
  module InstanceMethods
74
75
  def history_tracks
75
- @history_tracks ||= Mongoid::History.tracker_class.where(:scope => history_trackable_options[:scope], :association_chain => triverse_association_chain)
76
+ @history_tracks ||= Mongoid::History.tracker_class.where(:scope => history_trackable_options[:scope], :association_chain => traverse_association_chain)
76
77
  end
77
78
 
78
79
  # undo :from => 1, :to => 5
@@ -115,7 +116,8 @@ module Mongoid::History
115
116
  end
116
117
  else
117
118
  options_or_version = options_or_version.to_a if options_or_version.is_a?(Range)
118
- version = options_or_version || self.attributes[history_trackable_options[:version_field]] || self.attributes[history_trackable_options[:version_field].to_s]
119
+ version_field_name = history_trackable_options[:version_field]
120
+ version = options_or_version || self.attributes[version_field_name] || self.attributes[version_field_name.to_s]
119
121
  version = [ version ].flatten
120
122
  versions = history_tracks.where(:version.in => version)
121
123
  end
@@ -126,8 +128,8 @@ module Mongoid::History
126
128
  track_history? && !modified_attributes_for_update.blank?
127
129
  end
128
130
 
129
- def triverse_association_chain(node=self)
130
- list = node._parent ? triverse_association_chain(node._parent) : []
131
+ def traverse_association_chain(node=self)
132
+ list = node._parent ? traverse_association_chain(node._parent) : []
131
133
  list << { 'name' => node.class.name, 'id' => node.id }
132
134
  list
133
135
  end
@@ -167,7 +169,7 @@ module Mongoid::History
167
169
  return @history_tracker_attributes if @history_tracker_attributes
168
170
 
169
171
  @history_tracker_attributes = {
170
- :association_chain => triverse_association_chain,
172
+ :association_chain => traverse_association_chain,
171
173
  :scope => history_trackable_options[:scope],
172
174
  :modifier => send(history_trackable_options[:modifier_field])
173
175
  }
@@ -177,7 +179,7 @@ module Mongoid::History
177
179
  when :create then modified_attributes_for_create
178
180
  else modified_attributes_for_update
179
181
  end)
180
-
182
+
181
183
  @history_tracker_attributes[:original] = original
182
184
  @history_tracker_attributes[:modified] = modified
183
185
  @history_tracker_attributes
@@ -5,7 +5,7 @@ module Mongoid::History
5
5
  included do
6
6
  include Mongoid::Document
7
7
  include Mongoid::Timestamps
8
-
8
+
9
9
  field :association_chain, :type => Array, :default => []
10
10
  field :modified, :type => Hash
11
11
  field :original, :type => Hash
@@ -16,11 +16,7 @@ module Mongoid::History
16
16
 
17
17
  Mongoid::History.tracker_class_name = self.name.tableize.singularize.to_sym
18
18
  end
19
-
20
-
21
- module ClassMethods
22
- end
23
-
19
+
24
20
  def undo!(modifier)
25
21
  if action.to_sym == :destroy
26
22
  class_name = association_chain[0]["name"]
@@ -30,7 +26,7 @@ module Mongoid::History
30
26
  trackable.update_attributes!(undo_attr(modifier))
31
27
  end
32
28
  end
33
-
29
+
34
30
  def redo!(modifier)
35
31
  if action.to_sym == :destroy
36
32
  trackable.destroy
@@ -38,7 +34,7 @@ module Mongoid::History
38
34
  trackable.update_attributes!(redo_attr(modifier))
39
35
  end
40
36
  end
41
-
37
+
42
38
  def undo_attr(modifier)
43
39
  undo_hash = affected.easy_unmerge(modified)
44
40
  undo_hash.easy_merge!(original)
@@ -46,7 +42,7 @@ module Mongoid::History
46
42
  undo_hash[modifier_field] = modifier
47
43
  undo_hash
48
44
  end
49
-
45
+
50
46
  def redo_attr(modifier)
51
47
  redo_hash = affected.easy_unmerge(original)
52
48
  redo_hash.easy_merge!(modified)
@@ -54,24 +50,24 @@ module Mongoid::History
54
50
  redo_hash[modifier_field] = modifier
55
51
  redo_hash
56
52
  end
57
-
53
+
58
54
  def trackable_root
59
55
  @trackable_root ||= trackable_parents_and_trackable.first
60
56
  end
61
-
57
+
62
58
  def trackable
63
59
  @trackable ||= trackable_parents_and_trackable.last
64
60
  end
65
-
61
+
66
62
  def trackable_parents
67
63
  @trackable_parents ||= trackable_parents_and_trackable[0, -1]
68
64
  end
69
-
65
+
70
66
  def affected
71
67
  @affected ||= (modified.keys | original.keys).inject({}){ |h,k| h[k] =
72
68
  trackable ? trackable.attributes[k] : modified[k]; h}
73
69
  end
74
-
70
+
75
71
  private
76
72
  def trackable_parents_and_trackable
77
73
  @trackable_parents_and_trackable ||= traverse_association_chain
@@ -90,6 +86,6 @@ private
90
86
  end while( !chain.empty? )
91
87
  documents
92
88
  end
93
-
89
+
94
90
  end
95
91
  end
@@ -5,15 +5,15 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mongoid-history}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Aaron Qian", "Justin Grimes"]
12
- s.date = %q{2011-07-12}
11
+ s.authors = [%q{Aaron Qian}, %q{Justin Grimes}]
12
+ s.date = %q{2011-08-30}
13
13
  s.description = %q{In frustration of Mongoid::Versioning, I created this plugin for tracking historical changes for any document, including embedded ones. It achieves this by storing all history tracks in a single collection that you define. (See Usage for more details) Embedded documents are referenced by storing an association path, which is an array of document_name and document_id fields starting from the top most parent document and down to the embedded document that should track history.
14
14
 
15
15
  This plugin implements multi-user undo, which allows users to undo any history change in any order. Undoing a document also creates a new history track. This is great for auditing and preventing vandalism, but it is probably not suitable for use cases such as a wiki.}
16
- s.email = ["aq1018@gmail.com", "justin.mgrimes@gmail.com"]
16
+ s.email = [%q{aq1018@gmail.com}, %q{justin.mgrimes@gmail.com}]
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE.txt",
19
19
  "README.rdoc"
@@ -38,9 +38,9 @@ Gem::Specification.new do |s|
38
38
  "spec/tracker_spec.rb"
39
39
  ]
40
40
  s.homepage = %q{http://github.com/aq1018/mongoid-history}
41
- s.licenses = ["MIT"]
42
- s.require_paths = ["lib"]
43
- s.rubygems_version = %q{1.6.2}
41
+ s.licenses = [%q{MIT}]
42
+ s.require_paths = [%q{lib}]
43
+ s.rubygems_version = %q{1.8.6}
44
44
  s.summary = %q{history tracking, auditing, undo, redo for mongoid}
45
45
  s.test_files = [
46
46
  "spec/integration/integration_spec.rb",
@@ -54,7 +54,8 @@ Gem::Specification.new do |s|
54
54
 
55
55
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
56
  s.add_runtime_dependency(%q<easy_diff>, [">= 0"])
57
- s.add_runtime_dependency(%q<mongoid>, [">= 2.0.2"])
57
+ s.add_runtime_dependency(%q<mongoid>, ["~> 2.0"])
58
+ s.add_development_dependency(%q<bson_ext>, [">= 1.3.1"])
58
59
  s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
59
60
  s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
60
61
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -65,7 +66,8 @@ Gem::Specification.new do |s|
65
66
  s.add_development_dependency(%q<database_cleaner>, [">= 0"])
66
67
  else
67
68
  s.add_dependency(%q<easy_diff>, [">= 0"])
68
- s.add_dependency(%q<mongoid>, [">= 2.0.2"])
69
+ s.add_dependency(%q<mongoid>, ["~> 2.0"])
70
+ s.add_dependency(%q<bson_ext>, [">= 1.3.1"])
69
71
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
70
72
  s.add_dependency(%q<yard>, ["~> 0.6.0"])
71
73
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -77,7 +79,8 @@ Gem::Specification.new do |s|
77
79
  end
78
80
  else
79
81
  s.add_dependency(%q<easy_diff>, [">= 0"])
80
- s.add_dependency(%q<mongoid>, [">= 2.0.2"])
82
+ s.add_dependency(%q<mongoid>, ["~> 2.0"])
83
+ s.add_dependency(%q<bson_ext>, [">= 1.3.1"])
81
84
  s.add_dependency(%q<rspec>, ["~> 2.3.0"])
82
85
  s.add_dependency(%q<yard>, ["~> 0.6.0"])
83
86
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -40,36 +40,36 @@ describe Mongoid::History do
40
40
  track_history :except => [:email]
41
41
  end
42
42
  end
43
-
43
+
44
44
  before :each do
45
45
  @user = User.create(:name => "Aaron", :email => "aaron@randomemail.com")
46
46
  @another_user = User.create(:name => "Another Guy", :email => "anotherguy@randomemail.com")
47
47
  @post = Post.create(:title => "Test", :body => "Post", :modifier => @user, :views => 100)
48
48
  @comment = @post.comments.create(:title => "test", :body => "comment", :modifier => @user)
49
49
  end
50
-
50
+
51
51
  describe "track" do
52
52
  describe "on creation" do
53
53
  it "should have one history track in comment" do
54
54
  @comment.history_tracks.count.should == 1
55
55
  end
56
-
56
+
57
57
  it "should assign title and body on modified" do
58
58
  @comment.history_tracks.first.modified.should == {'title' => "test", 'body' => "comment"}
59
59
  end
60
-
60
+
61
61
  it "should not assign title and body on original" do
62
62
  @comment.history_tracks.first.original.should == {}
63
63
  end
64
-
64
+
65
65
  it "should assign modifier" do
66
66
  @comment.history_tracks.first.modifier.should == @user
67
67
  end
68
-
68
+
69
69
  it "should assign version" do
70
70
  @comment.history_tracks.first.version.should == 1
71
71
  end
72
-
72
+
73
73
  it "should assign scope" do
74
74
  @comment.history_tracks.first.scope == "Post"
75
75
  end
@@ -77,19 +77,19 @@ describe Mongoid::History do
77
77
  it "should assign method" do
78
78
  @comment.history_tracks.first.action == "create"
79
79
  end
80
-
80
+
81
81
  it "should assign association_chain" do
82
82
  @comment.history_tracks.first.association_chain = [{:id => @post.id, :name => "Post"}, {:id => @comment.id, :name => "Comment"}]
83
83
  end
84
84
  end
85
-
85
+
86
86
  describe "on destruction" do
87
87
  it "should have two history track records in post" do
88
88
  lambda {
89
89
  @post.destroy
90
90
  }.should change(HistoryTracker, :count).by(1)
91
91
  end
92
-
92
+
93
93
  it "should assign destroy on track record" do
94
94
  @post.destroy
95
95
  @post.history_tracks.last.action == "destroy"
@@ -101,12 +101,12 @@ describe Mongoid::History do
101
101
  end
102
102
 
103
103
  end
104
-
104
+
105
105
  describe "on update non-embedded" do
106
106
  it "should create a history track if changed attributes match tracked attributes" do
107
107
  lambda {
108
108
  @post.update_attributes(:title => "Another Test")
109
- }.should change(HistoryTracker, :count).by(1)
109
+ }.should change(HistoryTracker, :count).by(1)
110
110
  end
111
111
 
112
112
  it "should not create a history track if changed attributes do not match tracked attributes" do
@@ -114,7 +114,7 @@ describe Mongoid::History do
114
114
  @post.update_attributes(:rating => "untracked")
115
115
  }.should change(HistoryTracker, :count).by(0)
116
116
  end
117
-
117
+
118
118
  it "should assign modified fields" do
119
119
  @post.update_attributes(:title => "Another Test")
120
120
  @post.history_tracks.first.modified.should == {
@@ -126,7 +126,7 @@ describe Mongoid::History do
126
126
  @post.update_attributes(:title => "Another Test")
127
127
  @post.history_tracks.first.action.should == "update"
128
128
  end
129
-
129
+
130
130
  it "should assign original fields" do
131
131
  @post.update_attributes(:title => "Another Test")
132
132
  @post.history_tracks.first.original.should == {
@@ -143,7 +143,7 @@ describe Mongoid::History do
143
143
  @post.update_attributes(:title => "Another Test")
144
144
  @post.history_tracks.first.version.should == 1
145
145
  end
146
-
146
+
147
147
  it "should assign version on post" do
148
148
  @post.update_attributes(:title => "Another Test")
149
149
  @post.version.should == 1
@@ -166,7 +166,7 @@ describe Mongoid::History do
166
166
  }
167
167
  end
168
168
  end
169
-
169
+
170
170
  describe "on update non-embedded twice" do
171
171
  it "should assign version on post" do
172
172
  @post.update_attributes(:title => "Test2")
@@ -178,15 +178,15 @@ describe Mongoid::History do
178
178
  lambda {
179
179
  @post.update_attributes(:title => "Test2")
180
180
  @post.update_attributes(:title => "Test3")
181
- }.should change(HistoryTracker, :count).by(2)
181
+ }.should change(HistoryTracker, :count).by(2)
182
182
  end
183
-
183
+
184
184
  it "should create a history track of version 2" do
185
185
  @post.update_attributes(:title => "Test2")
186
186
  @post.update_attributes(:title => "Test3")
187
187
  @post.history_tracks.where(:version => 2).first.should_not be_nil
188
188
  end
189
-
189
+
190
190
  it "should assign modified fields" do
191
191
  @post.update_attributes(:title => "Test2")
192
192
  @post.update_attributes(:title => "Test3")
@@ -194,7 +194,7 @@ describe Mongoid::History do
194
194
  "title" => "Test3"
195
195
  }
196
196
  end
197
-
197
+
198
198
  it "should assign original fields" do
199
199
  @post.update_attributes(:title => "Test2")
200
200
  @post.update_attributes(:title => "Test3")
@@ -202,14 +202,14 @@ describe Mongoid::History do
202
202
  "title" => "Test2"
203
203
  }
204
204
  end
205
-
205
+
206
206
 
207
207
  it "should assign modifier" do
208
208
  @post.update_attributes(:title => "Another Test", :modifier => @another_user)
209
209
  @post.history_tracks.first.modifier.should == @another_user
210
210
  end
211
211
  end
212
-
212
+
213
213
  describe "on update embedded" do
214
214
  it "should assign version on comment" do
215
215
  @comment.update_attributes(:title => "Test2")
@@ -220,14 +220,14 @@ describe Mongoid::History do
220
220
  @comment.update_attributes(:title => "Test2")
221
221
  @comment.history_tracks.where(:version => 2).first.should_not be_nil
222
222
  end
223
-
223
+
224
224
  it "should assign modified fields" do
225
225
  @comment.update_attributes(:title => "Test2")
226
226
  @comment.history_tracks.where(:version => 2).first.modified.should == {
227
227
  "title" => "Test2"
228
228
  }
229
229
  end
230
-
230
+
231
231
  it "should assign original fields" do
232
232
  @comment.update_attributes(:title => "Test2")
233
233
  @comment.history_tracks.where(:version => 2).first.original.should == {
@@ -240,7 +240,7 @@ describe Mongoid::History do
240
240
  @post.history_tracks.first.modifier.should == @another_user
241
241
  end
242
242
  end
243
-
243
+
244
244
  describe "non-embedded" do
245
245
  it "should undo changes" do
246
246
  @post.update_attributes(:title => "Test2")
@@ -254,31 +254,31 @@ describe Mongoid::History do
254
254
  @post.history_tracks.where(:version => 1).first.undo!(@user)
255
255
  Post.find(@post.id).title.should == "Test"
256
256
  end
257
-
257
+
258
258
  it "should create a new history track after undo" do
259
259
  @post.update_attributes(:title => "Test2")
260
260
  @post.history_tracks.where(:version => 1).first.undo!(@user)
261
261
  @post.reload
262
262
  @post.history_tracks.count.should == 2
263
263
  end
264
-
264
+
265
265
  it "should assign @user as the modifier of the newly created history track" do
266
266
  @post.update_attributes(:title => "Test2")
267
267
  @post.history_tracks.where(:version => 1).first.undo!(@user)
268
268
  @post.reload
269
269
  @post.history_tracks.where(:version => 2).first.modifier.should == @user
270
270
  end
271
-
271
+
272
272
  it "should stay the same after undo and redo" do
273
273
  @post.update_attributes(:title => "Test2")
274
274
  @track = @post.history_tracks.where(:version => 1).first
275
275
  @track.undo!(@user)
276
276
  @track.redo!(@user)
277
277
  @post2 = Post.where(:_id => @post.id).first
278
-
278
+
279
279
  @post.title.should == @post2.title
280
280
  end
281
-
281
+
282
282
  it "should be destroyed after undo and redo" do
283
283
  @post.destroy
284
284
  @track = @post.history_tracks.where(:version => 1).first
@@ -286,9 +286,8 @@ describe Mongoid::History do
286
286
  @track.redo!(@user)
287
287
  Post.where(:_id => @post.id).first == nil
288
288
  end
289
-
290
289
  end
291
-
290
+
292
291
  describe "embedded" do
293
292
  it "should undo changes" do
294
293
  @comment.update_attributes(:title => "Test2")
@@ -299,7 +298,7 @@ describe Mongoid::History do
299
298
  @comment = @post.comments.first
300
299
  @comment.title.should == "test"
301
300
  end
302
-
301
+
303
302
  it "should create a new history track after undo" do
304
303
  @comment.update_attributes(:title => "Test2")
305
304
  @comment.history_tracks.where(:version => 2).first.undo!(@user)
@@ -307,7 +306,7 @@ describe Mongoid::History do
307
306
  @comment = @post.comments.first
308
307
  @comment.history_tracks.count.should == 3
309
308
  end
310
-
309
+
311
310
  it "should assign @user as the modifier of the newly created history track" do
312
311
  @comment.update_attributes(:title => "Test2")
313
312
  @comment.history_tracks.where(:version => 2).first.undo!(@user)
@@ -315,7 +314,7 @@ describe Mongoid::History do
315
314
  @comment = @post.comments.first
316
315
  @comment.history_tracks.where(:version => 3).first.modifier.should == @user
317
316
  end
318
-
317
+
319
318
  it "should stay the same after undo and redo" do
320
319
  @comment.update_attributes(:title => "Test2")
321
320
  @track = @comment.history_tracks.where(:version => 2).first
@@ -323,61 +322,60 @@ describe Mongoid::History do
323
322
  @track.redo!(@user)
324
323
  @post2 = Post.where(:_id => @post.id).first
325
324
  @comment2 = @post2.comments.first
326
-
325
+
327
326
  @comment.title.should == @comment2.title
328
327
  end
329
328
  end
330
-
329
+
331
330
  describe "trackables" do
332
331
  before :each do
333
332
  @comment.update_attributes(:title => "Test2") # version == 2
334
333
  @comment.update_attributes(:title => "Test3") # version == 3
335
334
  @comment.update_attributes(:title => "Test4") # version == 4
336
335
  end
337
-
336
+
338
337
  describe "undo" do
339
338
  it "should recognize :from, :to options" do
340
339
  @comment.undo! @user, :from => 4, :to => 2
341
340
  @comment.title.should == "test"
342
341
  end
343
-
342
+
344
343
  it "should recognize parameter as version number" do
345
344
  @comment.undo! @user, 3
346
-
347
345
  @comment.title.should == "Test2"
348
346
  end
349
-
347
+
350
348
  it "should undo last version when no parameter is specified" do
351
349
  @comment.undo! @user
352
350
  @comment.title.should == "Test3"
353
351
  end
354
-
352
+
355
353
  it "should recognize :last options" do
356
354
  @comment.undo! @user, :last => 2
357
355
  @comment.title.should == "Test2"
358
356
  end
359
357
  end
360
-
358
+
361
359
  describe "redo" do
362
360
  before :each do
363
361
  @comment.update_attributes(:title => "Test5")
364
362
  end
365
-
363
+
366
364
  it "should recognize :from, :to options" do
367
365
  @comment.redo! @user, :from => 2, :to => 4
368
366
  @comment.title.should == "Test4"
369
367
  end
370
-
368
+
371
369
  it "should recognize parameter as version number" do
372
370
  @comment.redo! @user, 2
373
371
  @comment.title.should == "Test2"
374
372
  end
375
-
373
+
376
374
  it "should redo last version when no parameter is specified" do
377
375
  @comment.redo! @user
378
376
  @comment.title.should == "Test5"
379
377
  end
380
-
378
+
381
379
  it "should recognize :last options" do
382
380
  @comment.redo! @user, :last => 1
383
381
  @comment.title.should == "Test5"
data/spec/spec_helper.rb CHANGED
@@ -12,7 +12,7 @@ RSpec.configure do |config|
12
12
  config.before(:suite) do
13
13
  DatabaseCleaner.strategy = :truncation
14
14
  end
15
-
15
+
16
16
  config.after(:each) do
17
17
  DatabaseCleaner.clean
18
18
  end
@@ -7,7 +7,7 @@ describe Mongoid::History::Trackable do
7
7
  include Mongoid::History::Trackable
8
8
  end
9
9
  end
10
-
10
+
11
11
  after :each do
12
12
  Mongoid::History.trackable_classes = nil
13
13
  Mongoid::History.trackable_class_options = nil
@@ -16,19 +16,19 @@ describe Mongoid::History::Trackable do
16
16
  it "should have #track_history" do
17
17
  MyModel.should respond_to :track_history
18
18
  end
19
-
19
+
20
20
  it "should append trackable_classes ONLY when #track_history is called" do
21
21
  Mongoid::History.trackable_classes.should be_blank
22
22
  MyModel.track_history
23
23
  Mongoid::History.trackable_classes.should == [MyModel]
24
24
  end
25
-
25
+
26
26
  it "should append trackable_class_options ONLY when #track_history is called" do
27
27
  Mongoid::History.trackable_class_options.should be_blank
28
28
  MyModel.track_history
29
29
  Mongoid::History.trackable_class_options.keys.should == [:my_model]
30
30
  end
31
-
31
+
32
32
  describe "#track_history" do
33
33
  before :each do
34
34
  class MyModel
@@ -36,7 +36,7 @@ describe Mongoid::History::Trackable do
36
36
  include Mongoid::History::Trackable
37
37
  track_history
38
38
  end
39
-
39
+
40
40
  @expected_option = {
41
41
  :on => :all,
42
42
  :modifier_field => :modifier,
@@ -44,23 +44,24 @@ describe Mongoid::History::Trackable do
44
44
  :scope => :my_model,
45
45
  :except => ["created_at", "updated_at", "version", "modifier_id", "_id", "id"],
46
46
  :track_create => false,
47
+ :track_update => true,
47
48
  :track_destroy => false,
48
49
  }
49
50
  end
50
-
51
+
51
52
  after :each do
52
53
  Mongoid::History.trackable_classes = nil
53
54
  Mongoid::History.trackable_class_options = nil
54
55
  end
55
-
56
+
56
57
  it "should have default options" do
57
58
  Mongoid::History.trackable_class_options[:my_model].should == @expected_option
58
59
  end
59
-
60
+
60
61
  it "should define callback function #track_update" do
61
62
  MyModel.new.private_methods.collect(&:to_sym).should include(:track_update)
62
63
  end
63
-
64
+
64
65
  it "should define callback function #track_create" do
65
66
  MyModel.new.private_methods.collect(&:to_sym).should include(:track_create)
66
67
  end
@@ -74,17 +75,17 @@ describe Mongoid::History::Trackable do
74
75
  end
75
76
 
76
77
  context "track_history" do
77
-
78
+
78
79
  it "should be enabled on the current thread" do
79
80
  MyModel.new.track_history?.should == true
80
81
  end
81
-
82
+
82
83
  it "should be disabled within disable_tracking" do
83
84
  MyModel.disable_tracking do
84
85
  MyModel.new.track_history?.should == false
85
86
  end
86
87
  end
87
-
88
+
88
89
  it "should be rescued if an exception occurs" do
89
90
  begin
90
91
  MyModel.disable_tracking do
@@ -94,20 +95,20 @@ describe Mongoid::History::Trackable do
94
95
  end
95
96
  MyModel.new.track_history?.should == true
96
97
  end
97
-
98
+
98
99
  it "should be disabled only for the class that calls disable_tracking" do
99
100
  class MyModel2
100
101
  include Mongoid::Document
101
102
  include Mongoid::History::Trackable
102
103
  track_history
103
104
  end
104
-
105
+
105
106
  MyModel.disable_tracking do
106
107
  MyModel2.new.track_history?.should == true
107
- end
108
+ end
108
109
  end
109
-
110
+
110
111
  end
111
-
112
+
112
113
  end
113
114
  end
data/spec/tracker_spec.rb CHANGED
@@ -6,11 +6,11 @@ describe Mongoid::History::Tracker do
6
6
  include Mongoid::History::Tracker
7
7
  end
8
8
  end
9
-
9
+
10
10
  after :each do
11
11
  Mongoid::History.tracker_class_name = nil
12
12
  end
13
-
13
+
14
14
  it "should set tracker_class_name when included" do
15
15
  Mongoid::History.tracker_class_name.should == :my_tracker
16
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-history
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,12 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-07-12 00:00:00.000000000 -07:00
14
- default_executable:
13
+ date: 2011-08-30 00:00:00.000000000Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: easy_diff
18
- requirement: &2155948740 !ruby/object:Gem::Requirement
17
+ requirement: &33065620 !ruby/object:Gem::Requirement
19
18
  none: false
20
19
  requirements:
21
20
  - - ! '>='
@@ -23,21 +22,32 @@ dependencies:
23
22
  version: '0'
24
23
  type: :runtime
25
24
  prerelease: false
26
- version_requirements: *2155948740
25
+ version_requirements: *33065620
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: mongoid
29
- requirement: &2155928240 !ruby/object:Gem::Requirement
28
+ requirement: &33065000 !ruby/object:Gem::Requirement
30
29
  none: false
31
30
  requirements:
32
- - - ! '>='
31
+ - - ~>
33
32
  - !ruby/object:Gem::Version
34
- version: 2.0.2
33
+ version: '2.0'
35
34
  type: :runtime
36
35
  prerelease: false
37
- version_requirements: *2155928240
36
+ version_requirements: *33065000
37
+ - !ruby/object:Gem::Dependency
38
+ name: bson_ext
39
+ requirement: &33064420 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: 1.3.1
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *33064420
38
48
  - !ruby/object:Gem::Dependency
39
49
  name: rspec
40
- requirement: &2155923360 !ruby/object:Gem::Requirement
50
+ requirement: &33063880 !ruby/object:Gem::Requirement
41
51
  none: false
42
52
  requirements:
43
53
  - - ~>
@@ -45,10 +55,10 @@ dependencies:
45
55
  version: 2.3.0
46
56
  type: :development
47
57
  prerelease: false
48
- version_requirements: *2155923360
58
+ version_requirements: *33063880
49
59
  - !ruby/object:Gem::Dependency
50
60
  name: yard
51
- requirement: &2155921300 !ruby/object:Gem::Requirement
61
+ requirement: &33063360 !ruby/object:Gem::Requirement
52
62
  none: false
53
63
  requirements:
54
64
  - - ~>
@@ -56,10 +66,10 @@ dependencies:
56
66
  version: 0.6.0
57
67
  type: :development
58
68
  prerelease: false
59
- version_requirements: *2155921300
69
+ version_requirements: *33063360
60
70
  - !ruby/object:Gem::Dependency
61
71
  name: bundler
62
- requirement: &2155911700 !ruby/object:Gem::Requirement
72
+ requirement: &33062780 !ruby/object:Gem::Requirement
63
73
  none: false
64
74
  requirements:
65
75
  - - ~>
@@ -67,10 +77,10 @@ dependencies:
67
77
  version: 1.0.0
68
78
  type: :development
69
79
  prerelease: false
70
- version_requirements: *2155911700
80
+ version_requirements: *33062780
71
81
  - !ruby/object:Gem::Dependency
72
82
  name: jeweler
73
- requirement: &2155908240 !ruby/object:Gem::Requirement
83
+ requirement: &33062260 !ruby/object:Gem::Requirement
74
84
  none: false
75
85
  requirements:
76
86
  - - ~>
@@ -78,10 +88,10 @@ dependencies:
78
88
  version: 1.5.2
79
89
  type: :development
80
90
  prerelease: false
81
- version_requirements: *2155908240
91
+ version_requirements: *33062260
82
92
  - !ruby/object:Gem::Dependency
83
93
  name: rcov
84
- requirement: &2155905900 !ruby/object:Gem::Requirement
94
+ requirement: &33061660 !ruby/object:Gem::Requirement
85
95
  none: false
86
96
  requirements:
87
97
  - - ! '>='
@@ -89,10 +99,10 @@ dependencies:
89
99
  version: '0'
90
100
  type: :development
91
101
  prerelease: false
92
- version_requirements: *2155905900
102
+ version_requirements: *33061660
93
103
  - !ruby/object:Gem::Dependency
94
104
  name: reek
95
- requirement: &2152407320 !ruby/object:Gem::Requirement
105
+ requirement: &33061160 !ruby/object:Gem::Requirement
96
106
  none: false
97
107
  requirements:
98
108
  - - ~>
@@ -100,10 +110,10 @@ dependencies:
100
110
  version: 1.2.8
101
111
  type: :development
102
112
  prerelease: false
103
- version_requirements: *2152407320
113
+ version_requirements: *33061160
104
114
  - !ruby/object:Gem::Dependency
105
115
  name: roodi
106
- requirement: &2152406080 !ruby/object:Gem::Requirement
116
+ requirement: &33060680 !ruby/object:Gem::Requirement
107
117
  none: false
108
118
  requirements:
109
119
  - - ~>
@@ -111,10 +121,10 @@ dependencies:
111
121
  version: 2.1.0
112
122
  type: :development
113
123
  prerelease: false
114
- version_requirements: *2152406080
124
+ version_requirements: *33060680
115
125
  - !ruby/object:Gem::Dependency
116
126
  name: database_cleaner
117
- requirement: &2152405440 !ruby/object:Gem::Requirement
127
+ requirement: &33060200 !ruby/object:Gem::Requirement
118
128
  none: false
119
129
  requirements:
120
130
  - - ! '>='
@@ -122,7 +132,7 @@ dependencies:
122
132
  version: '0'
123
133
  type: :development
124
134
  prerelease: false
125
- version_requirements: *2152405440
135
+ version_requirements: *33060200
126
136
  description: ! "In frustration of Mongoid::Versioning, I created this plugin for tracking
127
137
  historical changes for any document, including embedded ones. It achieves this by
128
138
  storing all history tracks in a single collection that you define. (See Usage for
@@ -159,7 +169,6 @@ files:
159
169
  - spec/spec_helper.rb
160
170
  - spec/trackable_spec.rb
161
171
  - spec/tracker_spec.rb
162
- has_rdoc: true
163
172
  homepage: http://github.com/aq1018/mongoid-history
164
173
  licenses:
165
174
  - MIT
@@ -175,7 +184,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
175
184
  version: '0'
176
185
  segments:
177
186
  - 0
178
- hash: -4357186795392850631
187
+ hash: -4230519887588344232
179
188
  required_rubygems_version: !ruby/object:Gem::Requirement
180
189
  none: false
181
190
  requirements:
@@ -184,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
193
  version: '0'
185
194
  requirements: []
186
195
  rubyforge_project:
187
- rubygems_version: 1.6.2
196
+ rubygems_version: 1.8.6
188
197
  signing_key:
189
198
  specification_version: 3
190
199
  summary: history tracking, auditing, undo, redo for mongoid