activehistory 0.2.2 → 5.1.0
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/.gitignore +1 -0
- data/Gemfile.lock +19 -18
- data/activehistory.gemspec +2 -4
- data/lib/activehistory/action.rb +8 -6
- data/lib/activehistory/adapters/active_record.rb +27 -6
- data/lib/activehistory/event.rb +2 -8
- data/lib/activehistory/metadatum.rb +9 -0
- data/lib/activehistory/version.rb +1 -1
- data/test/active_record_adapter/event_test.rb +8 -6
- data/test/models.rb +13 -5
- data/test/test_helper.rb +1 -0
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d058bc974abf0cc2b78bbe2f1a310d923917c39
|
4
|
+
data.tar.gz: b71d899daa40624f2fcdd234c66242e42944d36f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f73eff939b5cf10570e7738ba267c3b1c20a990981818590d86f9dc8cbecbf216e27d6e306a9a00380511a73dd7493006f1d9e9f78f5643da8f061676a4c219
|
7
|
+
data.tar.gz: 9691514585efb7e08f972733f73a7179da93755db86decbb88f5fa75da2c1384659df1366ada96dce8fafec28756ef0fa81c0273460d584728e1c14011ca5363
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
activehistory (0.2.
|
5
|
-
activerecord (~> 5.
|
6
|
-
arel (~> 7.0)
|
4
|
+
activehistory (0.2.3)
|
5
|
+
activerecord (~> 5.1)
|
7
6
|
globalid (~> 0.3.7)
|
8
7
|
|
9
8
|
GEM
|
10
9
|
remote: http://rubygems.org/
|
11
10
|
specs:
|
12
|
-
activemodel (5.
|
13
|
-
activesupport (= 5.
|
14
|
-
activerecord (5.
|
15
|
-
activemodel (= 5.
|
16
|
-
activesupport (= 5.
|
17
|
-
arel (~>
|
18
|
-
activesupport (5.
|
11
|
+
activemodel (5.1.0)
|
12
|
+
activesupport (= 5.1.0)
|
13
|
+
activerecord (5.1.0)
|
14
|
+
activemodel (= 5.1.0)
|
15
|
+
activesupport (= 5.1.0)
|
16
|
+
arel (~> 8.0)
|
17
|
+
activesupport (5.1.0)
|
19
18
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
20
19
|
i18n (~> 0.7)
|
21
20
|
minitest (~> 5.1)
|
22
21
|
tzinfo (~> 1.1)
|
23
22
|
addressable (2.4.0)
|
24
23
|
ansi (1.5.0)
|
25
|
-
arel (
|
24
|
+
arel (8.0.0)
|
26
25
|
builder (3.2.2)
|
27
|
-
|
26
|
+
byebug (9.0.6)
|
27
|
+
concurrent-ruby (1.0.5)
|
28
28
|
crack (0.4.3)
|
29
29
|
safe_yaml (~> 1.0.0)
|
30
30
|
docile (1.1.5)
|
@@ -35,10 +35,10 @@ GEM
|
|
35
35
|
globalid (0.3.7)
|
36
36
|
activesupport (>= 4.1.0)
|
37
37
|
hashdiff (0.3.0)
|
38
|
-
i18n (0.
|
39
|
-
json (1.8.
|
38
|
+
i18n (0.8.1)
|
39
|
+
json (1.8.6)
|
40
40
|
metaclass (0.0.4)
|
41
|
-
minitest (5.
|
41
|
+
minitest (5.10.1)
|
42
42
|
minitest-reporters (1.1.11)
|
43
43
|
ansi
|
44
44
|
builder
|
@@ -62,8 +62,8 @@ GEM
|
|
62
62
|
json (>= 1.8, < 3)
|
63
63
|
simplecov-html (~> 0.10.0)
|
64
64
|
simplecov-html (0.10.0)
|
65
|
-
thread_safe (0.3.
|
66
|
-
tzinfo (1.2.
|
65
|
+
thread_safe (0.3.6)
|
66
|
+
tzinfo (1.2.3)
|
67
67
|
thread_safe (~> 0.1)
|
68
68
|
webmock (2.1.0)
|
69
69
|
addressable (>= 2.3.6)
|
@@ -76,6 +76,7 @@ PLATFORMS
|
|
76
76
|
DEPENDENCIES
|
77
77
|
activehistory!
|
78
78
|
bundler
|
79
|
+
byebug
|
79
80
|
factory_girl
|
80
81
|
faker
|
81
82
|
minitest
|
@@ -90,4 +91,4 @@ DEPENDENCIES
|
|
90
91
|
webmock
|
91
92
|
|
92
93
|
BUNDLED WITH
|
93
|
-
1.
|
94
|
+
1.15.3
|
data/activehistory.gemspec
CHANGED
@@ -31,11 +31,9 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.add_development_dependency 'sdoc-templates-42floors'
|
32
32
|
s.add_development_dependency 'simplecov'
|
33
33
|
s.add_development_dependency 'pg'
|
34
|
+
s.add_development_dependency 'byebug'
|
34
35
|
|
35
36
|
# Runtime
|
36
|
-
|
37
|
-
# s.add_runtime_dependency 'cookie_store'
|
38
|
-
s.add_runtime_dependency 'arel', '~> 7.0'
|
39
|
-
s.add_runtime_dependency 'activerecord', '~> 5.0'
|
37
|
+
s.add_runtime_dependency 'activerecord', '~> 5.1'
|
40
38
|
s.add_runtime_dependency 'globalid', '~> 0.3.7'
|
41
39
|
end
|
data/lib/activehistory/action.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class ActiveHistory::Action
|
2
2
|
|
3
|
-
attr_accessor :type, :timestamp, :subject_type, :subject_id, :diff
|
3
|
+
attr_accessor :id, :event_id, :type, :timestamp, :subject_type, :subject_id, :diff
|
4
4
|
|
5
5
|
def initialize(attrs)
|
6
6
|
attrs.each do |k,v|
|
@@ -12,11 +12,13 @@ class ActiveHistory::Action
|
|
12
12
|
def as_json
|
13
13
|
{
|
14
14
|
diff: diff.as_json,
|
15
|
-
subject_type:
|
16
|
-
subject_id:
|
17
|
-
timestamp:
|
18
|
-
type:
|
19
|
-
|
15
|
+
subject_type: subject_type,
|
16
|
+
subject_id: subject_id,
|
17
|
+
timestamp: timestamp.iso8601(3),
|
18
|
+
type: type,
|
19
|
+
event_id: event_id,
|
20
|
+
id: id
|
21
|
+
}.select { |k, v| !v.nil? }
|
20
22
|
end
|
21
23
|
|
22
24
|
end
|
@@ -21,7 +21,7 @@ module ActiveHistory::Adapter
|
|
21
21
|
@activehistory = options
|
22
22
|
end
|
23
23
|
|
24
|
-
def has_and_belongs_to_many(name, scope = nil, options
|
24
|
+
def has_and_belongs_to_many(name, scope = nil, **options, &extension)
|
25
25
|
super
|
26
26
|
name = name.to_s
|
27
27
|
habtm_model = self.const_get("HABTM_#{name.to_s.camelize}")
|
@@ -53,6 +53,7 @@ module ActiveHistory::Adapter
|
|
53
53
|
action.diff[diff_key] ||= [[], []]
|
54
54
|
action.diff[diff_key][0] |= removed
|
55
55
|
action.diff[diff_key][1] |= added
|
56
|
+
|
56
57
|
in_common = (action.diff[diff_key][0] & action.diff[diff_key][1])
|
57
58
|
if !in_common.empty?
|
58
59
|
action.diff[diff_key][0] = action.diff[diff_key][0] - in_common
|
@@ -155,7 +156,8 @@ module ActiveHistory::Adapter
|
|
155
156
|
return if !activehistory_tracking
|
156
157
|
|
157
158
|
if type == :create || type == :update
|
158
|
-
diff = self.
|
159
|
+
diff = self.saved_changes.select { |k,v| !activehistory_tracking[:exclude].include?(k.to_sym) }
|
160
|
+
|
159
161
|
if type == :create
|
160
162
|
self.class.columns.each do |column|
|
161
163
|
if !diff[column.name] && !activehistory_tracking[:exclude].include?(column.name.to_sym) && column.default != self.attributes[column.name]
|
@@ -164,11 +166,29 @@ module ActiveHistory::Adapter
|
|
164
166
|
end
|
165
167
|
end
|
166
168
|
elsif type == :destroy
|
167
|
-
|
169
|
+
relations_ids = self.class.reflect_on_all_associations.map { |r| "#{r.name.to_s.singularize}_ids" }
|
170
|
+
|
171
|
+
diff = self.attributes.select do |k|
|
172
|
+
!activehistory_tracking[:exclude].include?(k.to_sym)
|
173
|
+
end.map do |k, i|
|
174
|
+
if relations_ids.include?(k)
|
175
|
+
[ k, [ i, [] ] ]
|
176
|
+
else
|
177
|
+
[ k, [ i, nil ] ]
|
178
|
+
end
|
179
|
+
end.to_h
|
168
180
|
end
|
169
|
-
|
170
|
-
|
171
|
-
|
181
|
+
|
182
|
+
if type == :update
|
183
|
+
diff_without_timestamps = if self.class.record_timestamps
|
184
|
+
diff.keys - (self.class.send(:timestamp_attributes_for_update_in_model) + self.class.send(:timestamp_attributes_for_create_in_model))
|
185
|
+
else
|
186
|
+
diff.keys
|
187
|
+
end
|
188
|
+
|
189
|
+
return if diff_without_timestamps.empty?
|
190
|
+
end
|
191
|
+
|
172
192
|
if activehistory_tracking[:habtm_model]
|
173
193
|
if type == :create
|
174
194
|
self.class.reflect_on_association(:left_side).klass.activehistory_association_changed(
|
@@ -269,6 +289,7 @@ module ActiveHistory::Adapter
|
|
269
289
|
})
|
270
290
|
|
271
291
|
action.diff ||= {}
|
292
|
+
|
272
293
|
if inverse_association.collection? || activehistory_tracking[:habtm_model]
|
273
294
|
diff_key = "#{inverse_association.name.to_s.singularize}_ids"
|
274
295
|
action.diff[diff_key] ||= [[], []]
|
data/lib/activehistory/event.rb
CHANGED
@@ -8,7 +8,7 @@ end
|
|
8
8
|
class ActiveHistory::Event
|
9
9
|
include GlobalID::Identification
|
10
10
|
|
11
|
-
attr_accessor :id, :
|
11
|
+
attr_accessor :id, :metadata, :timestamp, :actions
|
12
12
|
|
13
13
|
def initialize(attrs={})
|
14
14
|
attrs.each do |k,v|
|
@@ -25,7 +25,7 @@ class ActiveHistory::Event
|
|
25
25
|
@actions ||= []
|
26
26
|
@timestamp ||= Time.now
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def persisted?
|
30
30
|
@persisted
|
31
31
|
end
|
@@ -37,7 +37,6 @@ class ActiveHistory::Event
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def action_for(type, id, new_options=nil)
|
40
|
-
byebug if $debugging
|
41
40
|
type = type.base_class.model_name.name if !type.is_a?(String)
|
42
41
|
action = @actions.find { |a| a.subject_type.to_s == type.to_s && a.subject_id.to_s == id.to_s }
|
43
42
|
|
@@ -85,12 +84,7 @@ class ActiveHistory::Event
|
|
85
84
|
def as_json
|
86
85
|
{
|
87
86
|
id: id,
|
88
|
-
ip: ip,
|
89
|
-
user_agent: user_agent,
|
90
|
-
session_id: session_id,
|
91
87
|
metadata: metadata,
|
92
|
-
performed_by_type: performed_by_type,
|
93
|
-
performed_by_id: performed_by_id,
|
94
88
|
timestamp: timestamp.utc.iso8601(3),
|
95
89
|
actions: actions.as_json
|
96
90
|
}
|
@@ -9,12 +9,14 @@ class EventTest < ActiveSupport::TestCase
|
|
9
9
|
|
10
10
|
test 'Data captured from Event encalpsulation' do
|
11
11
|
data = {
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
metadata: {
|
13
|
+
ip: '127.0.0.1',
|
14
|
+
user_agent: 'user-agent',
|
15
|
+
session_id: 'session-id',
|
16
|
+
performed_by_type: 'model',
|
17
|
+
performed_by_id: 'id',
|
18
|
+
random: 'stuff'
|
19
|
+
},
|
18
20
|
timestamp: Time.now
|
19
21
|
}
|
20
22
|
|
data/test/models.rb
CHANGED
@@ -40,9 +40,19 @@ class Region < ActiveRecord::Base
|
|
40
40
|
track
|
41
41
|
|
42
42
|
has_and_belongs_to_many :properties, inverse_of: :regions
|
43
|
-
|
44
|
-
has_and_belongs_to_many :
|
45
|
-
|
43
|
+
|
44
|
+
has_and_belongs_to_many :parents,
|
45
|
+
class_name: 'Region',
|
46
|
+
join_table: 'regions_regions',
|
47
|
+
foreign_key: 'child_id',
|
48
|
+
association_foreign_key: 'parent_id'
|
49
|
+
|
50
|
+
has_and_belongs_to_many :children,
|
51
|
+
class_name: 'Region',
|
52
|
+
join_table: 'regions_regions',
|
53
|
+
foreign_key: 'parent_id',
|
54
|
+
association_foreign_key: 'child_id'
|
55
|
+
|
46
56
|
end
|
47
57
|
|
48
58
|
class Comment < ActiveRecord::Base
|
@@ -56,5 +66,3 @@ end
|
|
56
66
|
class UnobservedModel < ActiveRecord::Base
|
57
67
|
|
58
68
|
end
|
59
|
-
|
60
|
-
# ActiveRecord::Base.logger = Logger.new(STDOUT)
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activehistory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Bracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -193,33 +193,33 @@ dependencies:
|
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
|
-
name:
|
196
|
+
name: byebug
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
198
198
|
requirements:
|
199
|
-
- - "
|
199
|
+
- - ">="
|
200
200
|
- !ruby/object:Gem::Version
|
201
|
-
version: '
|
202
|
-
type: :
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
203
|
prerelease: false
|
204
204
|
version_requirements: !ruby/object:Gem::Requirement
|
205
205
|
requirements:
|
206
|
-
- - "
|
206
|
+
- - ">="
|
207
207
|
- !ruby/object:Gem::Version
|
208
|
-
version: '
|
208
|
+
version: '0'
|
209
209
|
- !ruby/object:Gem::Dependency
|
210
210
|
name: activerecord
|
211
211
|
requirement: !ruby/object:Gem::Requirement
|
212
212
|
requirements:
|
213
213
|
- - "~>"
|
214
214
|
- !ruby/object:Gem::Version
|
215
|
-
version: '5.
|
215
|
+
version: '5.1'
|
216
216
|
type: :runtime
|
217
217
|
prerelease: false
|
218
218
|
version_requirements: !ruby/object:Gem::Requirement
|
219
219
|
requirements:
|
220
220
|
- - "~>"
|
221
221
|
- !ruby/object:Gem::Version
|
222
|
-
version: '5.
|
222
|
+
version: '5.1'
|
223
223
|
- !ruby/object:Gem::Dependency
|
224
224
|
name: globalid
|
225
225
|
requirement: !ruby/object:Gem::Requirement
|
@@ -256,6 +256,7 @@ files:
|
|
256
256
|
- lib/activehistory/connection.rb
|
257
257
|
- lib/activehistory/event.rb
|
258
258
|
- lib/activehistory/exceptions.rb
|
259
|
+
- lib/activehistory/metadatum.rb
|
259
260
|
- lib/activehistory/regard.rb
|
260
261
|
- lib/activehistory/version.rb
|
261
262
|
- test/active_record_adapter/association_test/belongs_to_association_test.rb
|
@@ -290,7 +291,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
290
291
|
version: '0'
|
291
292
|
requirements: []
|
292
293
|
rubyforge_project:
|
293
|
-
rubygems_version: 2.6.
|
294
|
+
rubygems_version: 2.6.11
|
294
295
|
signing_key:
|
295
296
|
specification_version: 4
|
296
297
|
summary: Track changes to ActiveRecord models
|