acts_as_scrubbable 0.0.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 +7 -0
- data/.rspec +2 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +134 -0
- data/Guardfile +70 -0
- data/README.md +36 -0
- data/acts_as_scrubbable.gemspec +34 -0
- data/lib/acts_as_scrubbable/scrub.rb +44 -0
- data/lib/acts_as_scrubbable/scrubbable.rb +36 -0
- data/lib/acts_as_scrubbable/tasks.rb +40 -0
- data/lib/acts_as_scrubbable/version.rb +3 -0
- data/lib/acts_as_scrubbable.rb +18 -0
- data/spec/db/database.yml +2 -0
- data/spec/db/schema.rb +8 -0
- data/spec/lib/acts_as_scrubbable/scrub_spec.rb +35 -0
- data/spec/lib/acts_as_scrubbable/scrubbable_spec.rb +33 -0
- data/spec/spec_helper.rb +104 -0
- data/spec/support/database.rb +19 -0
- metadata +237 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 506eed204743c2535bcd8c437775b5e8d6b3d2a8
|
|
4
|
+
data.tar.gz: 6bce5efb2ca185f2b7db1947e8d6846350a47da4
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b71edf80be083447af3df693eb8429b47ff8c900c203bf1072c6a744d45a8dd6119359aafe257156a57193f06c3c777b8c3c54e3de8122c14950ed9c7245a48b
|
|
7
|
+
data.tar.gz: 05aeb0d66ac9763fef8574dcbca5793ccdb44c849b165a3f4004afd25c85ad2beaa672c7e7f4dc9f6cc79a67c1c3063b151fb9e074adf4b3b231dee9448979f6
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
acts_as_scrubbable (0.0.1)
|
|
5
|
+
activerecord (~> 4.1.13)
|
|
6
|
+
activesupport (~> 4.1.13)
|
|
7
|
+
faker (~> 1.4.3)
|
|
8
|
+
highline (~> 1.7.8)
|
|
9
|
+
railties (~> 4.1.13)
|
|
10
|
+
term-ansicolor (~> 1.3.2)
|
|
11
|
+
|
|
12
|
+
GEM
|
|
13
|
+
remote: https://rubygems.org/
|
|
14
|
+
specs:
|
|
15
|
+
actionpack (4.1.13)
|
|
16
|
+
actionview (= 4.1.13)
|
|
17
|
+
activesupport (= 4.1.13)
|
|
18
|
+
rack (~> 1.5.2)
|
|
19
|
+
rack-test (~> 0.6.2)
|
|
20
|
+
actionview (4.1.13)
|
|
21
|
+
activesupport (= 4.1.13)
|
|
22
|
+
builder (~> 3.1)
|
|
23
|
+
erubis (~> 2.7.0)
|
|
24
|
+
activemodel (4.1.13)
|
|
25
|
+
activesupport (= 4.1.13)
|
|
26
|
+
builder (~> 3.1)
|
|
27
|
+
activerecord (4.1.13)
|
|
28
|
+
activemodel (= 4.1.13)
|
|
29
|
+
activesupport (= 4.1.13)
|
|
30
|
+
arel (~> 5.0.0)
|
|
31
|
+
activerecord-nulldb-adapter (0.3.1)
|
|
32
|
+
activerecord (>= 2.0.0)
|
|
33
|
+
activesupport (4.1.13)
|
|
34
|
+
i18n (~> 0.6, >= 0.6.9)
|
|
35
|
+
json (~> 1.7, >= 1.7.7)
|
|
36
|
+
minitest (~> 5.1)
|
|
37
|
+
thread_safe (~> 0.1)
|
|
38
|
+
tzinfo (~> 1.1)
|
|
39
|
+
arel (5.0.1.20140414130214)
|
|
40
|
+
builder (3.2.2)
|
|
41
|
+
byebug (5.0.0)
|
|
42
|
+
columnize (= 0.9.0)
|
|
43
|
+
coderay (1.1.0)
|
|
44
|
+
columnize (0.9.0)
|
|
45
|
+
diff-lcs (1.2.5)
|
|
46
|
+
erubis (2.7.0)
|
|
47
|
+
faker (1.4.3)
|
|
48
|
+
i18n (~> 0.5)
|
|
49
|
+
ffi (1.9.10)
|
|
50
|
+
formatador (0.2.5)
|
|
51
|
+
guard (2.13.0)
|
|
52
|
+
formatador (>= 0.2.4)
|
|
53
|
+
listen (>= 2.7, <= 4.0)
|
|
54
|
+
lumberjack (~> 1.0)
|
|
55
|
+
nenv (~> 0.1)
|
|
56
|
+
notiffany (~> 0.0)
|
|
57
|
+
pry (>= 0.9.12)
|
|
58
|
+
shellany (~> 0.0)
|
|
59
|
+
thor (>= 0.18.1)
|
|
60
|
+
guard-compat (1.2.1)
|
|
61
|
+
guard-rspec (4.6.4)
|
|
62
|
+
guard (~> 2.1)
|
|
63
|
+
guard-compat (~> 1.1)
|
|
64
|
+
rspec (>= 2.99.0, < 4.0)
|
|
65
|
+
highline (1.7.8)
|
|
66
|
+
i18n (0.7.0)
|
|
67
|
+
json (1.8.3)
|
|
68
|
+
listen (3.0.3)
|
|
69
|
+
rb-fsevent (>= 0.9.3)
|
|
70
|
+
rb-inotify (>= 0.9)
|
|
71
|
+
lumberjack (1.0.9)
|
|
72
|
+
method_source (0.8.2)
|
|
73
|
+
minitest (5.8.2)
|
|
74
|
+
nenv (0.2.0)
|
|
75
|
+
notiffany (0.0.8)
|
|
76
|
+
nenv (~> 0.1)
|
|
77
|
+
shellany (~> 0.0)
|
|
78
|
+
pry (0.10.3)
|
|
79
|
+
coderay (~> 1.1.0)
|
|
80
|
+
method_source (~> 0.8.1)
|
|
81
|
+
slop (~> 3.4)
|
|
82
|
+
pry-byebug (3.2.0)
|
|
83
|
+
byebug (~> 5.0)
|
|
84
|
+
pry (~> 0.10)
|
|
85
|
+
rack (1.5.5)
|
|
86
|
+
rack-test (0.6.3)
|
|
87
|
+
rack (>= 1.0)
|
|
88
|
+
railties (4.1.13)
|
|
89
|
+
actionpack (= 4.1.13)
|
|
90
|
+
activesupport (= 4.1.13)
|
|
91
|
+
rake (>= 0.8.7)
|
|
92
|
+
thor (>= 0.18.1, < 2.0)
|
|
93
|
+
rake (10.4.2)
|
|
94
|
+
rb-fsevent (0.9.6)
|
|
95
|
+
rb-inotify (0.9.5)
|
|
96
|
+
ffi (>= 0.5.0)
|
|
97
|
+
rspec (3.3.0)
|
|
98
|
+
rspec-core (~> 3.3.0)
|
|
99
|
+
rspec-expectations (~> 3.3.0)
|
|
100
|
+
rspec-mocks (~> 3.3.0)
|
|
101
|
+
rspec-core (3.3.2)
|
|
102
|
+
rspec-support (~> 3.3.0)
|
|
103
|
+
rspec-expectations (3.3.1)
|
|
104
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
105
|
+
rspec-support (~> 3.3.0)
|
|
106
|
+
rspec-mocks (3.3.2)
|
|
107
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
108
|
+
rspec-support (~> 3.3.0)
|
|
109
|
+
rspec-support (3.3.0)
|
|
110
|
+
shellany (0.0.1)
|
|
111
|
+
slop (3.6.0)
|
|
112
|
+
term-ansicolor (1.3.2)
|
|
113
|
+
tins (~> 1.0)
|
|
114
|
+
terminal-notifier-guard (1.6.4)
|
|
115
|
+
thor (0.19.1)
|
|
116
|
+
thread_safe (0.3.5)
|
|
117
|
+
tins (1.6.0)
|
|
118
|
+
tzinfo (1.2.2)
|
|
119
|
+
thread_safe (~> 0.1)
|
|
120
|
+
|
|
121
|
+
PLATFORMS
|
|
122
|
+
ruby
|
|
123
|
+
|
|
124
|
+
DEPENDENCIES
|
|
125
|
+
activerecord-nulldb-adapter (~> 0.3.1)
|
|
126
|
+
acts_as_scrubbable!
|
|
127
|
+
guard (~> 2.13.0)
|
|
128
|
+
guard-rspec (~> 4.6.4)
|
|
129
|
+
pry-byebug (~> 3.2.0)
|
|
130
|
+
rspec (~> 3.3.0)
|
|
131
|
+
terminal-notifier-guard (~> 1.6.4)
|
|
132
|
+
|
|
133
|
+
BUNDLED WITH
|
|
134
|
+
1.10.6
|
data/Guardfile
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# A sample Guardfile
|
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
|
3
|
+
|
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
|
5
|
+
# directories %w(app lib config test spec features) \
|
|
6
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
|
7
|
+
|
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
|
11
|
+
#
|
|
12
|
+
# $ mkdir config
|
|
13
|
+
# $ mv Guardfile config/
|
|
14
|
+
# $ ln -s config/Guardfile .
|
|
15
|
+
#
|
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
|
17
|
+
|
|
18
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
|
19
|
+
# rspec may be run, below are examples of the most common uses.
|
|
20
|
+
# * bundler: 'bundle exec rspec'
|
|
21
|
+
# * bundler binstubs: 'bin/rspec'
|
|
22
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
|
23
|
+
# installed the spring binstubs per the docs)
|
|
24
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
|
25
|
+
# * 'just' rspec: 'rspec'
|
|
26
|
+
|
|
27
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
|
28
|
+
require "guard/rspec/dsl"
|
|
29
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
|
30
|
+
|
|
31
|
+
# Feel free to open issues for suggestions and improvements
|
|
32
|
+
|
|
33
|
+
# RSpec files
|
|
34
|
+
rspec = dsl.rspec
|
|
35
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
|
36
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
|
37
|
+
watch(rspec.spec_files)
|
|
38
|
+
|
|
39
|
+
# Ruby files
|
|
40
|
+
ruby = dsl.ruby
|
|
41
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
|
42
|
+
|
|
43
|
+
# Rails files
|
|
44
|
+
rails = dsl.rails(view_extensions: %w(erb haml slim))
|
|
45
|
+
dsl.watch_spec_files_for(rails.app_files)
|
|
46
|
+
dsl.watch_spec_files_for(rails.views)
|
|
47
|
+
|
|
48
|
+
watch(rails.controllers) do |m|
|
|
49
|
+
[
|
|
50
|
+
rspec.spec.("routing/#{m[1]}_routing"),
|
|
51
|
+
rspec.spec.("controllers/#{m[1]}_controller"),
|
|
52
|
+
rspec.spec.("acceptance/#{m[1]}")
|
|
53
|
+
]
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Rails config changes
|
|
57
|
+
watch(rails.spec_helper) { rspec.spec_dir }
|
|
58
|
+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
|
59
|
+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
|
60
|
+
|
|
61
|
+
# Capybara features specs
|
|
62
|
+
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
|
|
63
|
+
watch(rails.layouts) { |m| rspec.spec.("features/#{m[1]}") }
|
|
64
|
+
|
|
65
|
+
# Turnip features and steps
|
|
66
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
|
67
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
|
68
|
+
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
|
69
|
+
end
|
|
70
|
+
end
|
data/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# ActsAsScrubbable
|
|
2
|
+
|
|
3
|
+
Scrubbing made easy
|
|
4
|
+
|
|
5
|
+
Acts as scrubbable give you model level access to scrub your data per object
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
gem 'acts_as_scrubbable'
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
Simple add the configuration for your fields that map directly to your columns
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
```ruby
|
|
20
|
+
class User < ActiveRecord::Base
|
|
21
|
+
...
|
|
22
|
+
|
|
23
|
+
acts_as_scrubbable :first_name, :last_name
|
|
24
|
+
|
|
25
|
+
...
|
|
26
|
+
end
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
Incase the mapping is not straight forward
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
class Address
|
|
34
|
+
acts_as_scrubbable :lng => :longitude, :lat => :latitude
|
|
35
|
+
end
|
|
36
|
+
```
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
$:.unshift File.expand_path('lib', __dir__)
|
|
2
|
+
require 'acts_as_scrubbable/version'
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |s|
|
|
5
|
+
s.name = 'acts_as_scrubbable'
|
|
6
|
+
s.version = ActsAsScrubbable::VERSION
|
|
7
|
+
s.platform = Gem::Platform::RUBY
|
|
8
|
+
s.authors = ['Samer Masry']
|
|
9
|
+
s.email = ['samer.masry@gmail.com']
|
|
10
|
+
s.homepage = 'https://github.com/smasry/acts_as_scrubbable'
|
|
11
|
+
s.summary = %q{Scrubbing data made easy}
|
|
12
|
+
s.description = %q{ActsAsScrubbable helps you scrub your database the easy way with mock data at the ActiveRecord level}
|
|
13
|
+
s.license = "MIT"
|
|
14
|
+
s.required_ruby_version = '~> 2.0'
|
|
15
|
+
|
|
16
|
+
s.add_runtime_dependency 'activesupport' , '~> 4.1'
|
|
17
|
+
s.add_runtime_dependency 'activerecord' , '~> 4.1'
|
|
18
|
+
s.add_runtime_dependency 'railties' , '~> 4.1'
|
|
19
|
+
s.add_runtime_dependency 'faker' , '~> 1.4'
|
|
20
|
+
s.add_runtime_dependency 'highline' , '~> 1.7'
|
|
21
|
+
s.add_runtime_dependency 'term-ansicolor' , '~> 1.3'
|
|
22
|
+
|
|
23
|
+
s.add_development_dependency 'rspec' , '~> 3.3'
|
|
24
|
+
s.add_development_dependency 'guard' , '~> 2.13'
|
|
25
|
+
s.add_development_dependency 'guard-rspec' , '~> 4.6'
|
|
26
|
+
s.add_development_dependency 'pry-byebug' , '~> 3.2'
|
|
27
|
+
s.add_development_dependency 'terminal-notifier-guard' , '~> 1.6'
|
|
28
|
+
s.add_development_dependency 'activerecord-nulldb-adapter', '~> 0.3'
|
|
29
|
+
|
|
30
|
+
s.files = `git ls-files`.split("\n")
|
|
31
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
|
32
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f).strip }
|
|
33
|
+
s.require_paths = ['lib']
|
|
34
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module ActsAsScrubbable
|
|
2
|
+
module Scrub
|
|
3
|
+
|
|
4
|
+
def scrub!
|
|
5
|
+
require 'faker'
|
|
6
|
+
|
|
7
|
+
if self.class.scrubbable?
|
|
8
|
+
_updates = {}
|
|
9
|
+
scrubbable_fields.each do |key, value|
|
|
10
|
+
next if self.send(key).blank?
|
|
11
|
+
|
|
12
|
+
_updates[key] = if value == :first_name
|
|
13
|
+
Faker::Name.first_name
|
|
14
|
+
elsif value == :last_name
|
|
15
|
+
Faker::Name.last_name
|
|
16
|
+
elsif value == :full_name
|
|
17
|
+
Faker::Name.name
|
|
18
|
+
elsif value == :middle_name
|
|
19
|
+
Faker::Name.name
|
|
20
|
+
elsif value == :street_address
|
|
21
|
+
Faker::Address.street_address
|
|
22
|
+
elsif value == :secondary_address
|
|
23
|
+
Faker::Address.secondary_address
|
|
24
|
+
elsif value == :city
|
|
25
|
+
Faker::Address.city
|
|
26
|
+
elsif value == :latitude
|
|
27
|
+
Faker::Address.latitude
|
|
28
|
+
elsif value == :longitude
|
|
29
|
+
Faker::Address.longitude
|
|
30
|
+
elsif value == :email
|
|
31
|
+
Faker::Internet.email
|
|
32
|
+
elsif value == :name_title
|
|
33
|
+
Faker::Name.title
|
|
34
|
+
elsif value == :company_name
|
|
35
|
+
Faker::Company.name
|
|
36
|
+
else
|
|
37
|
+
nil
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
self.update_columns(_updates) unless _updates.empty?
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module ActsAsScrubbable
|
|
2
|
+
module Scrubbable
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def scrubbable?
|
|
6
|
+
false
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def acts_as_scrubbable(*scrubbable_fields)
|
|
11
|
+
|
|
12
|
+
class_attribute :scrubbable_fields
|
|
13
|
+
|
|
14
|
+
self.scrubbable_fields = {}
|
|
15
|
+
|
|
16
|
+
scrubbable_fields.each do |_field|
|
|
17
|
+
if _field.is_a? Hash
|
|
18
|
+
self.scrubbable_fields[_field.keys.first] = _field.values.first
|
|
19
|
+
else
|
|
20
|
+
self.scrubbable_fields[_field] = _field
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class_eval do
|
|
25
|
+
|
|
26
|
+
def self.scrubbable?
|
|
27
|
+
true
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
include Scrub
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require 'rake'
|
|
2
|
+
|
|
3
|
+
namespace :scrub do
|
|
4
|
+
|
|
5
|
+
desc "scrub all"
|
|
6
|
+
task all: :environment do
|
|
7
|
+
|
|
8
|
+
require 'highline/import'
|
|
9
|
+
require 'term/ansicolor'
|
|
10
|
+
require 'logger'
|
|
11
|
+
|
|
12
|
+
@logger = Logger.new($stdout)
|
|
13
|
+
|
|
14
|
+
answer = ask("Type SCRUB to continue.".red)
|
|
15
|
+
unless answer == "SCRUB"
|
|
16
|
+
puts "exiting ...".red
|
|
17
|
+
exit
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
@logger.warn "Scrubbing classes".red
|
|
21
|
+
|
|
22
|
+
Rails.application.eager_load! # make sure all the classes are loaded
|
|
23
|
+
ActiveRecord::Base.descendants.sort_by{|d| d.to_s }.each do |ar_class|
|
|
24
|
+
next unless ar_class.scrubbable?
|
|
25
|
+
|
|
26
|
+
@logger.info "Scrubbing #{ar_class}".green
|
|
27
|
+
|
|
28
|
+
ar_class.find_in_batches do |batch|
|
|
29
|
+
batch.each do |obj|
|
|
30
|
+
obj.scrub!
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
@logger.info "Scrub Complete!".white
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
desc "Links to scrub:all"
|
|
40
|
+
task :scrub => ['scrub:all']
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'active_record'
|
|
2
|
+
require 'active_record/version'
|
|
3
|
+
require 'active_support/core_ext/module'
|
|
4
|
+
require 'acts_as_scrubbable/tasks'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
module ActsAsScrubbable
|
|
8
|
+
extend ActiveSupport::Autoload
|
|
9
|
+
|
|
10
|
+
autoload :Scrubbable
|
|
11
|
+
autoload :Scrub
|
|
12
|
+
autoload :VERSION
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
ActiveSupport.on_load(:active_record) do
|
|
17
|
+
extend ActsAsScrubbable::Scrubbable
|
|
18
|
+
end
|
data/spec/db/schema.rb
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe ActsAsScrubbable::Scrub do
|
|
4
|
+
|
|
5
|
+
describe '.scrub' do
|
|
6
|
+
|
|
7
|
+
# update_columns cannot be run on a new record
|
|
8
|
+
subject{ ScrubbableModel.new }
|
|
9
|
+
before(:each) { subject.save }
|
|
10
|
+
|
|
11
|
+
it 'changes the first_name attribute when scrub is run' do
|
|
12
|
+
subject.first_name = "Ted"
|
|
13
|
+
allow(Faker::Name).to receive(:first_name).and_return("John")
|
|
14
|
+
subject.scrub!
|
|
15
|
+
expect(subject.first_name).to eq "John"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'calls street address on faker and updates address1' do
|
|
19
|
+
subject.address1 = "123 abc"
|
|
20
|
+
subject.save
|
|
21
|
+
allow(Faker::Address).to receive(:street_address).and_return("1 Embarcadero")
|
|
22
|
+
subject.scrub!
|
|
23
|
+
expect(subject.address1).to eq "1 Embarcadero"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "doesn't update the field if it's blank" do
|
|
27
|
+
subject.address1 = nil
|
|
28
|
+
subject.save
|
|
29
|
+
allow(Faker::Address).to receive(:street_address).and_return("1 Embarcadero")
|
|
30
|
+
subject.scrub!
|
|
31
|
+
expect(subject.address1).to be_nil
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
RSpec.describe ActsAsScrubbable::Scrubbable do
|
|
4
|
+
|
|
5
|
+
context "not scrubbable" do
|
|
6
|
+
subject {NonScrubbableModel.new}
|
|
7
|
+
|
|
8
|
+
describe "scrubbable?" do
|
|
9
|
+
it 'returns false' do
|
|
10
|
+
expect(subject.class.scrubbable?).to eq false
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
context "scrubbable" do
|
|
17
|
+
subject {ScrubbableModel.new}
|
|
18
|
+
|
|
19
|
+
describe "scrubbable?" do
|
|
20
|
+
it 'returns false' do
|
|
21
|
+
expect(subject.class.scrubbable?).to eq true
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
describe "scrubbable_fields" do
|
|
27
|
+
it 'returns the list of scrubbable fields' do
|
|
28
|
+
expect(subject.scrubbable_fields.keys.first).to eq :first_name
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
|
5
|
+
# files.
|
|
6
|
+
#
|
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
|
13
|
+
# it.
|
|
14
|
+
#
|
|
15
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
|
16
|
+
# users commonly want.
|
|
17
|
+
#
|
|
18
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
|
19
|
+
|
|
20
|
+
require 'acts_as_scrubbable'
|
|
21
|
+
require 'active_record/railtie'
|
|
22
|
+
require 'pry-byebug'
|
|
23
|
+
require 'faker'
|
|
24
|
+
|
|
25
|
+
Dir[File.join(__dir__,'support/**/*.rb')].each { |f| require f }
|
|
26
|
+
|
|
27
|
+
RSpec.configure do |config|
|
|
28
|
+
# rspec-expectations config goes here. You can use an alternate
|
|
29
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
|
30
|
+
# assertions if you prefer.
|
|
31
|
+
config.expect_with :rspec do |expectations|
|
|
32
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
|
33
|
+
# and `failure_message` of custom matchers include text for helper methods
|
|
34
|
+
# defined using `chain`, e.g.:
|
|
35
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
|
36
|
+
# # => "be bigger than 2 and smaller than 4"
|
|
37
|
+
# ...rather than:
|
|
38
|
+
# # => "be bigger than 2"
|
|
39
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
|
43
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
|
44
|
+
config.mock_with :rspec do |mocks|
|
|
45
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
|
46
|
+
# a real object. This is generally recommended, and will default to
|
|
47
|
+
# `true` in RSpec 4.
|
|
48
|
+
mocks.verify_partial_doubles = true
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# The settings below are suggested to provide a good initial experience
|
|
52
|
+
# with RSpec, but feel free to customize to your heart's content.
|
|
53
|
+
=begin
|
|
54
|
+
# These two settings work together to allow you to limit a spec run
|
|
55
|
+
# to individual examples or groups you care about by tagging them with
|
|
56
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
|
57
|
+
# get run.
|
|
58
|
+
config.filter_run :focus
|
|
59
|
+
config.run_all_when_everything_filtered = true
|
|
60
|
+
|
|
61
|
+
# Allows RSpec to persist some state between runs in order to support
|
|
62
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
|
63
|
+
# you configure your source control system to ignore this file.
|
|
64
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
|
65
|
+
|
|
66
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
|
67
|
+
# recommended. For more details, see:
|
|
68
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
|
69
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
|
70
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
|
71
|
+
config.disable_monkey_patching!
|
|
72
|
+
|
|
73
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
|
74
|
+
# be too noisy due to issues in dependencies.
|
|
75
|
+
config.warnings = true
|
|
76
|
+
|
|
77
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
|
78
|
+
# file, and it's useful to allow more verbose output when running an
|
|
79
|
+
# individual spec file.
|
|
80
|
+
if config.files_to_run.one?
|
|
81
|
+
# Use the documentation formatter for detailed output,
|
|
82
|
+
# unless a formatter has already been configured
|
|
83
|
+
# (e.g. via a command-line flag).
|
|
84
|
+
config.default_formatter = 'doc'
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Print the 10 slowest examples and example groups at the
|
|
88
|
+
# end of the spec run, to help surface which specs are running
|
|
89
|
+
# particularly slow.
|
|
90
|
+
config.profile_examples = 10
|
|
91
|
+
|
|
92
|
+
# Run specs in random order to surface order dependencies. If you find an
|
|
93
|
+
# order dependency and want to debug it, you can fix the order by providing
|
|
94
|
+
# the seed, which is printed after each run.
|
|
95
|
+
# --seed 1234
|
|
96
|
+
config.order = :random
|
|
97
|
+
|
|
98
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
|
99
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
|
100
|
+
# test failures related to randomization by passing the same `--seed` value
|
|
101
|
+
# as the one that triggered the failure.
|
|
102
|
+
Kernel.srand config.seed
|
|
103
|
+
=end
|
|
104
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'nulldb/rails'
|
|
2
|
+
require 'nulldb_rspec'
|
|
3
|
+
|
|
4
|
+
ActiveRecord::Base.configurations = {"test" => {adapter: :nulldb}}
|
|
5
|
+
|
|
6
|
+
NullDB.configure do |c|
|
|
7
|
+
c.project_root = './spec'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
RSpec.configure do |config|
|
|
11
|
+
config.include include NullDB::RSpec::NullifiedDatabase
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class NonScrubbableModel < ActiveRecord::Base; end
|
|
16
|
+
|
|
17
|
+
class ScrubbableModel < ActiveRecord::Base
|
|
18
|
+
acts_as_scrubbable :first_name, address1: :street_address
|
|
19
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: acts_as_scrubbable
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Samer Masry
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-11-04 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activesupport
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '4.1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '4.1'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: activerecord
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '4.1'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '4.1'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: railties
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '4.1'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '4.1'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: faker
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1.4'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '1.4'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: highline
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '1.7'
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '1.7'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: term-ansicolor
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '1.3'
|
|
90
|
+
type: :runtime
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '1.3'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: rspec
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '3.3'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '3.3'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: guard
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - "~>"
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '2.13'
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - "~>"
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '2.13'
|
|
125
|
+
- !ruby/object:Gem::Dependency
|
|
126
|
+
name: guard-rspec
|
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - "~>"
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: '4.6'
|
|
132
|
+
type: :development
|
|
133
|
+
prerelease: false
|
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - "~>"
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: '4.6'
|
|
139
|
+
- !ruby/object:Gem::Dependency
|
|
140
|
+
name: pry-byebug
|
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
|
142
|
+
requirements:
|
|
143
|
+
- - "~>"
|
|
144
|
+
- !ruby/object:Gem::Version
|
|
145
|
+
version: '3.2'
|
|
146
|
+
type: :development
|
|
147
|
+
prerelease: false
|
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
149
|
+
requirements:
|
|
150
|
+
- - "~>"
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: '3.2'
|
|
153
|
+
- !ruby/object:Gem::Dependency
|
|
154
|
+
name: terminal-notifier-guard
|
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
|
156
|
+
requirements:
|
|
157
|
+
- - "~>"
|
|
158
|
+
- !ruby/object:Gem::Version
|
|
159
|
+
version: '1.6'
|
|
160
|
+
type: :development
|
|
161
|
+
prerelease: false
|
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
163
|
+
requirements:
|
|
164
|
+
- - "~>"
|
|
165
|
+
- !ruby/object:Gem::Version
|
|
166
|
+
version: '1.6'
|
|
167
|
+
- !ruby/object:Gem::Dependency
|
|
168
|
+
name: activerecord-nulldb-adapter
|
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
|
170
|
+
requirements:
|
|
171
|
+
- - "~>"
|
|
172
|
+
- !ruby/object:Gem::Version
|
|
173
|
+
version: '0.3'
|
|
174
|
+
type: :development
|
|
175
|
+
prerelease: false
|
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
177
|
+
requirements:
|
|
178
|
+
- - "~>"
|
|
179
|
+
- !ruby/object:Gem::Version
|
|
180
|
+
version: '0.3'
|
|
181
|
+
description: ActsAsScrubbable helps you scrub your database the easy way with mock
|
|
182
|
+
data at the ActiveRecord level
|
|
183
|
+
email:
|
|
184
|
+
- samer.masry@gmail.com
|
|
185
|
+
executables: []
|
|
186
|
+
extensions: []
|
|
187
|
+
extra_rdoc_files: []
|
|
188
|
+
files:
|
|
189
|
+
- ".rspec"
|
|
190
|
+
- Gemfile
|
|
191
|
+
- Gemfile.lock
|
|
192
|
+
- Guardfile
|
|
193
|
+
- README.md
|
|
194
|
+
- acts_as_scrubbable.gemspec
|
|
195
|
+
- lib/acts_as_scrubbable.rb
|
|
196
|
+
- lib/acts_as_scrubbable/scrub.rb
|
|
197
|
+
- lib/acts_as_scrubbable/scrubbable.rb
|
|
198
|
+
- lib/acts_as_scrubbable/tasks.rb
|
|
199
|
+
- lib/acts_as_scrubbable/version.rb
|
|
200
|
+
- spec/db/database.yml
|
|
201
|
+
- spec/db/schema.rb
|
|
202
|
+
- spec/lib/acts_as_scrubbable/scrub_spec.rb
|
|
203
|
+
- spec/lib/acts_as_scrubbable/scrubbable_spec.rb
|
|
204
|
+
- spec/spec_helper.rb
|
|
205
|
+
- spec/support/database.rb
|
|
206
|
+
homepage: https://github.com/smasry/acts_as_scrubbable
|
|
207
|
+
licenses:
|
|
208
|
+
- MIT
|
|
209
|
+
metadata: {}
|
|
210
|
+
post_install_message:
|
|
211
|
+
rdoc_options: []
|
|
212
|
+
require_paths:
|
|
213
|
+
- lib
|
|
214
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
215
|
+
requirements:
|
|
216
|
+
- - "~>"
|
|
217
|
+
- !ruby/object:Gem::Version
|
|
218
|
+
version: '2.0'
|
|
219
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
|
+
requirements:
|
|
221
|
+
- - ">="
|
|
222
|
+
- !ruby/object:Gem::Version
|
|
223
|
+
version: '0'
|
|
224
|
+
requirements: []
|
|
225
|
+
rubyforge_project:
|
|
226
|
+
rubygems_version: 2.4.8
|
|
227
|
+
signing_key:
|
|
228
|
+
specification_version: 4
|
|
229
|
+
summary: Scrubbing data made easy
|
|
230
|
+
test_files:
|
|
231
|
+
- spec/db/database.yml
|
|
232
|
+
- spec/db/schema.rb
|
|
233
|
+
- spec/lib/acts_as_scrubbable/scrub_spec.rb
|
|
234
|
+
- spec/lib/acts_as_scrubbable/scrubbable_spec.rb
|
|
235
|
+
- spec/spec_helper.rb
|
|
236
|
+
- spec/support/database.rb
|
|
237
|
+
has_rdoc:
|