attr_masker 0.1.0 → 0.3.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.
Files changed (57) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/tests.yml +91 -0
  3. data/.gitignore +5 -1
  4. data/.rubocop.yml +13 -1069
  5. data/CHANGELOG.adoc +31 -0
  6. data/Gemfile +5 -0
  7. data/README.adoc +81 -30
  8. data/Rakefile +0 -27
  9. data/attr_masker.gemspec +15 -10
  10. data/bin/console +14 -0
  11. data/bin/rake +29 -0
  12. data/bin/rspec +29 -0
  13. data/bin/rubocop +29 -0
  14. data/bin/setup +9 -0
  15. data/gemfiles/Rails-4.2.gemfile +2 -3
  16. data/gemfiles/Rails-5.0.gemfile +2 -3
  17. data/gemfiles/Rails-5.1.gemfile +2 -3
  18. data/gemfiles/Rails-5.2.gemfile +4 -0
  19. data/gemfiles/Rails-6.0.gemfile +3 -0
  20. data/gemfiles/Rails-6.1.gemfile +3 -0
  21. data/gemfiles/Rails-head.gemfile +1 -3
  22. data/gemfiles/common.gemfile +4 -0
  23. data/lib/attr_masker.rb +6 -210
  24. data/lib/attr_masker/attribute.rb +80 -0
  25. data/lib/attr_masker/error.rb +1 -0
  26. data/lib/attr_masker/maskers/replacing.rb +20 -3
  27. data/lib/attr_masker/maskers/simple.rb +20 -5
  28. data/lib/attr_masker/model.rb +143 -0
  29. data/lib/attr_masker/performer.rb +56 -17
  30. data/lib/attr_masker/version.rb +1 -16
  31. data/lib/tasks/db.rake +13 -4
  32. data/spec/dummy/app/models/non_persisted_model.rb +2 -0
  33. data/spec/dummy/config/attr_masker.rb +1 -0
  34. data/spec/dummy/config/mongoid.yml +33 -0
  35. data/spec/dummy/config/routes.rb +0 -1
  36. data/spec/dummy/db/schema.rb +1 -0
  37. data/spec/features/active_record_spec.rb +97 -0
  38. data/spec/features/mongoid_spec.rb +36 -0
  39. data/spec/features/shared_examples.rb +382 -0
  40. data/spec/spec_helper.rb +26 -3
  41. data/spec/support/00_control_constants.rb +2 -0
  42. data/spec/support/10_mongoid_env.rb +9 -0
  43. data/spec/support/20_combustion.rb +10 -0
  44. data/spec/support/db_cleaner.rb +13 -2
  45. data/spec/support/force_config_file_reload.rb +9 -0
  46. data/spec/support/rake.rb +1 -1
  47. data/spec/unit/attribute_spec.rb +210 -0
  48. data/spec/{maskers → unit/maskers}/replacing_spec.rb +0 -0
  49. data/spec/{maskers → unit/maskers}/simple_spec.rb +2 -2
  50. data/spec/unit/model_spec.rb +12 -0
  51. data/spec/unit/rake_task_spec.rb +30 -0
  52. metadata +139 -32
  53. data/.travis.yml +0 -32
  54. data/gemfiles/Rails-4.0.gemfile +0 -5
  55. data/gemfiles/Rails-4.1.gemfile +0 -5
  56. data/spec/features_spec.rb +0 -203
  57. data/spec/support/0_combustion.rb +0 -5
data/.travis.yml DELETED
@@ -1,32 +0,0 @@
1
- sudo: false
2
- dist: trusty
3
- language: ruby
4
- before_install: gem install bundler -v 1.15.1
5
-
6
- script:
7
- - bundle exec rspec
8
-
9
- rvm:
10
- - "2.4"
11
- - "2.3"
12
- - "ruby-head"
13
-
14
- gemfile:
15
- - gemfiles/Rails-5.1.gemfile
16
-
17
- matrix:
18
- include:
19
- - rvm: "2.4"
20
- gemfile: "gemfiles/Rails-head.gemfile"
21
- - rvm: "2.4"
22
- gemfile: "gemfiles/Rails-5.0.gemfile"
23
- - rvm: "2.3"
24
- gemfile: "gemfiles/Rails-4.2.gemfile"
25
- - rvm: "2.3"
26
- gemfile: "gemfiles/Rails-4.1.gemfile"
27
- - rvm: "2.2"
28
- gemfile: "gemfiles/Rails-4.0.gemfile"
29
-
30
- allow_failures:
31
- - rvm: "ruby-head"
32
- - gemfile: "gemfiles/Rails-head.gemfile"
@@ -1,5 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "activerecord", "~> 4.0.0"
4
-
5
- gemspec path: ".."
@@ -1,5 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "activerecord", "~> 4.1.0"
4
-
5
- gemspec path: ".."
@@ -1,203 +0,0 @@
1
- # (c) 2017 Ribose Inc.
2
- #
3
-
4
- # No point in using ApplicationRecord here.
5
- # rubocop:disable Rails/ApplicationRecord
6
-
7
- # No point in ensuring a trailing comma in multiline argument lists here.
8
- # rubocop:disable Style/TrailingCommaInArguments
9
-
10
- require "spec_helper"
11
-
12
- RSpec.describe "Attr Masker gem", :suppress_progressbar do
13
- before do
14
- stub_const "User", Class.new(ActiveRecord::Base)
15
-
16
- User.class_eval do
17
- def jedi?
18
- email.ends_with? "@jedi.example.test"
19
- end
20
- end
21
-
22
- allow(ActiveRecord::Base).to receive(:descendants).
23
- and_return([ActiveRecord::SchemaMigration, User])
24
- end
25
-
26
- let!(:han) do
27
- User.create!(
28
- first_name: "Han",
29
- last_name: "Solo",
30
- email: "han@example.test",
31
- )
32
- end
33
-
34
- let!(:luke) do
35
- User.create!(
36
- first_name: "Luke",
37
- last_name: "Skywalker",
38
- email: "luke@jedi.example.test",
39
- )
40
- end
41
-
42
- example "Masking a single text attribute with default options" do
43
- User.class_eval do
44
- attr_masker :last_name
45
- end
46
-
47
- expect { run_rake_task }.not_to(change { User.count })
48
-
49
- [han, luke].each do |record|
50
- expect { record.reload }.to(
51
- change { record.last_name }.to("(redacted)") &
52
- preserve { record.first_name } &
53
- preserve { record.email }
54
- )
55
- end
56
- end
57
-
58
- example "Specifying multiple attributes in an attr_masker declaration" do
59
- User.class_eval do
60
- attr_masker :first_name, :last_name
61
- end
62
-
63
- expect { run_rake_task }.not_to(change { User.count })
64
-
65
- [han, luke].each do |record|
66
- expect { record.reload }.to(
67
- change { record.first_name }.to("(redacted)") &
68
- change { record.last_name }.to("(redacted)") &
69
- preserve { record.email }
70
- )
71
- end
72
- end
73
-
74
- example "Skipping some records when a symbol is passed to :if option" do
75
- User.class_eval do
76
- attr_masker :first_name, :last_name, if: :jedi?
77
- end
78
-
79
- expect { run_rake_task }.not_to(change { User.count })
80
-
81
- expect { han.reload }.to(
82
- preserve { han.first_name } &
83
- preserve { han.last_name } &
84
- preserve { han.email }
85
- )
86
-
87
- expect { luke.reload }.to(
88
- change { luke.first_name }.to("(redacted)") &
89
- change { luke.last_name }.to("(redacted)") &
90
- preserve { luke.email }
91
- )
92
- end
93
-
94
- example "Skipping some records when a lambda is passed to :if option" do
95
- User.class_eval do
96
- attr_masker :first_name, :last_name, if: ->(r) { r.jedi? }
97
- end
98
-
99
- expect { run_rake_task }.not_to(change { User.count })
100
-
101
- expect { han.reload }.to(
102
- preserve { han.first_name } &
103
- preserve { han.last_name } &
104
- preserve { han.email }
105
- )
106
-
107
- expect { luke.reload }.to(
108
- change { luke.first_name }.to("(redacted)") &
109
- change { luke.last_name }.to("(redacted)") &
110
- preserve { luke.email }
111
- )
112
- end
113
-
114
- example "Skipping some records when a symbol is passed to :unless option" do
115
- User.class_eval do
116
- attr_masker :first_name, :last_name, unless: :jedi?
117
- end
118
-
119
- expect { run_rake_task }.not_to(change { User.count })
120
-
121
- expect { han.reload }.to(
122
- change { han.first_name }.to("(redacted)") &
123
- change { han.last_name }.to("(redacted)") &
124
- preserve { han.email }
125
- )
126
-
127
- expect { luke.reload }.to(
128
- preserve { luke.first_name } &
129
- preserve { luke.last_name } &
130
- preserve { luke.email }
131
- )
132
- end
133
-
134
- example "Skipping some records when a lambda is passed to :unless option" do
135
- User.class_eval do
136
- attr_masker :first_name, :last_name, unless: ->(r) { r.jedi? }
137
- end
138
-
139
- expect { run_rake_task }.not_to(change { User.count })
140
-
141
- expect { han.reload }.to(
142
- change { han.first_name }.to("(redacted)") &
143
- change { han.last_name }.to("(redacted)") &
144
- preserve { han.email }
145
- )
146
-
147
- expect { luke.reload }.to(
148
- preserve { luke.first_name } &
149
- preserve { luke.last_name } &
150
- preserve { luke.email }
151
- )
152
- end
153
-
154
- example "Using a custom masker" do
155
- reverse_masker = ->(value:, **_) do
156
- value.reverse
157
- end
158
-
159
- upcase_masker = ->(value:, **_) do
160
- value.upcase
161
- end
162
-
163
- User.class_eval do
164
- attr_masker :first_name, masker: reverse_masker
165
- attr_masker :last_name, masker: upcase_masker
166
- end
167
-
168
- expect { run_rake_task }.not_to(change { User.count })
169
-
170
- expect { han.reload }.to(
171
- change { han.first_name }.to("naH") &
172
- change { han.last_name }.to("SOLO") &
173
- preserve { han.email }
174
- )
175
-
176
- expect { luke.reload }.to(
177
- change { luke.first_name }.to("ekuL") &
178
- change { luke.last_name }.to("SKYWALKER") &
179
- preserve { luke.email }
180
- )
181
- end
182
-
183
- example "It is disabled in production environment" do
184
- allow(Rails).to receive(:env) { "production".inquiry }
185
-
186
- User.class_eval do
187
- attr_masker :last_name
188
- end
189
-
190
- expect { run_rake_task }.to(
191
- preserve { User.count } &
192
- raise_exception(AttrMasker::Error)
193
- )
194
-
195
- [han, luke].each do |record|
196
- expect { record.reload }.not_to(change { record })
197
- end
198
- end
199
-
200
- def run_rake_task
201
- Rake::Task["db:mask"].execute
202
- end
203
- end
@@ -1,5 +0,0 @@
1
- # (c) 2017 Ribose Inc.
2
- #
3
-
4
- Combustion.path = "spec/dummy"
5
- Combustion.initialize! :all