historiographer 1.3.1 → 1.4.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/VERSION +1 -1
- data/historiographer.gemspec +2 -2
- data/lib/historiographer/relation.rb +30 -23
- data/spec/historiographer_spec.rb +6 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2c323e0b16003b066c298e281147b86e810ee0f2b7cc5bc859bfad1c861795b
|
4
|
+
data.tar.gz: 04b81492d7a2a24a8aa46935f64874f77521884dec9cd9aa2fd568785b399847
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8716822fb73b440fedb427ea732d87e15a4ffb4bc3ca902bfa57e4cbf5e9303fbc6a25482eadcbc9d00830eede9664685db8d05b05438a5fe08c32fa79c8e3ee
|
7
|
+
data.tar.gz: 86ce1d84a483a5384aea9e0d043911edc0f1cb3f3bf6f970d1dccee22d3369a2ef6437f65e2de6e46f9df4ec68a76b189411805ba98cca4874b39513c1162b69
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.0
|
data/historiographer.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: historiographer 1.
|
5
|
+
# stub: historiographer 1.4.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "historiographer".freeze
|
9
|
-
s.version = "1.
|
9
|
+
s.version = "1.4.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
@@ -15,35 +15,42 @@ module Historiographer
|
|
15
15
|
super(updates)
|
16
16
|
else
|
17
17
|
updates.symbolize_keys!
|
18
|
+
model_changes = updates.except(:history_user_id)
|
18
19
|
|
19
20
|
ActiveRecord::Base.transaction do
|
20
|
-
|
21
|
-
|
22
|
-
records = self.reload
|
23
|
-
history_class = records.klass.history_class
|
24
|
-
|
25
|
-
records.new.send(:history_user_absent_action) if updates[:history_user_id].nil?
|
26
|
-
history_user_id = updates[:history_user_id]
|
27
|
-
|
28
|
-
new_histories = records.map do |record|
|
29
|
-
attrs = record.attributes.clone
|
30
|
-
foreign_key = history_class.history_foreign_key
|
31
|
-
|
32
|
-
now = UTC.now
|
33
|
-
attrs.merge!(foreign_key => attrs["id"], history_started_at: now, history_user_id: history_user_id)
|
34
|
-
|
35
|
-
attrs = attrs.except("id")
|
36
|
-
|
37
|
-
record.histories.build(attrs)
|
21
|
+
changed_records = select do |record|
|
22
|
+
!(record.attributes.symbolize_keys >= model_changes)
|
38
23
|
end
|
39
24
|
|
40
|
-
|
25
|
+
super(model_changes)
|
26
|
+
bulk_record_history(self.reload.where(id: changed_records.pluck(:id)), updates)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
41
30
|
|
42
|
-
|
31
|
+
def bulk_record_history(records, updates = {})
|
32
|
+
now = UTC.now
|
33
|
+
history_class = self.klass.history_class
|
43
34
|
|
44
|
-
|
45
|
-
|
35
|
+
records.new.send(:history_user_absent_action) if updates[:history_user_id].nil?
|
36
|
+
history_user_id = updates[:history_user_id]
|
37
|
+
|
38
|
+
new_histories = records.map do |record|
|
39
|
+
attrs = record.attributes.clone
|
40
|
+
foreign_key = history_class.history_foreign_key
|
41
|
+
|
42
|
+
attrs.merge!(foreign_key => attrs["id"], history_started_at: now, history_user_id: history_user_id)
|
43
|
+
|
44
|
+
attrs = attrs.except("id")
|
45
|
+
|
46
|
+
record.histories.build(attrs)
|
46
47
|
end
|
48
|
+
|
49
|
+
current_histories = history_class.current.where("#{history_class.history_foreign_key} IN (?)", records.map(&:id))
|
50
|
+
|
51
|
+
current_histories.update_all(history_ended_at: now)
|
52
|
+
|
53
|
+
history_class.import new_histories
|
47
54
|
end
|
48
55
|
|
49
56
|
def delete_all_without_history
|
@@ -91,4 +98,4 @@ module Historiographer
|
|
91
98
|
records.each { |r| r.destroy(history_user_id: history_user_id) }.tap { reset }
|
92
99
|
end
|
93
100
|
end
|
94
|
-
end
|
101
|
+
end
|
@@ -164,9 +164,14 @@ describe Historiographer do
|
|
164
164
|
expect(posts.second.current_history.title).to eq "My New Post Title"
|
165
165
|
expect(posts.third.current_history.title).to eq "Brett's Post"
|
166
166
|
|
167
|
+
# It does not update histories if nothing changed
|
168
|
+
Post.all.update_all(title: "Brett's Post", history_user_id: 1)
|
169
|
+
posts = Post.all.reload.order(:id)
|
170
|
+
expect(posts.map(&:histories).map(&:count)).to all(eq 3)
|
171
|
+
|
167
172
|
posts.update_all_without_history(title: "Untracked")
|
168
173
|
expect(posts.first.histories.count).to eq 3
|
169
|
-
expect(posts.second.histories.count).to eq
|
174
|
+
expect(posts.second.histories.count).to eq 3
|
170
175
|
expect(posts.third.histories.count).to eq 3
|
171
176
|
|
172
177
|
thing1 = ThingWithoutHistory.create(name: "Thing 1")
|