mongoid-history 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -73,7 +73,7 @@ module Mongoid::History
73
73
  def history_tracks
74
74
  @history_tracks ||= Mongoid::History.tracker_class.where(:scope => history_trackable_options[:scope], :association_chain => association_hash)
75
75
  end
76
-
76
+
77
77
  # undo :from => 1, :to => 5
78
78
  # undo 4
79
79
  # undo :last => 10
@@ -140,7 +140,7 @@ module Mongoid::History
140
140
  node._parent == node.send(meta.key)
141
141
  end
142
142
 
143
- inverse = node._parent.reflect_on_association(meta.inverse)
143
+ inverse = node._parent.reflect_on_association(meta.inverse) if meta
144
144
  end
145
145
 
146
146
  # if root node has no meta, and should use class name instead
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "mongoid-history"
8
- s.version = "0.2.2"
8
+ s.version = "0.2.3"
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-05"
12
+ s.date = "2012-04-20"
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 = [
@@ -39,7 +39,7 @@ Gem::Specification.new do |s|
39
39
  s.homepage = "http://github.com/aq1018/mongoid-history"
40
40
  s.licenses = ["MIT"]
41
41
  s.require_paths = ["lib"]
42
- s.rubygems_version = "1.8.15"
42
+ s.rubygems_version = "1.8.19"
43
43
  s.summary = "history tracking, auditing, undo, redo for mongoid"
44
44
 
45
45
  if s.respond_to? :specification_version then
@@ -17,6 +17,10 @@ describe Mongoid::History do
17
17
 
18
18
  embeds_many :comments
19
19
  embeds_one :section
20
+ embeds_many :tags, :cascade_callbacks => true
21
+
22
+ accepts_nested_attributes_for :tags, :allow_destroy => true
23
+
20
24
  track_history :on => [:title, :body], :track_destroy => true
21
25
  end
22
26
 
@@ -50,6 +54,15 @@ describe Mongoid::History do
50
54
  field :name
51
55
  track_history :except => [:email]
52
56
  end
57
+
58
+ class Tag
59
+ include Mongoid::Document
60
+ include Mongoid::Timestamps
61
+ include Mongoid::History::Trackable
62
+
63
+ field :title
64
+ track_history :on => [:title], :scope => :post, :track_create => true, :track_destroy => true
65
+ end
53
66
  end
54
67
 
55
68
  before :each do
@@ -114,7 +127,6 @@ describe Mongoid::History do
114
127
  @post.destroy
115
128
  @post.history_tracks.last.affected["title"].should == "Test"
116
129
  end
117
-
118
130
  end
119
131
 
120
132
  describe "on update non-embedded" do
@@ -177,7 +189,7 @@ describe Mongoid::History do
177
189
  it "should exclude defined options" do
178
190
  @user.update_attributes(:name => "Aaron2", :email => "aaronsnewemail@randomemail.com")
179
191
  @user.history_tracks.first.modified.should == {
180
- "name" => "Aaron2"
192
+ "name" => "Aaron2"
181
193
  }
182
194
  end
183
195
  end
@@ -346,6 +358,32 @@ describe Mongoid::History do
346
358
  end
347
359
  end
348
360
 
361
+ describe "embedded with cascading callbacks" do
362
+ before(:each) do
363
+ @tag_foo = @post.tags.create(:title => "foo", :modifier => @user)
364
+ @tag_bar = @post.tags.create(:title => "bar", :modifier => @user)
365
+ end
366
+
367
+ it "should have cascaded the creation callbacks and set timestamps" do
368
+ @tag_foo.created_at.should_not be_nil
369
+ @tag_foo.updated_at.should_not be_nil
370
+ end
371
+
372
+ it "should allow an update through the parent model" do
373
+ update_hash = { "post" => { "tags_attributes" => { "1234" => { "id" => @tag_bar.id, "title" => "baz" } } } }
374
+ @post.update_attributes(update_hash["post"])
375
+ @post.tags.last.title.should == "baz"
376
+ end
377
+
378
+ it "should be possible to destroy through parent model using canoncial _destroy macro" do
379
+ @post.tags.count.should == 2
380
+ update_hash = { "post" => { "tags_attributes" => { "1234" => { "id" => @tag_bar.id, "title" => "baz", "_destroy" => "true"} } } }
381
+ @post.update_attributes(update_hash["post"])
382
+ @post.tags.count.should == 1
383
+ @post.history_tracks.last.action.should == "destroy"
384
+ end
385
+ end
386
+
349
387
  describe "non-embedded" do
350
388
  it "should undo changes" do
351
389
  @post.update_attributes(:title => "Test2")
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.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-04-05 00:00:00.000000000 Z
13
+ date: 2012-04-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: easy_diff
17
- requirement: &70112883354800 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70112883354800
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: mongoid
28
- requirement: &70112883352160 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ! '>='
@@ -33,10 +38,15 @@ dependencies:
33
38
  version: 2.0.0
34
39
  type: :runtime
35
40
  prerelease: false
36
- version_requirements: *70112883352160
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: 2.0.0
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: bson_ext
39
- requirement: &70112883350740 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ! '>='
@@ -44,10 +54,15 @@ dependencies:
44
54
  version: '0'
45
55
  type: :development
46
56
  prerelease: false
47
- version_requirements: *70112883350740
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
48
63
  - !ruby/object:Gem::Dependency
49
64
  name: rspec
50
- requirement: &70112883350000 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
51
66
  none: false
52
67
  requirements:
53
68
  - - ! '>='
@@ -55,10 +70,15 @@ dependencies:
55
70
  version: '0'
56
71
  type: :development
57
72
  prerelease: false
58
- version_requirements: *70112883350000
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
59
79
  - !ruby/object:Gem::Dependency
60
80
  name: yard
61
- requirement: &70112883346260 !ruby/object:Gem::Requirement
81
+ requirement: !ruby/object:Gem::Requirement
62
82
  none: false
63
83
  requirements:
64
84
  - - ! '>='
@@ -66,10 +86,15 @@ dependencies:
66
86
  version: '0'
67
87
  type: :development
68
88
  prerelease: false
69
- version_requirements: *70112883346260
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
70
95
  - !ruby/object:Gem::Dependency
71
96
  name: bundler
72
- requirement: &70112883344280 !ruby/object:Gem::Requirement
97
+ requirement: !ruby/object:Gem::Requirement
73
98
  none: false
74
99
  requirements:
75
100
  - - ! '>='
@@ -77,10 +102,15 @@ dependencies:
77
102
  version: 1.0.0
78
103
  type: :development
79
104
  prerelease: false
80
- version_requirements: *70112883344280
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: 1.0.0
81
111
  - !ruby/object:Gem::Dependency
82
112
  name: jeweler
83
- requirement: &70112883340980 !ruby/object:Gem::Requirement
113
+ requirement: !ruby/object:Gem::Requirement
84
114
  none: false
85
115
  requirements:
86
116
  - - ! '>='
@@ -88,10 +118,15 @@ dependencies:
88
118
  version: '0'
89
119
  type: :development
90
120
  prerelease: false
91
- version_requirements: *70112883340980
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
92
127
  - !ruby/object:Gem::Dependency
93
128
  name: database_cleaner
94
- requirement: &70112883336740 !ruby/object:Gem::Requirement
129
+ requirement: !ruby/object:Gem::Requirement
95
130
  none: false
96
131
  requirements:
97
132
  - - ! '>='
@@ -99,7 +134,12 @@ dependencies:
99
134
  version: '0'
100
135
  type: :development
101
136
  prerelease: false
102
- version_requirements: *70112883336740
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
103
143
  description: ! "In frustration of Mongoid::Versioning, I created this plugin for tracking
104
144
  historical changes for any document, including embedded ones. It achieves this by
105
145
  storing all history tracks in a single collection that you define. (See Usage for
@@ -152,7 +192,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
192
  version: '0'
153
193
  segments:
154
194
  - 0
155
- hash: -3312871868827146097
195
+ hash: 4511174551660468698
156
196
  required_rubygems_version: !ruby/object:Gem::Requirement
157
197
  none: false
158
198
  requirements:
@@ -161,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
201
  version: '0'
162
202
  requirements: []
163
203
  rubyforge_project:
164
- rubygems_version: 1.8.15
204
+ rubygems_version: 1.8.19
165
205
  signing_key:
166
206
  specification_version: 3
167
207
  summary: history tracking, auditing, undo, redo for mongoid