redacted 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +31 -0
  3. data/Gemfile +8 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +72 -0
  6. data/Rakefile +34 -0
  7. data/app/assets/stylesheets/redacted.css +2 -0
  8. data/lib/redacted.rb +10 -0
  9. data/lib/redacted/action_view/helpers.rb +45 -0
  10. data/lib/redacted/engine.rb +4 -0
  11. data/lib/redacted/railtie.rb +9 -0
  12. data/lib/redacted/version.rb +3 -0
  13. data/redacted.gemspec +28 -0
  14. data/test/dummy/Rakefile +6 -0
  15. data/test/dummy/app/assets/images/.keep +0 -0
  16. data/test/dummy/app/assets/javascripts/application.js +13 -0
  17. data/test/dummy/app/assets/stylesheets/application.css +16 -0
  18. data/test/dummy/app/controllers/application_controller.rb +5 -0
  19. data/test/dummy/app/controllers/concerns/.keep +0 -0
  20. data/test/dummy/app/controllers/welcome_controller.rb +4 -0
  21. data/test/dummy/app/helpers/application_helper.rb +2 -0
  22. data/test/dummy/app/mailers/.keep +0 -0
  23. data/test/dummy/app/models/.keep +0 -0
  24. data/test/dummy/app/models/concerns/.keep +0 -0
  25. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  26. data/test/dummy/app/views/welcome/index.html.erb +42 -0
  27. data/test/dummy/bin/bundle +3 -0
  28. data/test/dummy/bin/rails +4 -0
  29. data/test/dummy/bin/rake +4 -0
  30. data/test/dummy/config.ru +4 -0
  31. data/test/dummy/config/application.rb +25 -0
  32. data/test/dummy/config/boot.rb +5 -0
  33. data/test/dummy/config/environment.rb +5 -0
  34. data/test/dummy/config/environments/development.rb +37 -0
  35. data/test/dummy/config/environments/production.rb +78 -0
  36. data/test/dummy/config/environments/test.rb +38 -0
  37. data/test/dummy/config/initializers/assets.rb +8 -0
  38. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  39. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  40. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  41. data/test/dummy/config/initializers/inflections.rb +16 -0
  42. data/test/dummy/config/initializers/mime_types.rb +4 -0
  43. data/test/dummy/config/initializers/session_store.rb +3 -0
  44. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  45. data/test/dummy/config/locales/en.yml +23 -0
  46. data/test/dummy/config/routes.rb +3 -0
  47. data/test/dummy/config/secrets.yml +22 -0
  48. data/test/dummy/lib/assets/.keep +0 -0
  49. data/test/dummy/log/.keep +0 -0
  50. data/test/dummy/public/404.html +67 -0
  51. data/test/dummy/public/422.html +67 -0
  52. data/test/dummy/public/500.html +66 -0
  53. data/test/dummy/public/favicon.ico +0 -0
  54. data/test/dummy/test/controllers/welcome_controller_test.rb +9 -0
  55. data/test/redacted_helper_test.rb +63 -0
  56. data/test/redacted_test.rb +29 -0
  57. data/test/test_helper.rb +8 -0
  58. metadata +235 -0
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ class WelcomeControllerTest < ActionController::TestCase
4
+ test "should get index" do
5
+ get :index
6
+ assert_response :success
7
+ end
8
+
9
+ end
@@ -0,0 +1,63 @@
1
+ require 'test_helper'
2
+
3
+ class RedactedHelpersTest < ActionView::TestCase
4
+ include Redacted::ActionView::Helpers
5
+
6
+ def setup
7
+ @phrase = "Canada's maple syrup was stolen by grizzly bears"
8
+ @paragraphs = "This one paragraph.\nThis is two.\n\nThis is three!\r\nThis is four?"
9
+ @html = "<p>This is in a p tag.</p>This is outside a p tag.<br>This is after a break."
10
+ @redacted_text = redact_text(@phrase)
11
+ @redacted_paragraphs = redact_paragraphs(@paragraphs)
12
+ end
13
+
14
+ test '#redact returns single line when passed string without characters' do
15
+ refute redact(@phrase).include?('<p>'), "redact phrase should not have paragraph tags"
16
+ end
17
+
18
+ test '#redact splits into paragraphs when passed paragraphs' do
19
+ assert redact(@paragraphs).include?('<p>'), "redact_paragraphs should have p tags"
20
+ assert redact(@paragraphs).include?('</p>')
21
+ end
22
+
23
+ test '#redact_paragraphs returns an array' do
24
+ assert @redacted_paragraphs.class.name == "Array", "redact_paragraphs should be an array"
25
+ end
26
+
27
+ test '#redact_paragraphs returns proper number of paragraphs' do
28
+ assert_equal 4, @redacted_paragraphs.size, "redacted_paragraphs should return proper number of paragraphs"
29
+ end
30
+
31
+ test '#redact_paragraphs returns content with p tags' do
32
+ assert @redacted_paragraphs.first.include?('<p>')
33
+ assert @redacted_paragraphs.first.include?('</p>')
34
+ end
35
+
36
+ test '#redact_text returns string of random text' do
37
+ refute_equal html_text(@redacted_text), @phrase
38
+ refute html_text(@redacted_text).include?(@phrase)
39
+ end
40
+
41
+ test '#redact_text returns string of same length' do
42
+ assert_equal @phrase.length, html_text(@redacted_text).length
43
+ end
44
+
45
+ test '#redact_text creates span tags with class .redacted-text' do
46
+ assert @redacted_text.include?('<span class="redacted-text">')
47
+ assert @redacted_text.include?('</span>')
48
+ end
49
+
50
+ test '#redact_html replaces content of html with redacted text' do
51
+ refute_equal @html, redact_html(@html)
52
+ end
53
+
54
+ test '#ascii_redact returns ascii blocks of same length' do
55
+ assert_equal ["\u2588"], ascii_redact(@phrase).split('').uniq
56
+ assert_equal ("\u2588" * @phrase.length), ascii_redact(@phrase)
57
+ end
58
+
59
+ private
60
+ def html_text(redact_text)
61
+ strip_tags(redact_text)
62
+ end
63
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ class RedactedTest < ActionDispatch::IntegrationTest
4
+ test 'redacted stylesheet is available' do
5
+ get "/assets/redacted.css"
6
+ assert_response(:success)
7
+ assert_match ".redacted-text", @response.body
8
+ end
9
+
10
+ test 'engine is loaded' do
11
+ assert_equal ::Rails::Engine, Redacted::Engine.superclass
12
+ end
13
+
14
+ test 'Redacted::ActionView::Helpers is loaded' do
15
+ assert(Redacted::ActionView::Helpers.present?, 'Redacted::ActionView::Helpers is not defined')
16
+ end
17
+
18
+ test 'helper method redact is defined' do
19
+ assert(Redacted::ActionView::Helpers.method_defined?(:redact), '#redact is not defined')
20
+ end
21
+
22
+ test 'helper method redact_text is defined' do
23
+ assert(Redacted::ActionView::Helpers.method_defined?(:redact_text), '#redact_text is not defined')
24
+ end
25
+
26
+ test 'helper method redact_paragraphs is defined' do
27
+ assert(Redacted::ActionView::Helpers.method_defined?(:redact_paragraphs), '#redact_paragraphs is not defined')
28
+ end
29
+ end
@@ -0,0 +1,8 @@
1
+ # Configure Rails Environment
2
+ ENV["RAILS_ENV"] = "test"
3
+
4
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
5
+ require "rails/test_help"
6
+ require "pry"
7
+
8
+ Rails.backtrace_cleaner.remove_silencers!
metadata ADDED
@@ -0,0 +1,235 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redacted
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Kurt Funai
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faker
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: railties
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '5.0'
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '3.2'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '5.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: bundler
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.6'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.6'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rails
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '4.1'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '4.1'
103
+ description: Allows a user to turn any string of text into a redacted block of the
104
+ same size.
105
+ email:
106
+ - me@kurtfunai.com
107
+ executables: []
108
+ extensions: []
109
+ extra_rdoc_files: []
110
+ files:
111
+ - ".gitignore"
112
+ - Gemfile
113
+ - LICENSE.txt
114
+ - README.md
115
+ - Rakefile
116
+ - app/assets/stylesheets/redacted.css
117
+ - lib/redacted.rb
118
+ - lib/redacted/action_view/helpers.rb
119
+ - lib/redacted/engine.rb
120
+ - lib/redacted/railtie.rb
121
+ - lib/redacted/version.rb
122
+ - redacted.gemspec
123
+ - test/dummy/Rakefile
124
+ - test/dummy/app/assets/images/.keep
125
+ - test/dummy/app/assets/javascripts/application.js
126
+ - test/dummy/app/assets/stylesheets/application.css
127
+ - test/dummy/app/controllers/application_controller.rb
128
+ - test/dummy/app/controllers/concerns/.keep
129
+ - test/dummy/app/controllers/welcome_controller.rb
130
+ - test/dummy/app/helpers/application_helper.rb
131
+ - test/dummy/app/mailers/.keep
132
+ - test/dummy/app/models/.keep
133
+ - test/dummy/app/models/concerns/.keep
134
+ - test/dummy/app/views/layouts/application.html.erb
135
+ - test/dummy/app/views/welcome/index.html.erb
136
+ - test/dummy/bin/bundle
137
+ - test/dummy/bin/rails
138
+ - test/dummy/bin/rake
139
+ - test/dummy/config.ru
140
+ - test/dummy/config/application.rb
141
+ - test/dummy/config/boot.rb
142
+ - test/dummy/config/environment.rb
143
+ - test/dummy/config/environments/development.rb
144
+ - test/dummy/config/environments/production.rb
145
+ - test/dummy/config/environments/test.rb
146
+ - test/dummy/config/initializers/assets.rb
147
+ - test/dummy/config/initializers/backtrace_silencers.rb
148
+ - test/dummy/config/initializers/cookies_serializer.rb
149
+ - test/dummy/config/initializers/filter_parameter_logging.rb
150
+ - test/dummy/config/initializers/inflections.rb
151
+ - test/dummy/config/initializers/mime_types.rb
152
+ - test/dummy/config/initializers/session_store.rb
153
+ - test/dummy/config/initializers/wrap_parameters.rb
154
+ - test/dummy/config/locales/en.yml
155
+ - test/dummy/config/routes.rb
156
+ - test/dummy/config/secrets.yml
157
+ - test/dummy/lib/assets/.keep
158
+ - test/dummy/log/.keep
159
+ - test/dummy/public/404.html
160
+ - test/dummy/public/422.html
161
+ - test/dummy/public/500.html
162
+ - test/dummy/public/favicon.ico
163
+ - test/dummy/test/controllers/welcome_controller_test.rb
164
+ - test/redacted_helper_test.rb
165
+ - test/redacted_test.rb
166
+ - test/test_helper.rb
167
+ homepage: http://kurtfunai.com
168
+ licenses:
169
+ - MIT
170
+ metadata: {}
171
+ post_install_message:
172
+ rdoc_options: []
173
+ require_paths:
174
+ - lib
175
+ required_ruby_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ required_rubygems_version: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ requirements: []
186
+ rubyforge_project:
187
+ rubygems_version: 2.4.2
188
+ signing_key:
189
+ specification_version: 4
190
+ summary: Convert strings into redacted text.
191
+ test_files:
192
+ - test/dummy/Rakefile
193
+ - test/dummy/app/assets/images/.keep
194
+ - test/dummy/app/assets/javascripts/application.js
195
+ - test/dummy/app/assets/stylesheets/application.css
196
+ - test/dummy/app/controllers/application_controller.rb
197
+ - test/dummy/app/controllers/concerns/.keep
198
+ - test/dummy/app/controllers/welcome_controller.rb
199
+ - test/dummy/app/helpers/application_helper.rb
200
+ - test/dummy/app/mailers/.keep
201
+ - test/dummy/app/models/.keep
202
+ - test/dummy/app/models/concerns/.keep
203
+ - test/dummy/app/views/layouts/application.html.erb
204
+ - test/dummy/app/views/welcome/index.html.erb
205
+ - test/dummy/bin/bundle
206
+ - test/dummy/bin/rails
207
+ - test/dummy/bin/rake
208
+ - test/dummy/config.ru
209
+ - test/dummy/config/application.rb
210
+ - test/dummy/config/boot.rb
211
+ - test/dummy/config/environment.rb
212
+ - test/dummy/config/environments/development.rb
213
+ - test/dummy/config/environments/production.rb
214
+ - test/dummy/config/environments/test.rb
215
+ - test/dummy/config/initializers/assets.rb
216
+ - test/dummy/config/initializers/backtrace_silencers.rb
217
+ - test/dummy/config/initializers/cookies_serializer.rb
218
+ - test/dummy/config/initializers/filter_parameter_logging.rb
219
+ - test/dummy/config/initializers/inflections.rb
220
+ - test/dummy/config/initializers/mime_types.rb
221
+ - test/dummy/config/initializers/session_store.rb
222
+ - test/dummy/config/initializers/wrap_parameters.rb
223
+ - test/dummy/config/locales/en.yml
224
+ - test/dummy/config/routes.rb
225
+ - test/dummy/config/secrets.yml
226
+ - test/dummy/lib/assets/.keep
227
+ - test/dummy/log/.keep
228
+ - test/dummy/public/404.html
229
+ - test/dummy/public/422.html
230
+ - test/dummy/public/500.html
231
+ - test/dummy/public/favicon.ico
232
+ - test/dummy/test/controllers/welcome_controller_test.rb
233
+ - test/redacted_helper_test.rb
234
+ - test/redacted_test.rb
235
+ - test/test_helper.rb