historiographer 1.3.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2d85a348f2e7196cccef533c9562b53c9449df6a0dde03509a1d48a5d66c490
4
- data.tar.gz: f3b9f822e53fdadc04d20a0f4066b8b47e019c11333d9dccc0140ea1e9f12991
3
+ metadata.gz: 3693419549c943f0720d9e2282a6c5b62103dfa51fd206e799f83565fe287a2e
4
+ data.tar.gz: a534c87ea02111361362f28fc767177c2df0435cec1efcca3adbdbce3c2a127f
5
5
  SHA512:
6
- metadata.gz: 5011fe73d7a09abd888f362b1e3923436c5f29068f9b46650ac4e39f09ab3226d7f2d66072293d9908dc37693a7afc5b73f73c2db2c1f6f1b0e9119c153c511b
7
- data.tar.gz: ccca124547a124739d68183b9374ddd1b8fc452ed29b568da485981abb37cab8f055384065b00016981ea3844177c5e7e050d0fb6e5f8faef7844e5835387591
6
+ metadata.gz: 2266edb10a93aa6a924a418aba82e59cb198d44ff480ae240e5d88f90b3385d597d0ecbe95e6ce348345a4ba2ca3b903075fdd07807d796dc6619cad4cdfd375
7
+ data.tar.gz: cc5541d5e4fe6184977cf8564d6deda4d605280d6550c803e99e3b2c3ea99bbd342b72ed129319526e30994ed036e151d7575d712c284d3558a9100baad7ac19
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source "https://rubygems.org"
2
2
  ruby "2.6.3"
3
3
 
4
- gem "activerecord", "~> 5.1"
4
+ gem "activerecord", "~> 6"
5
5
  gem "activesupport"
6
6
  gem "rollbar"
7
7
  gem "activerecord-import"
@@ -9,7 +9,7 @@ gem "activerecord-import"
9
9
  group :development, :test do
10
10
  gem "pg"
11
11
  gem "pry"
12
- gem "mysql2", "0.4.10"
12
+ gem "mysql2", "0.5"
13
13
  gem "standalone_migrations"
14
14
  gem "timecop"
15
15
  gem "paranoia"
data/Gemfile.lock CHANGED
@@ -18,54 +18,59 @@ GIT
18
18
  GEM
19
19
  remote: https://rubygems.org/
20
20
  specs:
21
- actionpack (5.2.3)
22
- actionview (= 5.2.3)
23
- activesupport (= 5.2.3)
24
- rack (~> 2.0)
21
+ actionpack (6.1.4.4)
22
+ actionview (= 6.1.4.4)
23
+ activesupport (= 6.1.4.4)
24
+ rack (~> 2.0, >= 2.0.9)
25
25
  rack-test (>= 0.6.3)
26
26
  rails-dom-testing (~> 2.0)
27
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
- actionview (5.2.3)
29
- activesupport (= 5.2.3)
27
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
28
+ actionview (6.1.4.4)
29
+ activesupport (= 6.1.4.4)
30
30
  builder (~> 3.1)
31
31
  erubi (~> 1.4)
32
32
  rails-dom-testing (~> 2.0)
33
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
34
- activemodel (5.2.3)
35
- activesupport (= 5.2.3)
36
- activerecord (5.2.3)
37
- activemodel (= 5.2.3)
38
- activesupport (= 5.2.3)
39
- arel (>= 9.0)
40
- activerecord-import (1.0.2)
41
- activerecord (>= 3.2)
42
- activesupport (5.2.3)
33
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
34
+ activemodel (6.1.4.4)
35
+ activesupport (= 6.1.4.4)
36
+ activerecord (6.1.4.4)
37
+ activemodel (= 6.1.4.4)
38
+ activesupport (= 6.1.4.4)
39
+ activerecord-import (1.3.0)
40
+ activerecord (>= 4.2)
41
+ activesupport (6.1.4.4)
43
42
  concurrent-ruby (~> 1.0, >= 1.0.2)
44
- i18n (>= 0.7, < 2)
45
- minitest (~> 5.1)
46
- tzinfo (~> 1.1)
43
+ i18n (>= 1.6, < 2)
44
+ minitest (>= 5.1)
45
+ tzinfo (~> 2.0)
46
+ zeitwerk (~> 2.3)
47
47
  addressable (2.4.0)
48
- arel (9.0.0)
49
- builder (3.2.3)
50
- coderay (1.1.2)
51
- concurrent-ruby (1.1.5)
52
- crass (1.0.4)
53
- database_cleaner (1.7.0)
48
+ builder (3.2.4)
49
+ coderay (1.1.3)
50
+ concurrent-ruby (1.1.9)
51
+ crass (1.0.6)
52
+ database_cleaner (2.0.1)
53
+ database_cleaner-active_record (~> 2.0.0)
54
+ database_cleaner-active_record (2.0.1)
55
+ activerecord (>= 5.a)
56
+ database_cleaner-core (~> 2.0.0)
57
+ database_cleaner-core (2.0.1)
54
58
  descendants_tracker (0.0.4)
55
59
  thread_safe (~> 0.3, >= 0.3.1)
56
- diff-lcs (1.3)
57
- docile (1.3.2)
58
- erubi (1.8.0)
59
- factory_bot (5.1.1)
60
- activesupport (>= 4.2.0)
61
- factory_bot_rails (5.1.1)
62
- factory_bot (~> 5.1.0)
63
- railties (>= 4.2.0)
60
+ diff-lcs (1.5.0)
61
+ docile (1.4.0)
62
+ erubi (1.10.0)
63
+ factory_bot (6.2.0)
64
+ activesupport (>= 5.0.0)
65
+ factory_bot_rails (6.2.0)
66
+ factory_bot (~> 6.2.0)
67
+ railties (>= 5.0.0)
64
68
  faraday (0.9.2)
65
69
  multipart-post (>= 1.2, < 3)
66
- ffi (1.11.1)
67
- formatador (0.2.5)
68
- git (1.5.0)
70
+ ffi (1.15.5)
71
+ formatador (1.1.0)
72
+ git (1.10.2)
73
+ rchardet (~> 1.8)
69
74
  github_api (0.16.0)
70
75
  addressable (~> 2.4.0)
71
76
  descendants_tracker (~> 0.0.4)
@@ -73,13 +78,13 @@ GEM
73
78
  hashie (>= 3.4)
74
79
  mime-types (>= 1.16, < 3.0)
75
80
  oauth2 (~> 1.0)
76
- guard (2.15.0)
81
+ guard (2.18.0)
77
82
  formatador (>= 0.2.4)
78
83
  listen (>= 2.7, < 4.0)
79
84
  lumberjack (>= 1.0.12, < 2.0)
80
85
  nenv (~> 0.1)
81
86
  notiffany (~> 0.0)
82
- pry (>= 0.9.12)
87
+ pry (>= 0.13.0)
83
88
  shellany (~> 0.0)
84
89
  thor (>= 0.18.1)
85
90
  guard-compat (1.2.1)
@@ -87,104 +92,109 @@ GEM
87
92
  guard (~> 2.1)
88
93
  guard-compat (~> 1.1)
89
94
  rspec (>= 2.99.0, < 4.0)
90
- hashie (3.6.0)
91
- highline (2.0.2)
92
- i18n (1.6.0)
95
+ hashie (5.0.0)
96
+ highline (2.0.3)
97
+ i18n (1.9.1)
93
98
  concurrent-ruby (~> 1.0)
94
99
  json (1.8.6)
95
- jwt (2.2.1)
96
- listen (3.1.5)
97
- rb-fsevent (~> 0.9, >= 0.9.4)
98
- rb-inotify (~> 0.9, >= 0.9.7)
99
- ruby_dep (~> 1.2)
100
- loofah (2.2.3)
100
+ jwt (2.3.0)
101
+ listen (3.7.1)
102
+ rb-fsevent (~> 0.10, >= 0.10.3)
103
+ rb-inotify (~> 0.9, >= 0.9.10)
104
+ loofah (2.13.0)
101
105
  crass (~> 1.0.2)
102
106
  nokogiri (>= 1.5.9)
103
- lumberjack (1.0.13)
104
- method_source (0.9.2)
107
+ lumberjack (1.2.8)
108
+ method_source (1.0.0)
105
109
  mime-types (2.99.3)
106
- mini_portile2 (2.4.0)
107
- minitest (5.11.3)
108
- multi_json (1.13.1)
110
+ mini_portile2 (2.7.1)
111
+ minitest (5.15.0)
112
+ multi_json (1.15.0)
109
113
  multi_xml (0.6.0)
110
114
  multipart-post (2.1.1)
111
- mysql2 (0.4.10)
115
+ mysql2 (0.5.0)
112
116
  nenv (0.3.0)
113
- nokogiri (1.10.4)
114
- mini_portile2 (~> 2.4.0)
117
+ nokogiri (1.13.1)
118
+ mini_portile2 (~> 2.7.0)
119
+ racc (~> 1.4)
115
120
  notiffany (0.1.3)
116
121
  nenv (~> 0.1)
117
122
  shellany (~> 0.0)
118
- oauth2 (1.4.1)
119
- faraday (>= 0.8, < 0.16.0)
123
+ oauth2 (1.4.7)
124
+ faraday (>= 0.8, < 2.0)
120
125
  jwt (>= 1.0, < 3.0)
121
126
  multi_json (~> 1.3)
122
127
  multi_xml (~> 0.5)
123
128
  rack (>= 1.2, < 3)
124
- paranoia (2.4.2)
125
- activerecord (>= 4.0, < 6.1)
126
- pg (1.1.4)
127
- pry (0.12.2)
128
- coderay (~> 1.1.0)
129
- method_source (~> 0.9.0)
130
- psych (3.1.0)
131
- rack (2.0.7)
129
+ paranoia (2.5.2)
130
+ activerecord (>= 5.1, < 7.1)
131
+ pg (1.3.1)
132
+ pry (0.14.1)
133
+ coderay (~> 1.1)
134
+ method_source (~> 1.0)
135
+ psych (4.0.3)
136
+ stringio
137
+ racc (1.6.0)
138
+ rack (2.2.3)
132
139
  rack-test (1.1.0)
133
140
  rack (>= 1.0, < 3)
134
141
  rails-dom-testing (2.0.3)
135
142
  activesupport (>= 4.2.0)
136
143
  nokogiri (>= 1.6)
137
- rails-html-sanitizer (1.2.0)
138
- loofah (~> 2.2, >= 2.2.2)
139
- railties (5.2.3)
140
- actionpack (= 5.2.3)
141
- activesupport (= 5.2.3)
144
+ rails-html-sanitizer (1.4.2)
145
+ loofah (~> 2.3)
146
+ railties (6.1.4.4)
147
+ actionpack (= 6.1.4.4)
148
+ activesupport (= 6.1.4.4)
142
149
  method_source
143
- rake (>= 0.8.7)
144
- thor (>= 0.19.0, < 2.0)
145
- rake (12.3.3)
146
- rb-fsevent (0.10.3)
147
- rb-inotify (0.10.0)
150
+ rake (>= 0.13)
151
+ thor (~> 1.0)
152
+ rake (13.0.6)
153
+ rb-fsevent (0.11.0)
154
+ rb-inotify (0.10.1)
148
155
  ffi (~> 1.0)
156
+ rchardet (1.8.0)
149
157
  rdoc (3.12.2)
150
158
  json (~> 1.4)
151
- rollbar (2.21.0)
152
- rspec (3.8.0)
153
- rspec-core (~> 3.8.0)
154
- rspec-expectations (~> 3.8.0)
155
- rspec-mocks (~> 3.8.0)
156
- rspec-core (3.8.2)
157
- rspec-support (~> 3.8.0)
158
- rspec-expectations (3.8.4)
159
+ rollbar (3.3.0)
160
+ rspec (3.10.0)
161
+ rspec-core (~> 3.10.0)
162
+ rspec-expectations (~> 3.10.0)
163
+ rspec-mocks (~> 3.10.0)
164
+ rspec-core (3.10.2)
165
+ rspec-support (~> 3.10.0)
166
+ rspec-expectations (3.10.2)
159
167
  diff-lcs (>= 1.2.0, < 2.0)
160
- rspec-support (~> 3.8.0)
161
- rspec-mocks (3.8.1)
168
+ rspec-support (~> 3.10.0)
169
+ rspec-mocks (3.10.3)
162
170
  diff-lcs (>= 1.2.0, < 2.0)
163
- rspec-support (~> 3.8.0)
164
- rspec-support (3.8.2)
165
- ruby_dep (1.5.0)
171
+ rspec-support (~> 3.10.0)
172
+ rspec-support (3.10.3)
166
173
  semver2 (3.4.2)
167
174
  shellany (0.0.1)
168
- simplecov (0.17.0)
175
+ simplecov (0.21.2)
169
176
  docile (~> 1.1)
170
- json (>= 1.8, < 3)
171
- simplecov-html (~> 0.10.0)
172
- simplecov-html (0.10.2)
173
- standalone_migrations (5.2.7)
174
- activerecord (>= 4.2.7, < 5.3.0)
175
- railties (>= 4.2.7, < 5.3.0)
177
+ simplecov-html (~> 0.11)
178
+ simplecov_json_formatter (~> 0.1)
179
+ simplecov-html (0.12.3)
180
+ simplecov_json_formatter (0.1.3)
181
+ standalone_migrations (6.1.0)
182
+ activerecord (>= 4.2.7, < 6.2.0, != 5.2.3.rc1, != 5.2.3)
183
+ railties (>= 4.2.7, < 6.2.0, != 5.2.3.rc1, != 5.2.3)
176
184
  rake (>= 10.0)
177
- thor (0.20.3)
185
+ stringio (3.0.1)
186
+ thor (1.2.1)
178
187
  thread_safe (0.3.6)
179
- timecop (0.9.1)
180
- tzinfo (1.2.5)
181
- thread_safe (~> 0.1)
188
+ timecop (0.9.4)
189
+ tzinfo (2.0.4)
190
+ concurrent-ruby (~> 1.0)
191
+ zeitwerk (2.5.4)
182
192
 
183
193
  PLATFORMS
184
194
  ruby
185
195
 
186
196
  DEPENDENCIES
187
- activerecord (~> 5.1)
197
+ activerecord (~> 6)
188
198
  activerecord-import
189
199
  activesupport
190
200
  bundler (~> 1.0)
@@ -193,7 +203,7 @@ DEPENDENCIES
193
203
  guard
194
204
  guard-rspec
195
205
  jeweler!
196
- mysql2 (= 0.4.10)
206
+ mysql2 (= 0.5)
197
207
  paranoia
198
208
  pg
199
209
  pry
@@ -208,4 +218,4 @@ RUBY VERSION
208
218
  ruby 2.6.3p62
209
219
 
210
220
  BUNDLED WITH
211
- 1.17.2
221
+ 1.17.3
data/README.md CHANGED
@@ -198,7 +198,7 @@ require "historiographer/postgres_migration"
198
198
  class CreatePostHistories < ActiveRecord::Migration
199
199
  def change
200
200
  create_table :post_histories do |t|
201
- t.histories, index_names: {
201
+ t.histories index_names: {
202
202
  title: "my_index_name",
203
203
  [:compound, :index] => "my_compound_index_name"
204
204
  }
@@ -207,6 +207,15 @@ class CreatePostHistories < ActiveRecord::Migration
207
207
  end
208
208
  ```
209
209
 
210
+ == Mysql Install
211
+
212
+ For contributors on OSX, you may have difficulty installing mysql:
213
+
214
+ ```
215
+ gem install mysql2 -v '0.4.10' --source 'https://rubygems.org/' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
216
+ ```
217
+
218
+
210
219
  == Copyright
211
220
 
212
221
  Copyright (c) 2016-2020 brettshollenberger. See LICENSE.txt for
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.1
1
+ 2.0.0
@@ -2,16 +2,16 @@
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.3.1 ruby lib
5
+ # stub: historiographer 2.0.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "historiographer".freeze
9
- s.version = "1.3.1"
9
+ s.version = "2.0.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]
13
13
  s.authors = ["brettshollenberger".freeze]
14
- s.date = "2019-11-11"
14
+ s.date = "2022-02-04"
15
15
  s.description = "Creates separate tables for each history table".freeze
16
16
  s.email = "brett.shollenberger@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -59,51 +59,36 @@ Gem::Specification.new do |s|
59
59
  ]
60
60
  s.homepage = "http://github.com/brettshollenberger/historiographer".freeze
61
61
  s.licenses = ["MIT".freeze]
62
- s.rubygems_version = "3.0.3".freeze
62
+ s.rubygems_version = "3.2.23".freeze
63
63
  s.summary = "Create histories of your ActiveRecord tables".freeze
64
64
 
65
65
  if s.respond_to? :specification_version then
66
66
  s.specification_version = 4
67
+ end
67
68
 
68
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
69
- s.add_runtime_dependency(%q<activerecord>.freeze, ["~> 5.1"])
70
- s.add_runtime_dependency(%q<activesupport>.freeze, [">= 0"])
71
- s.add_runtime_dependency(%q<rollbar>.freeze, [">= 0"])
72
- s.add_runtime_dependency(%q<activerecord-import>.freeze, [">= 0"])
73
- s.add_development_dependency(%q<pg>.freeze, [">= 0"])
74
- s.add_development_dependency(%q<pry>.freeze, [">= 0"])
75
- s.add_development_dependency(%q<mysql2>.freeze, ["= 0.4.10"])
76
- s.add_development_dependency(%q<standalone_migrations>.freeze, [">= 0"])
77
- s.add_development_dependency(%q<timecop>.freeze, [">= 0"])
78
- s.add_development_dependency(%q<paranoia>.freeze, [">= 0"])
79
- s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
80
- s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0"])
81
- s.add_development_dependency(%q<jeweler>.freeze, [">= 0"])
82
- s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
83
- else
84
- s.add_dependency(%q<activerecord>.freeze, ["~> 5.1"])
85
- s.add_dependency(%q<activesupport>.freeze, [">= 0"])
86
- s.add_dependency(%q<rollbar>.freeze, [">= 0"])
87
- s.add_dependency(%q<activerecord-import>.freeze, [">= 0"])
88
- s.add_dependency(%q<pg>.freeze, [">= 0"])
89
- s.add_dependency(%q<pry>.freeze, [">= 0"])
90
- s.add_dependency(%q<mysql2>.freeze, ["= 0.4.10"])
91
- s.add_dependency(%q<standalone_migrations>.freeze, [">= 0"])
92
- s.add_dependency(%q<timecop>.freeze, [">= 0"])
93
- s.add_dependency(%q<paranoia>.freeze, [">= 0"])
94
- s.add_dependency(%q<rdoc>.freeze, ["~> 3.12"])
95
- s.add_dependency(%q<bundler>.freeze, ["~> 1.0"])
96
- s.add_dependency(%q<jeweler>.freeze, [">= 0"])
97
- s.add_dependency(%q<simplecov>.freeze, [">= 0"])
98
- end
69
+ if s.respond_to? :add_runtime_dependency then
70
+ s.add_runtime_dependency(%q<activerecord>.freeze, ["~> 6"])
71
+ s.add_runtime_dependency(%q<activesupport>.freeze, [">= 0"])
72
+ s.add_runtime_dependency(%q<rollbar>.freeze, [">= 0"])
73
+ s.add_runtime_dependency(%q<activerecord-import>.freeze, [">= 0"])
74
+ s.add_development_dependency(%q<pg>.freeze, [">= 0"])
75
+ s.add_development_dependency(%q<pry>.freeze, [">= 0"])
76
+ s.add_development_dependency(%q<mysql2>.freeze, ["= 0.5"])
77
+ s.add_development_dependency(%q<standalone_migrations>.freeze, [">= 0"])
78
+ s.add_development_dependency(%q<timecop>.freeze, [">= 0"])
79
+ s.add_development_dependency(%q<paranoia>.freeze, [">= 0"])
80
+ s.add_development_dependency(%q<rdoc>.freeze, ["~> 3.12"])
81
+ s.add_development_dependency(%q<bundler>.freeze, ["~> 1.0"])
82
+ s.add_development_dependency(%q<jeweler>.freeze, [">= 0"])
83
+ s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
99
84
  else
100
- s.add_dependency(%q<activerecord>.freeze, ["~> 5.1"])
85
+ s.add_dependency(%q<activerecord>.freeze, ["~> 6"])
101
86
  s.add_dependency(%q<activesupport>.freeze, [">= 0"])
102
87
  s.add_dependency(%q<rollbar>.freeze, [">= 0"])
103
88
  s.add_dependency(%q<activerecord-import>.freeze, [">= 0"])
104
89
  s.add_dependency(%q<pg>.freeze, [">= 0"])
105
90
  s.add_dependency(%q<pry>.freeze, [">= 0"])
106
- s.add_dependency(%q<mysql2>.freeze, ["= 0.4.10"])
91
+ s.add_dependency(%q<mysql2>.freeze, ["= 0.5"])
107
92
  s.add_dependency(%q<standalone_migrations>.freeze, [">= 0"])
108
93
  s.add_dependency(%q<timecop>.freeze, [">= 0"])
109
94
  s.add_dependency(%q<paranoia>.freeze, [">= 0"])
@@ -16,15 +16,17 @@ module Historiographer
16
16
  # Will automatically add user_id, history_started_at,
17
17
  # and history_ended_at columns
18
18
  #
19
- def histories(except: [], only: [], no_business_columns: false)
20
- original_table_name = self.name.gsub(/_histories$/) {}.pluralize
21
- foreign_key = original_table_name.singularize.foreign_key
19
+ def histories(except: [], only: [], no_business_columns: false, index_names: {})
20
+ index_names.symbolize_keys!
21
+
22
+ original_table_name = self.name.gsub(/_histories$/) { }.pluralize
23
+ foreign_key = original_table_name.singularize.foreign_key
22
24
 
23
25
  class_definer = Class.new(ActiveRecord::Base) do
24
26
  end
25
27
 
26
28
  class_name = original_table_name.classify
27
- klass = Object.const_set(class_name, class_definer)
29
+ klass = Object.const_set(class_name, class_definer)
28
30
  original_columns = klass.columns.reject { |c| c.name == "id" || except.include?(c.name) || (only.any? && only.exclude?(c.name)) || no_business_columns }
29
31
 
30
32
  integer foreign_key.to_sym, null: false
@@ -48,7 +50,6 @@ module Historiographer
48
50
  ActiveRecord::Base.connection.indexes(original_table_name).each do |index|
49
51
  index index.columns
50
52
  end
51
-
52
53
  end
53
54
  end
54
55
  end
@@ -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
- super(updates.except(:history_user_id))
21
- now = UTC.now
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
- current_histories = history_class.current.where("#{history_class.history_foreign_key} IN (?)", records.map(&:id))
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
- current_histories.update_all(history_ended_at: now)
31
+ def bulk_record_history(records, updates = {})
32
+ now = UTC.now
33
+ history_class = self.klass.history_class
43
34
 
44
- history_class.import new_histories
45
- end
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
@@ -28,6 +28,5 @@ module Historiographer
28
28
  Rollbar.error("history_user_id must be passed in order to save record with histories! If you are in a context with no history_user_id, explicitly call #save_without_history")
29
29
  end
30
30
  end
31
-
32
31
  end
33
32
  end
@@ -91,7 +91,10 @@ module Historiographer
91
91
  end
92
92
 
93
93
  alias_method :destroy_without_history, :destroy
94
- def destroy_with_history(history_user_id: )
94
+
95
+ def destroy_with_history(history_user_id: nil)
96
+ history_user_absent_action if history_user_id.nil?
97
+
95
98
  current_history = histories.where(history_ended_at: nil).order("id desc").limit(1).last
96
99
  current_history.update!(history_ended_at: UTC.now) if current_history.present?
97
100
 
@@ -104,6 +107,7 @@ module Historiographer
104
107
  @no_history = false
105
108
  end
106
109
  end
110
+
107
111
  alias_method :destroy, :destroy_with_history
108
112
 
109
113
  def assign_attributes(new_attributes)
@@ -111,7 +115,7 @@ module Historiographer
111
115
 
112
116
  if huid.present?
113
117
  self.class.nested_attributes_options.each do |association, _|
114
- reflection = self.class.reflect_on_association(association)
118
+ reflection = self.class.reflect_on_association(association)
115
119
  assoc_attrs = new_attributes["#{association}_attributes"]
116
120
 
117
121
  if assoc_attrs.present?
@@ -132,11 +136,12 @@ module Historiographer
132
136
  def historiographer_changes?
133
137
  case Rails.version.to_f
134
138
  when 0..5 then changed? && valid?
135
- when 5.1..6 then saved_changes?
139
+ when 5.1..7 then saved_changes?
136
140
  else
137
141
  raise "Unsupported Rails version"
138
142
  end
139
143
  end
144
+
140
145
  #
141
146
  # If there are any changes, and the model is valid,
142
147
  # and we're not force-overriding history recording,
@@ -193,6 +198,7 @@ module Historiographer
193
198
  end
194
199
  end
195
200
  end
201
+
196
202
  base.send(:prepend, UpdateColumnsWithHistory)
197
203
 
198
204
  def save_without_history(*args, &block)
@@ -222,9 +228,9 @@ module Historiographer
222
228
  def record_history
223
229
  history_user_absent_action if history_user_id.nil?
224
230
 
225
- attrs = attributes.clone
231
+ attrs = attributes.clone
226
232
  history_class = self.class.history_class
227
- foreign_key = history_class.history_foreign_key
233
+ foreign_key = history_class.history_foreign_key
228
234
 
229
235
  now = UTC.now
230
236
  attrs.merge!(foreign_key => attrs["id"], history_started_at: now, history_user_id: history_user_id)
data/spec/db/database.yml CHANGED
@@ -1,14 +1,13 @@
1
- default: &default
1
+ development:
2
2
  adapter: postgresql
3
3
  prepared_statements: false
4
4
  url: "postgres://localhost/historiographer_development"
5
5
 
6
- development:
7
- <<: *default
8
-
9
6
  test:
10
7
  adapter: postgresql
11
8
  database: historiographer_test
9
+ url: "postgres://localhost/historiographer_test"
10
+
12
11
  # mysql_default: &mysql_default
13
12
  # adapter: mysql2
14
13
  # encoding: utf8
data/spec/db/schema.rb CHANGED
@@ -2,11 +2,11 @@
2
2
  # of editing this file, please use the migrations feature of Active Record to
3
3
  # incrementally modify your database, and then regenerate this schema definition.
4
4
  #
5
- # Note that this schema.rb definition is the authoritative source for your
6
- # database schema. If you need to create the application database on another
7
- # system, you should be using db:schema:load, not running all the migrations
8
- # from scratch. The latter is a flawed and unsustainable approach (the more migrations
9
- # you'll amass, the slower it'll run and the greater likelihood for issues).
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
data/spec/examples.txt CHANGED
@@ -1,21 +1,29 @@
1
- example_id | status | run_time |
2
- --------------------------------------- | ------ | --------------- |
3
- ./spec/historiographer_spec.rb[1:1:1] | passed | 0.00794 seconds |
4
- ./spec/historiographer_spec.rb[1:1:2] | passed | 0.04572 seconds |
5
- ./spec/historiographer_spec.rb[1:1:3] | passed | 0.03308 seconds |
6
- ./spec/historiographer_spec.rb[1:2:1] | passed | 0.0742 seconds |
7
- ./spec/historiographer_spec.rb[1:2:2] | passed | 0.00138 seconds |
8
- ./spec/historiographer_spec.rb[1:2:3:1] | passed | 0.01369 seconds |
9
- ./spec/historiographer_spec.rb[1:2:3:2] | passed | 0.059 seconds |
10
- ./spec/historiographer_spec.rb[1:2:3:3] | passed | 0.00794 seconds |
11
- ./spec/historiographer_spec.rb[1:2:4] | passed | 0.00348 seconds |
12
- ./spec/historiographer_spec.rb[1:2:5] | passed | 0.03144 seconds |
13
- ./spec/historiographer_spec.rb[1:2:6] | passed | 0.01239 seconds |
14
- ./spec/historiographer_spec.rb[1:3:1] | passed | 0.04853 seconds |
15
- ./spec/historiographer_spec.rb[1:4:1] | passed | 0.03917 seconds |
16
- ./spec/historiographer_spec.rb[1:5:1] | passed | 0.03402 seconds |
17
- ./spec/historiographer_spec.rb[1:5:2] | passed | 0.02494 seconds |
18
- ./spec/historiographer_spec.rb[1:6:1] | passed | 0.0287 seconds |
19
- ./spec/historiographer_spec.rb[1:7:1] | passed | 0.07329 seconds |
20
- ./spec/historiographer_spec.rb[1:7:2] | passed | 0.01293 seconds |
21
- ./spec/historiographer_spec.rb[1:8:1] | passed | 0.08211 seconds |
1
+ example_id | status | run_time |
2
+ ----------------------------------------- | ------ | --------------- |
3
+ ./spec/historiographer_spec.rb[1:1:1] | passed | 0.00973 seconds |
4
+ ./spec/historiographer_spec.rb[1:1:2] | passed | 0.01848 seconds |
5
+ ./spec/historiographer_spec.rb[1:1:3] | passed | 0.0092 seconds |
6
+ ./spec/historiographer_spec.rb[1:2:1] | passed | 0.02492 seconds |
7
+ ./spec/historiographer_spec.rb[1:2:2] | passed | 0.00099 seconds |
8
+ ./spec/historiographer_spec.rb[1:2:3:1:1] | passed | 0.13892 seconds |
9
+ ./spec/historiographer_spec.rb[1:2:3:1:2] | passed | 0.1202 seconds |
10
+ ./spec/historiographer_spec.rb[1:2:3:2:1] | passed | 0.02734 seconds |
11
+ ./spec/historiographer_spec.rb[1:2:3:2:2] | passed | 0.04699 seconds |
12
+ ./spec/historiographer_spec.rb[1:2:3:2:3] | passed | 0.02185 seconds |
13
+ ./spec/historiographer_spec.rb[1:2:3:3:1] | passed | 0.08042 seconds |
14
+ ./spec/historiographer_spec.rb[1:2:3:3:2] | passed | 0.02825 seconds |
15
+ ./spec/historiographer_spec.rb[1:2:4:1] | passed | 0.02411 seconds |
16
+ ./spec/historiographer_spec.rb[1:2:4:2] | passed | 0.01286 seconds |
17
+ ./spec/historiographer_spec.rb[1:2:4:3] | passed | 0.00469 seconds |
18
+ ./spec/historiographer_spec.rb[1:2:5] | passed | 0.00478 seconds |
19
+ ./spec/historiographer_spec.rb[1:2:6] | passed | 0.0035 seconds |
20
+ ./spec/historiographer_spec.rb[1:2:7] | passed | 0.01157 seconds |
21
+ ./spec/historiographer_spec.rb[1:3:1] | passed | 0.09042 seconds |
22
+ ./spec/historiographer_spec.rb[1:4:1] | passed | 0.05553 seconds |
23
+ ./spec/historiographer_spec.rb[1:5:1] | passed | 0.0104 seconds |
24
+ ./spec/historiographer_spec.rb[1:5:2] | passed | 0.00905 seconds |
25
+ ./spec/historiographer_spec.rb[1:6:1] | passed | 0.02652 seconds |
26
+ ./spec/historiographer_spec.rb[1:6:2] | passed | 0.04419 seconds |
27
+ ./spec/historiographer_spec.rb[1:7:1] | passed | 0.02102 seconds |
28
+ ./spec/historiographer_spec.rb[1:8:1] | passed | 0.02556 seconds |
29
+ ./spec/historiographer_spec.rb[1:9:1] | passed | 0.01444 seconds |
@@ -10,6 +10,7 @@ end
10
10
 
11
11
  class SafePost < ActiveRecord::Base
12
12
  include Historiographer::Safe
13
+ acts_as_paranoid
13
14
  end
14
15
 
15
16
  class SafePostHistory < ActiveRecord::Base
@@ -164,9 +165,14 @@ describe Historiographer do
164
165
  expect(posts.second.current_history.title).to eq "My New Post Title"
165
166
  expect(posts.third.current_history.title).to eq "Brett's Post"
166
167
 
168
+ # It does not update histories if nothing changed
169
+ Post.all.update_all(title: "Brett's Post", history_user_id: 1)
170
+ posts = Post.all.reload.order(:id)
171
+ expect(posts.map(&:histories).map(&:count)).to all(eq 3)
172
+
167
173
  posts.update_all_without_history(title: "Untracked")
168
174
  expect(posts.first.histories.count).to eq 3
169
- expect(posts.second.histories.count).to eq 2
175
+ expect(posts.second.histories.count).to eq 3
170
176
  expect(posts.third.histories.count).to eq 3
171
177
 
172
178
  thing1 = ThingWithoutHistory.create(name: "Thing 1")
@@ -440,6 +446,30 @@ describe Historiographer do
440
446
  expect(PostHistory.where.not(deleted_at: nil).count).to eq 1
441
447
  expect(PostHistory.last.history_user_id).to eq 2
442
448
  end
449
+
450
+ it "works with Historiographer::Safe" do
451
+ post = SafePost.create(title: "HELLO", body: "YO", author_id: 1)
452
+
453
+ expect {
454
+ post.destroy
455
+ }.to_not raise_error
456
+
457
+ expect(SafePost.count).to eq 0
458
+ expect(post.deleted_at).to_not be_nil
459
+ expect(SafePostHistory.count).to eq 2
460
+ expect(SafePostHistory.current.last.deleted_at).to eq post.deleted_at
461
+
462
+ post2 = SafePost.create(title: "HELLO", body: "YO", author_id: 1)
463
+
464
+ expect {
465
+ post2.destroy!
466
+ }.to_not raise_error
467
+
468
+ expect(SafePost.count).to eq 0
469
+ expect(post2.deleted_at).to_not be_nil
470
+ expect(SafePostHistory.count).to eq 4
471
+ expect(SafePostHistory.current.where(safe_post_id: post2.id).last.deleted_at).to eq post2.deleted_at
472
+ end
443
473
  end
444
474
 
445
475
  describe "Scopes" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: historiographer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - brettshollenberger
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-11 00:00:00.000000000 Z
11
+ date: 2022-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '5.1'
19
+ version: '6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '5.1'
26
+ version: '6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 0.4.10
103
+ version: '0.5'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 0.4.10
110
+ version: '0.5'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: standalone_migrations
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -255,7 +255,7 @@ homepage: http://github.com/brettshollenberger/historiographer
255
255
  licenses:
256
256
  - MIT
257
257
  metadata: {}
258
- post_install_message:
258
+ post_install_message:
259
259
  rdoc_options: []
260
260
  require_paths:
261
261
  - lib
@@ -270,8 +270,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
270
  - !ruby/object:Gem::Version
271
271
  version: '0'
272
272
  requirements: []
273
- rubygems_version: 3.0.3
274
- signing_key:
273
+ rubygems_version: 3.2.23
274
+ signing_key:
275
275
  specification_version: 4
276
276
  summary: Create histories of your ActiveRecord tables
277
277
  test_files: []