acts_as_scrubbable 1.4.0 → 2.1.1
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 +5 -5
- 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 +19 -16
- 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: 7fd0a4a434939fca6bd900a3a8d9add32055f9cc727e4dffbc2bf557a00cbb47
|
|
4
|
+
data.tar.gz: 6606ec1824f14d10ed43bd310621551970b6cd921fd6a73d1935b41dfb0025dc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 84806a9849b90c498156b9aab9a3c7a4660d522cdcaf6aba7844675db430dcdd4afeb8fa7dea210190dce76f479d564cfc8bba56e88ce44647a0d954a4f6688d
|
|
7
|
+
data.tar.gz: cac874269684e74d817edfa4bd2712c0276a86806efc86430593600b3494b00fecb411864266fae3b4bcb742ec4c1d8273d1968b2393ac0e1369baea0c904106
|
data/.gitignore
CHANGED
data/acts_as_scrubbable.gemspec
CHANGED
|
@@ -11,13 +11,13 @@ Gem::Specification.new do |s|
|
|
|
11
11
|
s.summary = %q{Scrubbing data made easy}
|
|
12
12
|
s.description = %q{ActsAsScrubbable helps you scrub your database the easy way with mock data at the ActiveRecord level}
|
|
13
13
|
s.license = "MIT"
|
|
14
|
-
s.required_ruby_version = '
|
|
14
|
+
s.required_ruby_version = ['>= 2.0', '< 4.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
|
-
s.add_runtime_dependency 'highline' , '>= 1.
|
|
20
|
+
s.add_runtime_dependency 'highline' , '>= 2.1.0'
|
|
21
21
|
s.add_runtime_dependency 'term-ansicolor' , '>= 1.3'
|
|
22
22
|
s.add_runtime_dependency 'parallel' , '>= 1.6'
|
|
23
23
|
|
|
@@ -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: 1.
|
|
4
|
+
version: 2.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Samer Masry
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2023-01-09 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'
|
|
@@ -90,14 +90,14 @@ dependencies:
|
|
|
90
90
|
requirements:
|
|
91
91
|
- - ">="
|
|
92
92
|
- !ruby/object:Gem::Version
|
|
93
|
-
version:
|
|
93
|
+
version: 2.1.0
|
|
94
94
|
type: :runtime
|
|
95
95
|
prerelease: false
|
|
96
96
|
version_requirements: !ruby/object:Gem::Requirement
|
|
97
97
|
requirements:
|
|
98
98
|
- - ">="
|
|
99
99
|
- !ruby/object:Gem::Version
|
|
100
|
-
version:
|
|
100
|
+
version: 2.1.0
|
|
101
101
|
- !ruby/object:Gem::Dependency
|
|
102
102
|
name: term-ansicolor
|
|
103
103
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -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
|
|
@@ -249,15 +249,18 @@ homepage: https://github.com/smasry/acts_as_scrubbable
|
|
|
249
249
|
licenses:
|
|
250
250
|
- MIT
|
|
251
251
|
metadata: {}
|
|
252
|
-
post_install_message:
|
|
252
|
+
post_install_message:
|
|
253
253
|
rdoc_options: []
|
|
254
254
|
require_paths:
|
|
255
255
|
- lib
|
|
256
256
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
257
257
|
requirements:
|
|
258
|
-
- - "
|
|
258
|
+
- - ">="
|
|
259
259
|
- !ruby/object:Gem::Version
|
|
260
260
|
version: '2.0'
|
|
261
|
+
- - "<"
|
|
262
|
+
- !ruby/object:Gem::Version
|
|
263
|
+
version: '4.0'
|
|
261
264
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
262
265
|
requirements:
|
|
263
266
|
- - ">="
|
|
@@ -265,16 +268,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
265
268
|
version: '0'
|
|
266
269
|
requirements: []
|
|
267
270
|
rubygems_version: 3.1.4
|
|
268
|
-
signing_key:
|
|
271
|
+
signing_key:
|
|
269
272
|
specification_version: 4
|
|
270
273
|
summary: Scrubbing data made easy
|
|
271
274
|
test_files:
|
|
272
|
-
- spec/db/database.yml
|
|
273
275
|
- spec/db/schema.rb
|
|
274
276
|
- spec/lib/acts_as_scrubbable/ar_class_processor_spec.rb
|
|
275
277
|
- spec/lib/acts_as_scrubbable/import_processor_spec.rb
|
|
276
278
|
- spec/lib/acts_as_scrubbable/scrub_spec.rb
|
|
277
279
|
- spec/lib/acts_as_scrubbable/scrubbable_spec.rb
|
|
280
|
+
- spec/lib/acts_as_scrubbable/task_runner_spec.rb
|
|
278
281
|
- spec/lib/acts_as_scrubbable/update_processor_spec.rb
|
|
279
282
|
- spec/spec_helper.rb
|
|
280
283
|
- spec/support/database.rb
|
data/spec/db/database.yml
DELETED