mongoid-history 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -2,3 +2,9 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
+ - 1.9.3
6
+ - ruby-head
7
+ - jruby
8
+ - rbx
9
+ - ree
10
+
data/CHANGELOG.md ADDED
@@ -0,0 +1,33 @@
1
+ 0.2.4 (8/21/2012)
2
+ -----------------
3
+
4
+ * [#38](https://github.com/aq1018/mongoid-history/pull/38) Fix: Allow sub-models to be tracked by using `collection_name` as the scope - [@acant](https://github.com/acant).
5
+ * [#35](https://github.com/aq1018/mongoid-history/pull/35): Fix: sweeper references record of change, not the record changed - [@dblock](https://github.com/dblock).
6
+
7
+ 0.2.3 (4/20/2012)
8
+ -----------------
9
+
10
+ * [#23](https://github.com/aq1018/mongoid-history/pull/34): Updated `Trackable::association_hash` to write through parent - [@tcopple](https://github.com/tcopple).
11
+ * Fix: `Trackable::association_hash` nil meta value call - [@tcopple](https://github.com/tcopple).
12
+ * [#27](https://github.com/aq1018/mongoid-history/pull/27): Added support for re-creation of destroyed embedded documents - [@erlingwl](https://github.com/erlingwl)
13
+
14
+ 0.1.7 (12/9/2011)
15
+ -----------------
16
+
17
+ * Fix: tracking `false` values - [@gottfrois](https://github.com/gottfrois).
18
+ * Use a mongoid observer and controller `around_filter` to pick up modifying user from controller - [@bensymonds](https://github.com/bensymonds).
19
+ * More flexible dependency on mongoid - [@sarcilav](https://github.com/sarcilav).
20
+ * Fix: tracking broken in a multithreaded environment - [@dblock](https://github.com/dblock).
21
+
22
+ 0.1.0 (5/13/2011)
23
+ -----------------
24
+
25
+ * Added support for `destroy` - [@dblock](https://github.com/dblock).
26
+ * Added undo and redo - [@aq1018](https://github.com/aq1018).
27
+ * Added support for temporarily disabling history tracking - [@aq1018](https://github.com/aq1018).
28
+ * Record modifier for undo and redo actions - [@aq1018](https://github.com/aq1018).
29
+
30
+ 0.0.1 (3/4/2011)
31
+ ----------------
32
+
33
+ * Intial public release - [@aq1018](https://github.com/aq1018).
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source "http://rubygems.org"
3
3
  gem "easy_diff"
4
4
  gem "mongoid", ">= 2.0.0"
5
5
 
6
- group :development do
6
+ group :test do
7
7
  gem "bson_ext"
8
8
  gem "rspec"
9
9
  gem "yard"
data/README.md CHANGED
@@ -4,16 +4,16 @@ mongoid-history
4
4
  [![Build Status](https://secure.travis-ci.org/aq1018/mongoid-history.png?branch=master)](http://travis-ci.org/aq1018/mongoid-history) [![Dependency Status](https://gemnasium.com/aq1018/mongoid-history.png?travis)](https://gemnasium.com/aq1018/mongoid-history)
5
5
 
6
6
 
7
- 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.
7
+ 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. 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.
8
8
 
9
- 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.
9
+ This plugin also 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.
10
10
 
11
11
  Note
12
12
  ----
13
13
 
14
14
  **Please don't use 0.1.8 and 0.2.0.**
15
15
 
16
- They won't work in Rails because there was an error in the sweeper that causes history tracker creation to fail. Upgrade to version 0.2.1 instead as it is able to track history on `embeds_one` documents correctly.
16
+ These versions won't work in Rails because there was an error in the sweeper that causes history tracker creation to fail. Upgrade to version 0.2.1 instead as it's able to track history on `embeds_one` documents correctly.
17
17
 
18
18
  **Refactor in progress**
19
19
 
@@ -22,7 +22,7 @@ If you feel brave, you can look at the `refactor` branch and get a feel of what'
22
22
  Upgrading from mongoid-history-0.1.x to >= 0.2
23
23
  ------------------------------------------------
24
24
 
25
- If you are upgrade from 0.1.x to version 0.2.x, you need to run the following code **before** you start to use the 0.2.x. This is due to changes in `Mongoid::History::Tracker`'s `association_chain` field.
25
+ If you are upgrading from 0.1.x to version 0.2.x and have existing data, run the following code **before** you start using 0.2.x. This is due to changes in `Mongoid::History::Tracker`'s `association_chain` field.
26
26
 
27
27
  ```ruby
28
28
  Mongoid::History.tracker_class.all.each do |tracker|
@@ -36,16 +36,7 @@ end
36
36
  Install
37
37
  -------
38
38
 
39
- Currently this gem supports ruby 1.9.x only. ruby 1.8.7, ree and rubinus are not working right now.
40
-
41
- ```
42
- gem install mongoid-history
43
- ```
44
-
45
- Rails 3
46
- -------
47
-
48
- In your Gemfile:
39
+ This gem supports Ruby 1.8.7, 1.9.2, 1.9.3, JRuby, Rubinius and REE. Add it to your `Gemfile` or run `gem install mongoid-history`.
49
40
 
50
41
  ```ruby
51
42
  gem 'mongoid-history'
@@ -54,9 +45,9 @@ gem 'mongoid-history'
54
45
  Usage
55
46
  -----
56
47
 
57
- Here is a quick example on how to use this plugin. For more details, please look at spec/integration/integration_spec.rb. It offers more detailed examples on how to use `Mongoid::History`.
48
+ Here is a quick example on how to use this plugin.
58
49
 
59
- **Create a History Tracker**
50
+ **Create a history tracker**
60
51
 
61
52
  Create a new class to track histories. All histories are stored in this tracker. The name of the class can be anything you like. The only requirement is that it includes `Mongoid::History::Tracker`
62
53
 
@@ -67,12 +58,11 @@ class HistoryTracker
67
58
  end
68
59
  ```
69
60
 
70
- **Set Tracker Class Name**
71
-
61
+ **Set tracker class name**
72
62
 
73
- You should manually set the tracker class name to make sure your tracker can be found and loaded properly. You can skip this step if you manually require your tracker before using any trackables. If you don't know what I'm talking about, then you should just follow the example below.
63
+ You should manually set the tracker class name to make sure your tracker can be found and loaded properly. You can skip this step if you manually require your tracker before using any trackables.
74
64
 
75
- Here is an example of setting the tracker class name using a rails initializer
65
+ The following example sets the tracker class name using a Rails initializer.
76
66
 
77
67
  ```ruby
78
68
  # config/initializers/mongoid-history.rb
@@ -83,9 +73,9 @@ Mongoid::History.tracker_class_name = :history_tracker
83
73
 
84
74
  **Set `#current_user` method name**
85
75
 
86
- You can set name of method which returns currently logged in user if you don't want to set modifier explicitly on every update.
76
+ You can set the name of the method that returns currently logged in user if you don't want to set `modifier` explicitly on every update.
87
77
 
88
- Here is an example of setting the current_user_method using a rails initializer
78
+ The following example sets the `current_user_method` using a Rails initializer
89
79
 
90
80
  ```ruby
91
81
  # config/initializers/mongoid-history.rb
@@ -94,25 +84,25 @@ Here is an example of setting the current_user_method using a rails initializer
94
84
  Mongoid::History.current_user_method = :current_user
95
85
  ```
96
86
 
97
- When current_user_method is set mongoid-history call this method on each update and set it as modifier
87
+ When `current_user_method` is set, mongoid-history will invoke this method on each update and set its result as the instance modifier.
98
88
 
99
89
  ```ruby
100
- # Assume that current_user return #<User _id: 1>
90
+ # assume that current_user return #<User _id: 1>
101
91
  post = Post.first
102
92
  post.update_attributes(:title => 'New title')
103
93
 
104
94
  post.history_tracks.last.modifier #=> #<User _id: 1>
105
95
  ```
106
96
 
107
- ***Create Trackable classes and objects***
97
+ **Create trackable classes and objects**
108
98
 
109
99
  ```ruby
110
100
  class Post
111
101
  include Mongoid::Document
112
102
  include Mongoid::Timestamps
113
103
 
114
- # History tracking all Post Documents
115
- # Note: Tracking will not work until #track_history is invoked
104
+ # history tracking all Post documents
105
+ # note: tracking will not work until #track_history is invoked
116
106
  include Mongoid::History::Trackable
117
107
 
118
108
  field :title
@@ -120,32 +110,32 @@ class Post
120
110
  field :rating
121
111
  embeds_many :comments
122
112
 
123
- # Telling Mongoid::History how you want to track
124
- track_history :on => [:title, :body], # I want to track title and body fields only. Default is :all
125
- :modifier_field => :modifier, # Adds "referened_in :modifier" to track who made the change. Default is :modifier
126
- :version_field => :version, # Adds "field :version, :type => Integer" to track current version. Default is :version
127
- :track_create => false, # Do you want to track document creation? Default is false
128
- :track_update => true, # Do you want to track document updates? Default is true
129
- :track_destroy => false, # Do you want to track document destruction? Default is false
113
+ # telling Mongoid::History how you want to track changes
114
+ track_history :on => [:title, :body], # track title and body fields only, default is :all
115
+ :modifier_field => :modifier, # adds "referenced_in :modifier" to track who made the change, default is :modifier
116
+ :version_field => :version, # adds "field :version, :type => Integer" to track current version, default is :version
117
+ :track_create => false, # track document creation, default is false
118
+ :track_update => true, # track document updates, default is true
119
+ :track_destroy => false, # track document destruction, default is false
130
120
  end
131
121
 
132
122
  class Comment
133
123
  include Mongoid::Document
134
124
  include Mongoid::Timestamps
135
125
 
136
- # Declare that we want to track comments
126
+ # declare that we want to track comments
137
127
  include Mongoid::History::Trackable
138
128
 
139
129
  field :title
140
130
  field :body
141
131
  embedded_in :post, :inverse_of => :comments
142
132
 
143
- # Track title and body for all comments, scope it to post (the parent)
144
- # Also track creation and destruction
133
+ # track title and body for all comments, scope it to post (the parent)
134
+ # also track creation and destruction
145
135
  track_history :on => [:title, :body], :scope => :post, :track_create => true, :track_destroy => true
146
136
  end
147
137
 
148
- # The modifier can be specified as well
138
+ # the modifier class
149
139
  class User
150
140
  include Mongoid::Document
151
141
  include Mongoid::Timestamps
@@ -193,21 +183,24 @@ Comment.disable_tracking do
193
183
  comment.update_attributes(:title => "Test 3")
194
184
  end
195
185
  ```
186
+ For more examples, check out [spec/integration/integration_spec.rb](https://github.com/aq1018/mongoid-history/blob/master/spec/integration/integration_spec.rb).
196
187
 
197
188
  Contributing to mongoid-history
198
189
  -------------------------------
199
190
 
200
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
201
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
202
- * Fork the project
203
- * Start a feature/bugfix branch
204
- * Commit and push until you are happy with your contribution
205
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
206
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
191
+ * Check out the latest code to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
192
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
193
+ * Fork the project.
194
+ * Create a feature/bugfix branch.
195
+ * Commit and push until you are happy with your changes.
196
+ * Make sure to add tests.
197
+ * Update the CHANGELOG for the next release.
198
+ * Try not to mess with the Rakefile or version.
199
+ * Make a pull request.
207
200
 
208
201
  Copyright
209
202
  ---------
210
203
 
211
- Copyright (c) 2011 Aaron Qian. See LICENSE.txt for
212
- further details.
204
+ Copyright (c) 2011-2012 Aaron Qian. MIT License.
205
+ See [LICENSE.txt](https://github.com/aq1018/mongoid-history/blob/master/LICENSE.txt) for further details.
213
206
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
@@ -31,8 +31,8 @@ module Mongoid::History
31
31
 
32
32
  def before_create(track)
33
33
  modifier_field = track.trackable.history_trackable_options[:modifier_field]
34
- modifier = track.send modifier_field
35
- track.send "#{modifier_field}=", current_user unless modifier
34
+ modifier = track.trackable.send modifier_field
35
+ track.modifier = current_user unless modifier
36
36
  end
37
37
 
38
38
  def current_user
@@ -4,13 +4,13 @@ module Mongoid::History
4
4
 
5
5
  module ClassMethods
6
6
  def track_history(options={})
7
- model_name = self.name.tableize.singularize.to_sym
7
+ scope_name = self.collection_name.singularize.to_sym
8
8
  default_options = {
9
9
  :on => :all,
10
10
  :except => [:created_at, :updated_at],
11
11
  :modifier_field => :modifier,
12
12
  :version_field => :version,
13
- :scope => model_name,
13
+ :scope => scope_name,
14
14
  :track_create => false,
15
15
  :track_update => true,
16
16
  :track_destroy => false,
@@ -47,7 +47,7 @@ module Mongoid::History
47
47
  before_destroy :track_destroy if options[:track_destroy]
48
48
 
49
49
  Mongoid::History.trackable_class_options ||= {}
50
- Mongoid::History.trackable_class_options[model_name] = options
50
+ Mongoid::History.trackable_class_options[scope_name] = options
51
51
  end
52
52
 
53
53
  def track_history?
@@ -133,18 +133,18 @@ module Mongoid::History
133
133
  end
134
134
 
135
135
  def association_hash(node=self)
136
- # get all reflections of embedded_in association metadata
137
- # and find the first association that matches _parent.
138
- if node._parent
139
- meta = node.reflect_on_all_associations(:embedded_in).find do |meta|
140
- node._parent == node.send(meta.key)
141
- end
142
136
 
143
- inverse = node._parent.reflect_on_association(meta.inverse) if meta
137
+ # We prefer to look up associations through the parent record because
138
+ # we're assured, through the object creation, it'll exist. Whereas we're not guarenteed
139
+ # the child to parent (embedded_in, belongs_to) relation will be defined
140
+ if node._parent
141
+ meta = _parent.relations.values.select do |relation|
142
+ relation.class_name == node.class.to_s
143
+ end.first
144
144
  end
145
145
 
146
146
  # if root node has no meta, and should use class name instead
147
- name = meta ? meta.inverse.to_s : node.class.name
147
+ name = meta ? meta.key.to_s : node.class.name
148
148
 
149
149
  { 'name' => name, 'id' => node.id}
150
150
  end
@@ -246,9 +246,8 @@ module Mongoid::History
246
246
 
247
247
  module SingletonMethods
248
248
  def history_trackable_options
249
- @history_trackable_options ||= Mongoid::History.trackable_class_options[self.name.tableize.singularize.to_sym]
249
+ @history_trackable_options ||= Mongoid::History.trackable_class_options[self.collection_name.singularize.to_sym]
250
250
  end
251
251
  end
252
-
253
252
  end
254
253
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "mongoid-history"
8
- s.version = "0.2.3"
8
+ s.version = "0.2.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", "Justin Grimes"]
12
- s.date = "2012-04-20"
12
+ s.date = "2012-08-21"
13
13
  s.description = "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.\n\n 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."
14
14
  s.email = ["aq1018@gmail.com", "justin.mgrimes@gmail.com"]
15
15
  s.extra_rdoc_files = [
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  ".document",
21
21
  ".rspec",
22
22
  ".travis.yml",
23
+ "CHANGELOG.md",
23
24
  "Gemfile",
24
25
  "LICENSE.txt",
25
26
  "README.md",
@@ -33,13 +34,15 @@ Gem::Specification.new do |s|
33
34
  "mongoid-history.gemspec",
34
35
  "spec/integration/integration_spec.rb",
35
36
  "spec/spec_helper.rb",
37
+ "spec/support/database_cleaner.rb",
38
+ "spec/support/mongoid.rb",
36
39
  "spec/trackable_spec.rb",
37
40
  "spec/tracker_spec.rb"
38
41
  ]
39
42
  s.homepage = "http://github.com/aq1018/mongoid-history"
40
43
  s.licenses = ["MIT"]
41
44
  s.require_paths = ["lib"]
42
- s.rubygems_version = "1.8.19"
45
+ s.rubygems_version = "1.8.24"
43
46
  s.summary = "history tracking, auditing, undo, redo for mongoid"
44
47
 
45
48
  if s.respond_to? :specification_version then
@@ -48,31 +51,13 @@ Gem::Specification.new do |s|
48
51
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
52
  s.add_runtime_dependency(%q<easy_diff>, [">= 0"])
50
53
  s.add_runtime_dependency(%q<mongoid>, [">= 2.0.0"])
51
- s.add_development_dependency(%q<bson_ext>, [">= 0"])
52
- s.add_development_dependency(%q<rspec>, [">= 0"])
53
- s.add_development_dependency(%q<yard>, [">= 0"])
54
- s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
55
- s.add_development_dependency(%q<jeweler>, [">= 0"])
56
- s.add_development_dependency(%q<database_cleaner>, [">= 0"])
57
54
  else
58
55
  s.add_dependency(%q<easy_diff>, [">= 0"])
59
56
  s.add_dependency(%q<mongoid>, [">= 2.0.0"])
60
- s.add_dependency(%q<bson_ext>, [">= 0"])
61
- s.add_dependency(%q<rspec>, [">= 0"])
62
- s.add_dependency(%q<yard>, [">= 0"])
63
- s.add_dependency(%q<bundler>, [">= 1.0.0"])
64
- s.add_dependency(%q<jeweler>, [">= 0"])
65
- s.add_dependency(%q<database_cleaner>, [">= 0"])
66
57
  end
67
58
  else
68
59
  s.add_dependency(%q<easy_diff>, [">= 0"])
69
60
  s.add_dependency(%q<mongoid>, [">= 2.0.0"])
70
- s.add_dependency(%q<bson_ext>, [">= 0"])
71
- s.add_dependency(%q<rspec>, [">= 0"])
72
- s.add_dependency(%q<yard>, [">= 0"])
73
- s.add_dependency(%q<bundler>, [">= 1.0.0"])
74
- s.add_dependency(%q<jeweler>, [">= 0"])
75
- s.add_dependency(%q<database_cleaner>, [">= 0"])
76
61
  end
77
62
  end
78
63
 
@@ -59,9 +59,11 @@ describe Mongoid::History do
59
59
  include Mongoid::Document
60
60
  include Mongoid::Timestamps
61
61
  include Mongoid::History::Trackable
62
+
63
+ belongs_to :updated_by, :class_name => "User"
62
64
 
63
65
  field :title
64
- track_history :on => [:title], :scope => :post, :track_create => true, :track_destroy => true
66
+ track_history :on => [:title], :scope => :post, :track_create => true, :track_destroy => true, :modifier_field => :updated_by
65
67
  end
66
68
  end
67
69
 
@@ -188,9 +190,8 @@ describe Mongoid::History do
188
190
 
189
191
  it "should exclude defined options" do
190
192
  @user.update_attributes(:name => "Aaron2", :email => "aaronsnewemail@randomemail.com")
191
- @user.history_tracks.first.modified.should == {
192
- "name" => "Aaron2"
193
- }
193
+ @user.history_tracks.first.modified.keys.should include "name"
194
+ @user.history_tracks.first.modified.keys.should_not include "email"
194
195
  end
195
196
  end
196
197
 
@@ -360,8 +361,15 @@ describe Mongoid::History do
360
361
 
361
362
  describe "embedded with cascading callbacks" do
362
363
  before(:each) do
363
- @tag_foo = @post.tags.create(:title => "foo", :modifier => @user)
364
- @tag_bar = @post.tags.create(:title => "bar", :modifier => @user)
364
+ Mongoid.instantiate_observers
365
+ Thread.current[:mongoid_history_sweeper_controller] = self
366
+ self.stub!(:current_user).and_return @user
367
+ @tag_foo = @post.tags.create(:title => "foo", :updated_by => @user)
368
+ @tag_bar = @post.tags.create(:title => "bar")
369
+ end
370
+
371
+ after(:each) do
372
+ Thread.current[:mongoid_history_sweeper_controller] = nil
365
373
  end
366
374
 
367
375
  it "should have cascaded the creation callbacks and set timestamps" do
@@ -382,6 +390,21 @@ describe Mongoid::History do
382
390
  @post.tags.count.should == 1
383
391
  @post.history_tracks.last.action.should == "destroy"
384
392
  end
393
+
394
+ it "should write relationship name for association_chain hiearchy instead of class name when using _destroy macro" do
395
+ update_hash = {"tags_attributes" => { "1234" => { "id" => @tag_foo.id, "_destroy" => "1"} } }
396
+ @post.update_attributes(update_hash)
397
+
398
+ # historically this would have evaluated to 'Tags' and an error would be thrown
399
+ # on any call that walked up the association_chain, e.g. 'trackable'
400
+ @tag_foo.history_tracks.last.association_chain.last["name"].should == "tags"
401
+ lambda{ @tag_foo.history_tracks.last.trackable }.should_not raise_error
402
+ end
403
+
404
+ it "should save modifier" do
405
+ @tag_foo.history_tracks.last.modifier.should eq @user
406
+ @tag_bar.history_tracks.last.modifier.should eq @user
407
+ end
385
408
  end
386
409
 
387
410
  describe "non-embedded" do
data/spec/spec_helper.rb CHANGED
@@ -1,23 +1,13 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- $LOAD_PATH.unshift(File.dirname(__FILE__))
3
2
 
4
- require 'rspec'
5
- require 'mongoid'
6
- require 'mongoid-history'
7
- require 'database_cleaner'
8
-
9
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
3
+ require 'rubygems'
4
+ require 'bundler/setup'
10
5
 
11
- RSpec.configure do |config|
12
- config.before(:suite) do
13
- DatabaseCleaner.strategy = :truncation
14
- end
6
+ Bundler.require :default, :test
15
7
 
16
- config.after(:each) do
17
- DatabaseCleaner.clean
18
- end
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each do |f|
9
+ require f
19
10
  end
20
11
 
21
- Mongoid.configure do |config|
22
- config.master = Mongo::Connection.new.db("mongoid-history")
23
- end
12
+ require 'mongoid-history'
13
+
@@ -0,0 +1,9 @@
1
+ RSpec.configure do |config|
2
+ config.before :suite do
3
+ DatabaseCleaner.strategy = :truncation
4
+ end
5
+ config.after :each do
6
+ DatabaseCleaner.clean
7
+ end
8
+ end
9
+
@@ -0,0 +1,11 @@
1
+ Mongoid.configure do |config|
2
+ config.master = Mongo::Connection.new.db("mongoid-history")
3
+ end
4
+
5
+ RSpec.configure do |config|
6
+ config.before :each do
7
+ Mongoid.observers = Mongoid::History::Sweeper
8
+ end
9
+ end
10
+
11
+
@@ -66,6 +66,21 @@ describe Mongoid::History::Trackable do
66
66
  MyModel.history_trackable_options.should == @expected_option
67
67
  end
68
68
 
69
+ context "sub-model" do
70
+ before :each do
71
+ class MySubModel < MyModel
72
+ end
73
+ end
74
+
75
+ it "should have default options" do
76
+ Mongoid::History.trackable_class_options[:my_model].should == @expected_option
77
+ end
78
+
79
+ it "should define #history_trackable_options" do
80
+ MySubModel.history_trackable_options.should == @expected_option
81
+ end
82
+ end
83
+
69
84
  context "track_history" do
70
85
 
71
86
  it "should be enabled on the current thread" do
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.2.3
4
+ version: 0.2.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-20 00:00:00.000000000 Z
13
+ date: 2012-08-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: easy_diff
@@ -44,102 +44,6 @@ dependencies:
44
44
  - - ! '>='
45
45
  - !ruby/object:Gem::Version
46
46
  version: 2.0.0
47
- - !ruby/object:Gem::Dependency
48
- name: bson_ext
49
- requirement: !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- type: :development
56
- prerelease: false
57
- version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
60
- - - ! '>='
61
- - !ruby/object:Gem::Version
62
- version: '0'
63
- - !ruby/object:Gem::Dependency
64
- name: rspec
65
- requirement: !ruby/object:Gem::Requirement
66
- none: false
67
- requirements:
68
- - - ! '>='
69
- - !ruby/object:Gem::Version
70
- version: '0'
71
- type: :development
72
- prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ! '>='
77
- - !ruby/object:Gem::Version
78
- version: '0'
79
- - !ruby/object:Gem::Dependency
80
- name: yard
81
- requirement: !ruby/object:Gem::Requirement
82
- none: false
83
- requirements:
84
- - - ! '>='
85
- - !ruby/object:Gem::Version
86
- version: '0'
87
- type: :development
88
- prerelease: false
89
- version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
- requirements:
92
- - - ! '>='
93
- - !ruby/object:Gem::Version
94
- version: '0'
95
- - !ruby/object:Gem::Dependency
96
- name: bundler
97
- requirement: !ruby/object:Gem::Requirement
98
- none: false
99
- requirements:
100
- - - ! '>='
101
- - !ruby/object:Gem::Version
102
- version: 1.0.0
103
- type: :development
104
- prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
- requirements:
108
- - - ! '>='
109
- - !ruby/object:Gem::Version
110
- version: 1.0.0
111
- - !ruby/object:Gem::Dependency
112
- name: jeweler
113
- requirement: !ruby/object:Gem::Requirement
114
- none: false
115
- requirements:
116
- - - ! '>='
117
- - !ruby/object:Gem::Version
118
- version: '0'
119
- type: :development
120
- prerelease: false
121
- version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
- requirements:
124
- - - ! '>='
125
- - !ruby/object:Gem::Version
126
- version: '0'
127
- - !ruby/object:Gem::Dependency
128
- name: database_cleaner
129
- requirement: !ruby/object:Gem::Requirement
130
- none: false
131
- requirements:
132
- - - ! '>='
133
- - !ruby/object:Gem::Version
134
- version: '0'
135
- type: :development
136
- prerelease: false
137
- version_requirements: !ruby/object:Gem::Requirement
138
- none: false
139
- requirements:
140
- - - ! '>='
141
- - !ruby/object:Gem::Version
142
- version: '0'
143
47
  description: ! "In frustration of Mongoid::Versioning, I created this plugin for tracking
144
48
  historical changes for any document, including embedded ones. It achieves this by
145
49
  storing all history tracks in a single collection that you define. (See Usage for
@@ -162,6 +66,7 @@ files:
162
66
  - .document
163
67
  - .rspec
164
68
  - .travis.yml
69
+ - CHANGELOG.md
165
70
  - Gemfile
166
71
  - LICENSE.txt
167
72
  - README.md
@@ -175,6 +80,8 @@ files:
175
80
  - mongoid-history.gemspec
176
81
  - spec/integration/integration_spec.rb
177
82
  - spec/spec_helper.rb
83
+ - spec/support/database_cleaner.rb
84
+ - spec/support/mongoid.rb
178
85
  - spec/trackable_spec.rb
179
86
  - spec/tracker_spec.rb
180
87
  homepage: http://github.com/aq1018/mongoid-history
@@ -192,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
192
99
  version: '0'
193
100
  segments:
194
101
  - 0
195
- hash: 4511174551660468698
102
+ hash: -172559448489131861
196
103
  required_rubygems_version: !ruby/object:Gem::Requirement
197
104
  none: false
198
105
  requirements:
@@ -201,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
108
  version: '0'
202
109
  requirements: []
203
110
  rubyforge_project:
204
- rubygems_version: 1.8.19
111
+ rubygems_version: 1.8.24
205
112
  signing_key:
206
113
  specification_version: 3
207
114
  summary: history tracking, auditing, undo, redo for mongoid