mongoid-history 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -103,6 +103,11 @@ Here is a quick example on how to use this plugin. For more details, please look
103
103
 
104
104
  # undelete post
105
105
  post.undo! @user
106
+
107
+ # disable tracking for comments within a block
108
+ Comment.disable_tracking do
109
+ comment.update_attributes(:title => "Test 3")
110
+ end
106
111
 
107
112
  == Contributing to mongoid-history
108
113
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -4,6 +4,6 @@ require File.expand_path(File.dirname(__FILE__) + '/mongoid/history')
4
4
  require File.expand_path(File.dirname(__FILE__) + '/mongoid/history/tracker')
5
5
  require File.expand_path(File.dirname(__FILE__) + '/mongoid/history/trackable')
6
6
 
7
- Mongoid::History.modifer_class_name = "User"
7
+ Mongoid::History.modifier_class_name = "User"
8
8
  Mongoid::History.trackable_classes = []
9
- Mongoid::History.trackable_class_options = {}
9
+ Mongoid::History.trackable_class_options = {}
@@ -3,11 +3,11 @@ module Mongoid
3
3
  mattr_accessor :tracker_class_name
4
4
  mattr_accessor :trackable_classes
5
5
  mattr_accessor :trackable_class_options
6
- mattr_accessor :modifer_class_name
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
11
11
 
12
12
  end
13
- end
13
+ end
@@ -33,7 +33,7 @@ module Mongoid::History
33
33
  end
34
34
 
35
35
  field options[:version_field].to_sym, :type => Integer
36
- referenced_in options[:modifier_field].to_sym, :class_name => Mongoid::History.modifer_class_name
36
+ referenced_in options[:modifier_field].to_sym, :class_name => Mongoid::History.modifier_class_name
37
37
 
38
38
  include InstanceMethods
39
39
  extend SingletonMethods
@@ -49,17 +49,24 @@ module Mongoid::History
49
49
  Mongoid::History.trackable_classes << self
50
50
  Mongoid::History.trackable_class_options ||= {}
51
51
  Mongoid::History.trackable_class_options[model_name] = options
52
- Thread.current[:mongoid_history_trackable_enabled] = true
53
52
  end
54
-
53
+
55
54
  def track_history?
56
- !!Thread.current[:mongoid_history_trackable_enabled]
55
+ enabled = Thread.current[track_history_flag]
56
+ enabled.nil? ? true : enabled
57
57
  end
58
58
 
59
59
  def disable_tracking(&block)
60
- Thread.current[:mongoid_history_trackable_enabled] = false
61
- yield
62
- Thread.current[:mongoid_history_trackable_enabled] = true
60
+ begin
61
+ Thread.current[track_history_flag] = false
62
+ yield
63
+ ensure
64
+ Thread.current[track_history_flag] = true
65
+ end
66
+ end
67
+
68
+ def track_history_flag
69
+ "mongoid_history_#{self.name.underscore}_trackable_enabled".to_sym
63
70
  end
64
71
  end
65
72
 
@@ -12,7 +12,7 @@ module Mongoid::History
12
12
  field :version, :type => Integer
13
13
  field :action, :type => String
14
14
  field :scope, :type => String
15
- referenced_in :modifier, :class_name => Mongoid::History.modifer_class_name
15
+ referenced_in :modifier, :class_name => Mongoid::History.modifier_class_name
16
16
 
17
17
  Mongoid::History.tracker_class_name = self.name.tableize.singularize.to_sym
18
18
  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.0"
8
+ s.version = "0.1.1"
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-05-13}
11
+ s.authors = [%q{Aaron Qian}, %q{Justin Grimes}]
12
+ s.date = %q{2011-05-25}
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.5.3}
41
+ s.licenses = [%q{MIT}]
42
+ s.require_paths = [%q{lib}]
43
+ s.rubygems_version = %q{1.8.3}
44
44
  s.summary = %q{history tracking, auditing, undo, redo for mongoid}
45
45
  s.test_files = [
46
46
  "spec/integration/integration_spec.rb",
@@ -72,5 +72,42 @@ describe Mongoid::History::Trackable do
72
72
  it "should define #history_trackable_options" do
73
73
  MyModel.history_trackable_options.should == @expected_option
74
74
  end
75
+
76
+ context "track_history" do
77
+
78
+ it "should be enabled on the current thread" do
79
+ MyModel.new.track_history?.should == true
80
+ end
81
+
82
+ it "should be disabled within disable_tracking" do
83
+ MyModel.disable_tracking do
84
+ MyModel.new.track_history?.should == false
85
+ end
86
+ end
87
+
88
+ it "should be rescued if an exception occurs" do
89
+ begin
90
+ MyModel.disable_tracking do
91
+ raise "exception"
92
+ end
93
+ rescue
94
+ end
95
+ MyModel.new.track_history?.should == true
96
+ end
97
+
98
+ it "should be disabled only for the class that calls disable_tracking" do
99
+ class MyModel2
100
+ include Mongoid::Document
101
+ include Mongoid::History::Trackable
102
+ track_history
103
+ end
104
+
105
+ MyModel.disable_tracking do
106
+ MyModel2.new.track_history?.should == true
107
+ end
108
+ end
109
+
110
+ end
111
+
75
112
  end
76
113
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mongoid-history
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Aaron Qian
@@ -11,8 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-05-13 00:00:00 -07:00
15
- default_executable:
14
+ date: 2011-05-25 00:00:00 Z
16
15
  dependencies:
17
16
  - !ruby/object:Gem::Dependency
18
17
  name: easy_diff
@@ -156,7 +155,6 @@ files:
156
155
  - spec/spec_helper.rb
157
156
  - spec/trackable_spec.rb
158
157
  - spec/tracker_spec.rb
159
- has_rdoc: true
160
158
  homepage: http://github.com/aq1018/mongoid-history
161
159
  licenses:
162
160
  - MIT
@@ -170,7 +168,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
168
  requirements:
171
169
  - - ">="
172
170
  - !ruby/object:Gem::Version
173
- hash: -1260875336228097140
171
+ hash: 2593170872748444504
174
172
  segments:
175
173
  - 0
176
174
  version: "0"
@@ -183,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
181
  requirements: []
184
182
 
185
183
  rubyforge_project:
186
- rubygems_version: 1.5.3
184
+ rubygems_version: 1.8.3
187
185
  signing_key:
188
186
  specification_version: 3
189
187
  summary: history tracking, auditing, undo, redo for mongoid