acts_as_scrubbable 1.4.0 → 2.0.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 +2 -1
- data/acts_as_scrubbable.gemspec +3 -3
- data/lib/acts_as_scrubbable/task_runner.rb +4 -4
- data/lib/acts_as_scrubbable/version.rb +1 -1
- data/spec/lib/acts_as_scrubbable/task_runner_spec.rb +143 -0
- data/spec/support/database.rb +12 -8
- metadata +10 -10
- data/spec/db/database.yml +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21f5d280a1785c5fa8107fa5d7a0f53939c00cb4426ac0bf1fdf22dc91e09c2c
|
4
|
+
data.tar.gz: d4d78fba1d4274380b77f090fe6673c0f07ccd97ed785ab7eefcb26f4a96bf29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff835f166087c1bdf1e950a3fbec2e7c618773af25e271714faba04ccd5860626228fdc6fc4c18521d9ac58f0b960d8a142edb8cab0adca42a6878e1d22ef7cc
|
7
|
+
data.tar.gz: 34862f07b833fbe839b8838b628e6eb6ba4305fe06f1c5bb8d4ba2b41de193c9248a2dc8800fd6abe887351e7df64583134dd7f7a12c719d06e7ee9121822ab9
|
data/.gitignore
CHANGED
data/acts_as_scrubbable.gemspec
CHANGED
@@ -13,9 +13,9 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.license = "MIT"
|
14
14
|
s.required_ruby_version = '~> 2.0'
|
15
15
|
|
16
|
-
s.add_runtime_dependency 'activesupport' , '>=
|
17
|
-
s.add_runtime_dependency 'activerecord' , '>=
|
18
|
-
s.add_runtime_dependency 'railties' , '>=
|
16
|
+
s.add_runtime_dependency 'activesupport' , '>= 6.1', '< 8'
|
17
|
+
s.add_runtime_dependency 'activerecord' , '>= 6.1', '< 8'
|
18
|
+
s.add_runtime_dependency 'railties' , '>= 6.1', '< 8'
|
19
19
|
s.add_runtime_dependency 'faker' , '>= 1.4'
|
20
20
|
s.add_runtime_dependency 'highline' , '>= 1.7'
|
21
21
|
s.add_runtime_dependency 'term-ansicolor' , '>= 1.3'
|
@@ -13,8 +13,8 @@ module ActsAsScrubbable
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def prompt_db_configuration
|
16
|
-
db_host = ActiveRecord::Base.
|
17
|
-
db_name = ActiveRecord::Base.
|
16
|
+
db_host = ActiveRecord::Base.connection_db_config.host
|
17
|
+
db_name = ActiveRecord::Base.connection_db_config.database
|
18
18
|
|
19
19
|
ActsAsScrubbable.logger.warn Term::ANSIColor.red("Please verify the information below to continue")
|
20
20
|
ActsAsScrubbable.logger.warn Term::ANSIColor.red("Host: ") + Term::ANSIColor.white(" #{db_host}")
|
@@ -22,10 +22,10 @@ module ActsAsScrubbable
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def confirmed_configuration?
|
25
|
-
db_host = ActiveRecord::Base.
|
25
|
+
db_host = ActiveRecord::Base.connection_db_config.host
|
26
26
|
|
27
27
|
unless ENV["SKIP_CONFIRM"] == "true"
|
28
|
-
answer = ask("Type '#{db_host}' to continue. \n"
|
28
|
+
answer = ask(Term::ANSIColor.red("Type '#{db_host}' to continue. \n") + Term::ANSIColor.white("-> "))
|
29
29
|
unless answer == db_host
|
30
30
|
ActsAsScrubbable.logger.error Term::ANSIColor.red("exiting ...")
|
31
31
|
return false
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe ActsAsScrubbable::TaskRunner do
|
4
|
+
subject(:runner) { described_class.new }
|
5
|
+
|
6
|
+
let(:logger) { instance_double("Logger", error: nil, info: nil, warn: nil) }
|
7
|
+
before do
|
8
|
+
allow(ActsAsScrubbable).to receive(:logger).and_return(logger)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#prompt_db_configuration" do
|
12
|
+
it "reports database host and name" do
|
13
|
+
runner.prompt_db_configuration
|
14
|
+
expect(logger).to have_received(:warn).with(/Host:/)
|
15
|
+
expect(logger).to have_received(:warn).with(/Database:/)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#confirmed_configuration?" do
|
20
|
+
before do
|
21
|
+
allow(runner).to receive(:ask).and_return(answer)
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when answer matches database host" do
|
25
|
+
let(:answer) { ActiveRecord::Base.connection_db_config.host }
|
26
|
+
|
27
|
+
it "is true" do
|
28
|
+
expect(runner).to be_confirmed_configuration
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when answer does not match database host" do
|
33
|
+
let(:answer) { "anything else" }
|
34
|
+
|
35
|
+
it "is false" do
|
36
|
+
expect(runner).not_to be_confirmed_configuration
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#scrub" do
|
42
|
+
let(:application) { instance_double("Rails::Application", eager_load!: nil) }
|
43
|
+
let(:processor) { instance_double("ActsAsScrubbable::ArClassProcessor", process: nil) }
|
44
|
+
before do
|
45
|
+
allow(Rails).to receive(:application).and_return(application)
|
46
|
+
allow(ActsAsScrubbable::ArClassProcessor).to receive(:new).and_return(processor)
|
47
|
+
# RSpec mocks are not tracking calls across the forks that Parallel creates, so stub it out
|
48
|
+
allow(Parallel).to receive(:each) do |array, &block|
|
49
|
+
array.each(&block)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "scrubs all scrubbable classes", :aggregate_failures do
|
54
|
+
runner.extract_ar_classes
|
55
|
+
runner.scrub(num_of_batches: 1)
|
56
|
+
expect(processor).to have_received(:process).with(1).exactly(3).times
|
57
|
+
expect(ActsAsScrubbable::ArClassProcessor).to have_received(:new).with(ScrubbableModel)
|
58
|
+
expect(ActsAsScrubbable::ArClassProcessor).to have_received(:new).with(AnotherScrubbableModel)
|
59
|
+
expect(ActsAsScrubbable::ArClassProcessor).to have_received(:new).with(AThirdScrubbableModel)
|
60
|
+
expect(ActsAsScrubbable::ArClassProcessor).not_to have_received(:new).with(NonScrubbableModel)
|
61
|
+
end
|
62
|
+
|
63
|
+
context "if SCRUB_CLASSES is set" do
|
64
|
+
before do
|
65
|
+
allow(ENV).to receive(:[]).and_call_original
|
66
|
+
allow(ENV).to receive(:[]).with("SCRUB_CLASSES").and_return(
|
67
|
+
"NonScrubbableModel,ScrubbableModel,AThirdScrubbableModel",
|
68
|
+
)
|
69
|
+
runner.extract_ar_classes
|
70
|
+
end
|
71
|
+
|
72
|
+
it "only scrubs specified scrubbable classes" do
|
73
|
+
runner.scrub
|
74
|
+
expect(processor).to have_received(:process).twice
|
75
|
+
expect(ActsAsScrubbable::ArClassProcessor).to have_received(:new).with(ScrubbableModel)
|
76
|
+
expect(ActsAsScrubbable::ArClassProcessor).to have_received(:new).with(AThirdScrubbableModel)
|
77
|
+
expect(ActsAsScrubbable::ArClassProcessor).not_to have_received(:new).with(AnotherScrubbableModel)
|
78
|
+
expect(ActsAsScrubbable::ArClassProcessor).not_to have_received(:new).with(NonScrubbableModel)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "if a specific class is set" do
|
83
|
+
before do
|
84
|
+
runner.set_ar_class(AnotherScrubbableModel)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "only scrubs the specified class" do
|
88
|
+
runner.scrub
|
89
|
+
expect(processor).to have_received(:process).once
|
90
|
+
expect(ActsAsScrubbable::ArClassProcessor).to have_received(:new).with(AnotherScrubbableModel)
|
91
|
+
expect(ActsAsScrubbable::ArClassProcessor).not_to have_received(:new).with(ScrubbableModel)
|
92
|
+
expect(ActsAsScrubbable::ArClassProcessor).not_to have_received(:new).with(AThirdScrubbableModel)
|
93
|
+
expect(ActsAsScrubbable::ArClassProcessor).not_to have_received(:new).with(NonScrubbableModel)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#before_hooks" do
|
99
|
+
before do
|
100
|
+
allow(ActsAsScrubbable).to receive(:execute_before_hook)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "executes before hook" do
|
104
|
+
runner.before_hooks
|
105
|
+
expect(ActsAsScrubbable).to have_received(:execute_before_hook)
|
106
|
+
end
|
107
|
+
|
108
|
+
context "if SKIP_BEFOREHOOK is set" do
|
109
|
+
before do
|
110
|
+
allow(ENV).to receive(:[]).and_call_original
|
111
|
+
allow(ENV).to receive(:[]).with("SKIP_BEFOREHOOK").and_return("true")
|
112
|
+
end
|
113
|
+
|
114
|
+
it "does nothing" do
|
115
|
+
runner.before_hooks
|
116
|
+
expect(ActsAsScrubbable).not_to have_received(:execute_before_hook)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "#after_hooks" do
|
122
|
+
before do
|
123
|
+
allow(ActsAsScrubbable).to receive(:execute_after_hook)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "executes after hook" do
|
127
|
+
runner.after_hooks
|
128
|
+
expect(ActsAsScrubbable).to have_received(:execute_after_hook)
|
129
|
+
end
|
130
|
+
|
131
|
+
context "if SKIP_AFTERHOOK is set" do
|
132
|
+
before do
|
133
|
+
allow(ENV).to receive(:[]).and_call_original
|
134
|
+
allow(ENV).to receive(:[]).with("SKIP_AFTERHOOK").and_return("true")
|
135
|
+
end
|
136
|
+
|
137
|
+
it "does nothing" do
|
138
|
+
runner.after_hooks
|
139
|
+
expect(ActsAsScrubbable).not_to have_received(:execute_after_hook)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
data/spec/support/database.rb
CHANGED
@@ -1,14 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "nulldb/rails"
|
2
|
+
require "nulldb_rspec"
|
3
3
|
|
4
|
-
|
5
|
-
ActiveRecord::Base.configurations.merge!("test" => {adapter: 'nulldb'})
|
6
|
-
else
|
7
|
-
ActiveRecord::Base.configurations = ActiveRecord::DatabaseConfigurations.new(test: {adapter: 'nulldb'})
|
8
|
-
end
|
4
|
+
ActiveRecord::Base.configurations = ActiveRecord::DatabaseConfigurations.new(test: {adapter: "nulldb"})
|
9
5
|
|
10
6
|
NullDB.configure do |c|
|
11
|
-
c.project_root =
|
7
|
+
c.project_root = "./spec"
|
12
8
|
end
|
13
9
|
|
14
10
|
RSpec.configure do |config|
|
@@ -49,3 +45,11 @@ class ScrubbableModel < ActiveRecord::Base
|
|
49
45
|
self.scrubbing_finished = true
|
50
46
|
end
|
51
47
|
end
|
48
|
+
|
49
|
+
class AnotherScrubbableModel < ActiveRecord::Base
|
50
|
+
acts_as_scrubbable :active => :boolean
|
51
|
+
end
|
52
|
+
|
53
|
+
class AThirdScrubbableModel < ActiveRecord::Base
|
54
|
+
acts_as_scrubbable :active => :boolean
|
55
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_scrubbable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samer Masry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.1'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '8'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '6.1'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '8'
|
@@ -36,7 +36,7 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
39
|
+
version: '6.1'
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '8'
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '
|
49
|
+
version: '6.1'
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '8'
|
@@ -56,7 +56,7 @@ dependencies:
|
|
56
56
|
requirements:
|
57
57
|
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: '
|
59
|
+
version: '6.1'
|
60
60
|
- - "<"
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '8'
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
requirements:
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
69
|
+
version: '6.1'
|
70
70
|
- - "<"
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: '8'
|
@@ -236,12 +236,12 @@ files:
|
|
236
236
|
- lib/acts_as_scrubbable/tasks.rb
|
237
237
|
- lib/acts_as_scrubbable/update_processor.rb
|
238
238
|
- lib/acts_as_scrubbable/version.rb
|
239
|
-
- spec/db/database.yml
|
240
239
|
- spec/db/schema.rb
|
241
240
|
- spec/lib/acts_as_scrubbable/ar_class_processor_spec.rb
|
242
241
|
- spec/lib/acts_as_scrubbable/import_processor_spec.rb
|
243
242
|
- spec/lib/acts_as_scrubbable/scrub_spec.rb
|
244
243
|
- spec/lib/acts_as_scrubbable/scrubbable_spec.rb
|
244
|
+
- spec/lib/acts_as_scrubbable/task_runner_spec.rb
|
245
245
|
- spec/lib/acts_as_scrubbable/update_processor_spec.rb
|
246
246
|
- spec/spec_helper.rb
|
247
247
|
- spec/support/database.rb
|
@@ -269,12 +269,12 @@ signing_key:
|
|
269
269
|
specification_version: 4
|
270
270
|
summary: Scrubbing data made easy
|
271
271
|
test_files:
|
272
|
-
- spec/db/database.yml
|
273
272
|
- spec/db/schema.rb
|
274
273
|
- spec/lib/acts_as_scrubbable/ar_class_processor_spec.rb
|
275
274
|
- spec/lib/acts_as_scrubbable/import_processor_spec.rb
|
276
275
|
- spec/lib/acts_as_scrubbable/scrub_spec.rb
|
277
276
|
- spec/lib/acts_as_scrubbable/scrubbable_spec.rb
|
277
|
+
- spec/lib/acts_as_scrubbable/task_runner_spec.rb
|
278
278
|
- spec/lib/acts_as_scrubbable/update_processor_spec.rb
|
279
279
|
- spec/spec_helper.rb
|
280
280
|
- spec/support/database.rb
|
data/spec/db/database.yml
DELETED