mongoid-history 0.4.2 → 0.4.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/mongoid/history/trackable.rb +14 -11
- data/lib/mongoid/history/version.rb +1 -1
- data/spec/integration/embedded_in_polymorphic_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2f7422b15f0027945a65e155ac5776cbbb7f3a38
|
|
4
|
+
data.tar.gz: e23db13692cbf5679ad32fecaa2a6bd000379547
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2d88df0753a104a5fa4577ad4c8117d2fb46e0e1bcd1d996669d79a9f64bc92e8bd32dfecbcbc549d7801d815817eeef805f451b01bd8ba9485fd6f2abbbc3b6
|
|
7
|
+
data.tar.gz: 718ff47501c3b4feac38f5113131fcffca37570954bce7be763a88ae12a3c7f36f0b6ad6dbe063b6a8018256c4f14f5b7e9d6d364423ec61a34631e02bc1ffaf
|
data/CHANGELOG.md
CHANGED
|
@@ -68,7 +68,7 @@ module Mongoid
|
|
|
68
68
|
|
|
69
69
|
module MyInstanceMethods
|
|
70
70
|
def history_tracks
|
|
71
|
-
@history_tracks ||= Mongoid::History.tracker_class.where(scope:
|
|
71
|
+
@history_tracks ||= Mongoid::History.tracker_class.where(scope: related_scope, association_chain: association_hash)
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
# undo :from => 1, :to => 5
|
|
@@ -128,6 +128,18 @@ module Mongoid
|
|
|
128
128
|
versions.desc(:version)
|
|
129
129
|
end
|
|
130
130
|
|
|
131
|
+
def related_scope
|
|
132
|
+
scope = history_trackable_options[:scope]
|
|
133
|
+
scope = _parent.collection_name.to_s.singularize.to_sym if scope.is_a?(Array)
|
|
134
|
+
|
|
135
|
+
if Mongoid::History.mongoid3?
|
|
136
|
+
scope = metadata.inverse_class_name.tableize.singularize.to_sym if metadata.present? && scope == metadata.as
|
|
137
|
+
else
|
|
138
|
+
scope = relation_metadata.inverse_class_name.tableize.singularize.to_sym if relation_metadata.present? && scope == relation_metadata.as
|
|
139
|
+
end
|
|
140
|
+
scope
|
|
141
|
+
end
|
|
142
|
+
|
|
131
143
|
def traverse_association_chain(node = self)
|
|
132
144
|
list = node._parent ? traverse_association_chain(node._parent) : []
|
|
133
145
|
list << association_hash(node)
|
|
@@ -191,18 +203,9 @@ module Mongoid
|
|
|
191
203
|
def history_tracker_attributes(action)
|
|
192
204
|
return @history_tracker_attributes if @history_tracker_attributes
|
|
193
205
|
|
|
194
|
-
scope = history_trackable_options[:scope]
|
|
195
|
-
scope = _parent.collection_name.to_s.singularize.to_sym if scope.is_a?(Array)
|
|
196
|
-
|
|
197
|
-
if Mongoid::History.mongoid3?
|
|
198
|
-
scope = metadata.inverse_class_name.tableize.singularize.to_sym if metadata.present? && scope == metadata.as
|
|
199
|
-
else
|
|
200
|
-
scope = relation_metadata.inverse_class_name.tableize.singularize.to_sym if relation_metadata.present? && scope == relation_metadata.as
|
|
201
|
-
end
|
|
202
|
-
|
|
203
206
|
@history_tracker_attributes = {
|
|
204
207
|
association_chain: traverse_association_chain,
|
|
205
|
-
scope:
|
|
208
|
+
scope: related_scope,
|
|
206
209
|
modifier: send(history_trackable_options[:modifier_field])
|
|
207
210
|
}
|
|
208
211
|
|
|
@@ -86,14 +86,17 @@ describe Mongoid::History::Tracker do
|
|
|
86
86
|
real_state.save!
|
|
87
87
|
real_state.build_address(address: "Main Street #123", city: "Highland Park", state: 'IL').save!
|
|
88
88
|
expect(real_state.history_tracks.count).to eq(2)
|
|
89
|
+
expect(real_state.address.history_tracks.count).to eq(1)
|
|
89
90
|
|
|
90
91
|
real_state.reload
|
|
91
92
|
real_state.address.update_attribute(:address, 'Second Street')
|
|
92
93
|
expect(real_state.history_tracks.count).to eq(3)
|
|
94
|
+
expect(real_state.address.history_tracks.count).to eq(2)
|
|
93
95
|
expect(real_state.history_tracks.last.action).to eq('update')
|
|
94
96
|
|
|
95
97
|
real_state.build_embone(name: 'Lorem ipsum').save!
|
|
96
98
|
expect(real_state.history_tracks.count).to eq(4)
|
|
99
|
+
expect(real_state.embone.history_tracks.count).to eq(1)
|
|
97
100
|
expect(real_state.history_tracks.last.action).to eq('create')
|
|
98
101
|
expect(real_state.history_tracks.last.association_chain.last['name']).to eq('embone')
|
|
99
102
|
|
|
@@ -101,19 +104,23 @@ describe Mongoid::History::Tracker do
|
|
|
101
104
|
company.save!
|
|
102
105
|
company.build_address(address: "Main Street #456", city: "Evanston", state: 'IL').save!
|
|
103
106
|
expect(company.history_tracks.count).to eq(2)
|
|
107
|
+
expect(company.address.history_tracks.count).to eq(1)
|
|
104
108
|
|
|
105
109
|
company.reload
|
|
106
110
|
company.address.update_attribute(:address, 'Second Street')
|
|
107
111
|
expect(company.history_tracks.count).to eq(3)
|
|
112
|
+
expect(company.address.history_tracks.count).to eq(2)
|
|
108
113
|
expect(company.history_tracks.last.action).to eq('update')
|
|
109
114
|
|
|
110
115
|
company.build_second_address(address: "Main Street #789", city: "Highland Park", state: 'IL').save!
|
|
111
116
|
expect(company.history_tracks.count).to eq(4)
|
|
117
|
+
expect(company.second_address.history_tracks.count).to eq(1)
|
|
112
118
|
expect(company.history_tracks.last.action).to eq('create')
|
|
113
119
|
expect(company.history_tracks.last.association_chain.last['name']).to eq('second_address')
|
|
114
120
|
|
|
115
121
|
company.build_embone(name: 'Lorem ipsum').save!
|
|
116
122
|
expect(company.history_tracks.count).to eq(5)
|
|
123
|
+
expect(company.embone.history_tracks.count).to eq(1)
|
|
117
124
|
expect(company.history_tracks.last.action).to eq('create')
|
|
118
125
|
expect(company.history_tracks.last.association_chain.last['name']).to eq('embone')
|
|
119
126
|
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.4.
|
|
4
|
+
version: 0.4.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aaron Qian
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2014-07-
|
|
13
|
+
date: 2014-07-10 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: easy_diff
|