obscenity-plus 1.0.3 → 1.0.4
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
- metadata +2 -11
- data/test/helper.rb +0 -29
- data/test/static/422.html +0 -1
- data/test/test_active_model.rb +0 -70
- data/test/test_base.rb +0 -29
- data/test/test_config.rb +0 -67
- data/test/test_obscenity.rb +0 -70
- data/test/test_rack.rb +0 -207
- data/test/test_test.rb +0 -17
- data/test/test_version.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95fe7b37b3b580613fcce66b26012a7b5f3499bca65e62806297d55034fa4d35
|
4
|
+
data.tar.gz: 898a7965d4fa9fcd0e650ecce0d2af58ccc40e4c28a796a2ffa20366fbde78f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ff216439ef22b2a0881b70d16181d99208b258d515f3266e086a333ac6db403dca34cc559fa62487716d7028f7666e5acac40a5913deccf0a3590e05d69a1d1
|
7
|
+
data.tar.gz: '091bfbae422af0095219191ab00f00ebdb006debf095ce4c1b1004968da50f7d149ac03d03c71ade1d1178378ccf47c11900abf1bd8a520eed51237daad44d54'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: obscenity-plus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ropetow
|
@@ -113,15 +113,6 @@ files:
|
|
113
113
|
- lib/obscenity/rack.rb
|
114
114
|
- lib/obscenity/rspec_matcher.rb
|
115
115
|
- lib/obscenity/version.rb
|
116
|
-
- test/helper.rb
|
117
|
-
- test/static/422.html
|
118
|
-
- test/test_active_model.rb
|
119
|
-
- test/test_base.rb
|
120
|
-
- test/test_config.rb
|
121
|
-
- test/test_obscenity.rb
|
122
|
-
- test/test_rack.rb
|
123
|
-
- test/test_test.rb
|
124
|
-
- test/test_version.rb
|
125
116
|
homepage: http://github.com/ropetow/obscenity-plus
|
126
117
|
licenses:
|
127
118
|
- MIT
|
@@ -134,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
125
|
requirements:
|
135
126
|
- - ">="
|
136
127
|
- !ruby/object:Gem::Version
|
137
|
-
version: '
|
128
|
+
version: '3.0'
|
138
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
130
|
requirements:
|
140
131
|
- - ">="
|
data/test/helper.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
#helper.rb
|
2
|
-
require 'rubygems'
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'rspec'
|
5
|
-
|
6
|
-
# Load ActiveModel and Obscenity
|
7
|
-
require 'active_model'
|
8
|
-
require 'obscenity'
|
9
|
-
require 'obscenity/active_model'
|
10
|
-
|
11
|
-
# Dummy Model for Testing
|
12
|
-
FactoryBot.define do
|
13
|
-
factory :base_model, class: Dummy::BaseModel do
|
14
|
-
title { "Sample title" }
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
# Configure RSpec
|
19
|
-
RSpec.configure do |config|
|
20
|
-
config.expect_with :rspec do |expectations|
|
21
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
22
|
-
end
|
23
|
-
|
24
|
-
config.mock_with :rspec do |mocks|
|
25
|
-
mocks.verify_partial_doubles = true
|
26
|
-
end
|
27
|
-
|
28
|
-
config.shared_context_metadata_behavior = :apply_to_host_groups
|
29
|
-
end
|
data/test/static/422.html
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
We don't accept profanity
|
data/test/test_active_model.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
#test_active_model.rb
|
2
|
-
require 'helper'
|
3
|
-
|
4
|
-
class TestActiveModel < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def generate_new_class(name, options = {})
|
7
|
-
Dummy.send(:remove_const, name) if Dummy.const_defined?(name)
|
8
|
-
klass = Class.new(Dummy::BaseModel) do
|
9
|
-
validates :title, options
|
10
|
-
end
|
11
|
-
Dummy.const_set(name, klass)
|
12
|
-
end
|
13
|
-
|
14
|
-
should "be invalid when title is profane" do
|
15
|
-
klass = generate_new_class("Post", obscenity: true)
|
16
|
-
post = klass.new(title: "He who poops, shits itself")
|
17
|
-
assert !post.valid?
|
18
|
-
assert post.errors.has_key?(:title)
|
19
|
-
assert_equal ['cannot be profane'], post.errors[:title]
|
20
|
-
end
|
21
|
-
|
22
|
-
should "be invalid when title is profane and should include a custom error message" do
|
23
|
-
klass = generate_new_class("Post", obscenity: { message: "can't be profane!" })
|
24
|
-
post = klass.new(title: "He who poops, shits itself")
|
25
|
-
assert !post.valid?
|
26
|
-
assert post.errors.has_key?(:title)
|
27
|
-
assert_equal ["can't be profane!"], post.errors[:title]
|
28
|
-
end
|
29
|
-
|
30
|
-
should "sanitize the title using the default replacement" do
|
31
|
-
klass = generate_new_class("Post", obscenity: { sanitize: true })
|
32
|
-
post = klass.new(title: "He who poops, shits itself")
|
33
|
-
assert post.valid?
|
34
|
-
assert !post.errors.has_key?(:title)
|
35
|
-
assert_equal "He who poops, $@!#% itself", post.title
|
36
|
-
end
|
37
|
-
|
38
|
-
should "sanitize the title using the :garbled replacement" do
|
39
|
-
klass = generate_new_class("Post", obscenity: { sanitize: true, replacement: :garbled })
|
40
|
-
post = klass.new(title: "He who poops, shits itself")
|
41
|
-
assert post.valid?
|
42
|
-
assert !post.errors.has_key?(:title)
|
43
|
-
assert_equal "He who poops, $@!#% itself", post.title
|
44
|
-
end
|
45
|
-
|
46
|
-
should "sanitize the title using the :stars replacement" do
|
47
|
-
klass = generate_new_class("Post", obscenity: { sanitize: true, replacement: :stars })
|
48
|
-
post = klass.new(title: "He who poops, shits itself")
|
49
|
-
assert post.valid?
|
50
|
-
assert !post.errors.has_key?(:title)
|
51
|
-
assert_equal "He who poops, ***** itself", post.title
|
52
|
-
end
|
53
|
-
|
54
|
-
should "sanitize the title using the :vowels replacement" do
|
55
|
-
klass = generate_new_class("Post", obscenity: { sanitize: true, replacement: :vowels })
|
56
|
-
post = klass.new(title: "He who poops, shits itself")
|
57
|
-
assert post.valid?
|
58
|
-
assert !post.errors.has_key?(:title)
|
59
|
-
assert_equal "He who poops, sh*ts itself", post.title
|
60
|
-
end
|
61
|
-
|
62
|
-
should "sanitize the title using a custom replacement" do
|
63
|
-
klass = generate_new_class("Post", obscenity: { sanitize: true, replacement: '[censored]' })
|
64
|
-
post = klass.new(title: "He who poops, shits itself")
|
65
|
-
assert post.valid?
|
66
|
-
assert !post.errors.has_key?(:title)
|
67
|
-
assert_equal "He who poops, [censored] itself", post.title
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
data/test/test_base.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# test_base.rb
|
2
|
-
require 'test/unit'
|
3
|
-
require 'obscenity'
|
4
|
-
|
5
|
-
class TestObscenityBase < Test::Unit::TestCase
|
6
|
-
def setup
|
7
|
-
Obscenity.configure do |config|
|
8
|
-
config.blacklist = ["badword"]
|
9
|
-
config.whitelist = []
|
10
|
-
config.replacement = :stars
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_methods_respond
|
15
|
-
[:blacklist, :whitelist, :profane?, :sanitize, :replacement, :offensive, :replace].each do |method|
|
16
|
-
assert_respond_to Obscenity::Base, method
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_profane_detection
|
21
|
-
assert Obscenity::Base.profane?("badword")
|
22
|
-
assert !Obscenity::Base.profane?("cleanword")
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_sanitization
|
26
|
-
assert_equal "*******", Obscenity::Base.sanitize("badword")
|
27
|
-
assert_equal "cleanword", Obscenity::Base.sanitize("cleanword")
|
28
|
-
end
|
29
|
-
end
|
data/test/test_config.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
#test_config.rb
|
2
|
-
require 'helper'
|
3
|
-
|
4
|
-
class TestConfig < Test::Unit::TestCase
|
5
|
-
|
6
|
-
context "#respond_to?" do
|
7
|
-
should "respond to methods and attributes" do
|
8
|
-
Obscenity::Config.new do |config|
|
9
|
-
[:blacklist, :whitelist, :replacement].each do |field|
|
10
|
-
assert config.respond_to?(field)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
should "properly set the config parameters" do
|
17
|
-
blacklist = ['ass', 'shit', 'penis']
|
18
|
-
whitelist = ['penis']
|
19
|
-
replacement = :stars
|
20
|
-
|
21
|
-
config = Obscenity::Config.new do |config|
|
22
|
-
config.blacklist = blacklist
|
23
|
-
config.whitelist = whitelist
|
24
|
-
config.replacement = replacement
|
25
|
-
end
|
26
|
-
|
27
|
-
assert_equal blacklist, config.blacklist
|
28
|
-
assert_equal whitelist, config.whitelist
|
29
|
-
assert_equal replacement, config.replacement
|
30
|
-
end
|
31
|
-
|
32
|
-
should "return default values if none is set" do
|
33
|
-
config = Obscenity::Config.new
|
34
|
-
assert_equal [], config.whitelist
|
35
|
-
assert_equal :garbled, config.replacement
|
36
|
-
assert_match /config\/blacklist.yml/, config.blacklist
|
37
|
-
end
|
38
|
-
|
39
|
-
should "return default values when default values are set" do
|
40
|
-
config = Obscenity::Config.new do |config|
|
41
|
-
config.blacklist = :default
|
42
|
-
config.replacement = :default
|
43
|
-
end
|
44
|
-
assert_equal [], config.whitelist
|
45
|
-
assert_equal :default, config.replacement
|
46
|
-
assert_match /config\/blacklist.yml/, config.blacklist
|
47
|
-
end
|
48
|
-
|
49
|
-
should "properly validate the config options" do
|
50
|
-
[:blacklist, :whitelist].each do |field|
|
51
|
-
exceptions = [
|
52
|
-
[Obscenity::UnkownContent, {}],
|
53
|
-
[Obscenity::UnkownContent, ":unkown"],
|
54
|
-
[Obscenity::EmptyContentList, []],
|
55
|
-
[Obscenity::UnkownContentFile, "'path/to/file'"],
|
56
|
-
[Obscenity::UnkownContentFile, Pathname.new("'path/to/file'")]
|
57
|
-
].each do |klass, value|
|
58
|
-
assert_raise(klass){
|
59
|
-
Obscenity::Config.new do |config|
|
60
|
-
config.instance_eval "config.#{field} = #{value}"
|
61
|
-
end
|
62
|
-
}
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
data/test/test_obscenity.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
#test_obscenity.rb
|
2
|
-
require 'helper'
|
3
|
-
|
4
|
-
class TestObscenity < Test::Unit::TestCase
|
5
|
-
|
6
|
-
context "#respond_to?" do
|
7
|
-
should "respond to methods and attributes" do
|
8
|
-
[:configure, :config, :profane?, :sanitize, :offensive, :replacement].each do |field|
|
9
|
-
assert Obscenity.respond_to?(field)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
# More comprehensive test in test_config.rb
|
15
|
-
context "#configure" do
|
16
|
-
should "accept a configuration block " do
|
17
|
-
assert_nothing_raised{
|
18
|
-
Obscenity.configure do |config|
|
19
|
-
config.blacklist = :default
|
20
|
-
config.replacement = :garbled
|
21
|
-
end
|
22
|
-
}
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# More comprehensive test in test_config.rb
|
27
|
-
context "#config" do
|
28
|
-
should "return the current config object" do
|
29
|
-
assert_not_nil Obscenity.config
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# More comprehensive test in test_base.rb
|
34
|
-
context "#profane?" do
|
35
|
-
should "validate the profanity of the given content" do
|
36
|
-
assert Obscenity.profane?('Yo, check that ass out')
|
37
|
-
assert !Obscenity.profane?('Hello world')
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# More comprehensive test in test_base.rb
|
42
|
-
context "#sanitize" do
|
43
|
-
should "sanitize the given content" do
|
44
|
-
assert_equal "Yo, check that $@!#% out", Obscenity.sanitize('Yo, check that ass out')
|
45
|
-
assert_equal "Hello world", Obscenity.sanitize('Hello world')
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# More comprehensive test in test_base.rb
|
50
|
-
context "#offensive" do
|
51
|
-
should "return the offensive words for the given content" do
|
52
|
-
assert_equal ['ass', 'biatch'], Obscenity.offensive('Yo, check that ass biatch')
|
53
|
-
assert_equal [], Obscenity.offensive('Hello world')
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# More comprehensive test in test_base.rb
|
58
|
-
context "#replacement" do
|
59
|
-
should "sanitize the given content based on the given replacement" do
|
60
|
-
assert_equal "Yo, check that $@!#% out", Obscenity.replacement(:garbled).sanitize('Yo, check that ass out')
|
61
|
-
assert_equal "Yo, check that $@!#% out", Obscenity.replacement(:default).sanitize('Yo, check that ass out')
|
62
|
-
assert_equal "Yo, check that *ss out", Obscenity.replacement(:vowels).sanitize('Yo, check that ass out')
|
63
|
-
assert_equal "Yo, check that *h*t out", Obscenity.replacement(:nonconsonants).sanitize('Yo, check that 5hit out')
|
64
|
-
assert_equal "Yo, check that *** out", Obscenity.replacement(:stars).sanitize('Yo, check that ass out')
|
65
|
-
assert_equal "Yo, check that [censored] out", Obscenity.replacement("[censored]").sanitize('Yo, check that ass out')
|
66
|
-
assert_equal "Hello world", Obscenity.sanitize('Hello world')
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
data/test/test_rack.rb
DELETED
@@ -1,207 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'rack/mock'
|
3
|
-
require 'obscenity/rack'
|
4
|
-
|
5
|
-
class TestRack < Test::Unit::TestCase
|
6
|
-
|
7
|
-
context "Rack::Obscenity" do
|
8
|
-
setup do
|
9
|
-
@env = {}
|
10
|
-
@body = 'hello'
|
11
|
-
@status = 200
|
12
|
-
@headers = { 'Content-Type' => 'text/plain' }
|
13
|
-
@app = lambda { |env| [@status, @headers, [@body]] }
|
14
|
-
end
|
15
|
-
|
16
|
-
def mock_env(options = {})
|
17
|
-
@env = Rack::MockRequest.env_for('/', options)
|
18
|
-
end
|
19
|
-
|
20
|
-
def middleware(options = {})
|
21
|
-
Rack::Obscenity.new(@app, options)
|
22
|
-
end
|
23
|
-
|
24
|
-
def get(params = {})
|
25
|
-
{ 'QUERY_STRING' => Rack::Utils.build_query(params) }
|
26
|
-
end
|
27
|
-
|
28
|
-
def get_response_params
|
29
|
-
Rack::Utils.parse_query(@env['QUERY_STRING'], "&")
|
30
|
-
end
|
31
|
-
|
32
|
-
def post(params = {})
|
33
|
-
{ 'rack.input' => StringIO.new(Rack::Utils.build_query(params)) }
|
34
|
-
end
|
35
|
-
|
36
|
-
def post_response_params
|
37
|
-
Rack::Utils.parse_query(@env['rack.input'].read, "&")
|
38
|
-
end
|
39
|
-
|
40
|
-
def assert_success_response(status, headers, body)
|
41
|
-
assert_equal @status, status
|
42
|
-
assert_equal @headers, headers
|
43
|
-
assert_equal [@body], body
|
44
|
-
end
|
45
|
-
|
46
|
-
context "default configuration" do
|
47
|
-
should "not evaluate the profanity of parameters" do
|
48
|
-
app = middleware
|
49
|
-
status, headers, body = app.call(mock_env)
|
50
|
-
assert_success_response status, headers, body
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context "rejecting requests" do
|
55
|
-
should "not reject if parameter values don't contain profanity" do
|
56
|
-
app = middleware(reject: true)
|
57
|
-
status, headers, body = app.call(mock_env(get(foo: 'bar')))
|
58
|
-
assert_success_response status, headers, body
|
59
|
-
end
|
60
|
-
|
61
|
-
should "reject if GET parameter values contain profanity" do
|
62
|
-
app = middleware(reject: true)
|
63
|
-
status, headers, body = app.call(mock_env(get(foo: 'bar', baz: 'shit')))
|
64
|
-
assert_equal 422, status
|
65
|
-
assert_equal [''], body
|
66
|
-
end
|
67
|
-
|
68
|
-
should "reject if POST parameter values contain profanity" do
|
69
|
-
app = middleware(reject: true)
|
70
|
-
status, headers, body = app.call(mock_env(post(foo: 'bar', baz: 'ass')))
|
71
|
-
assert_equal 422, status
|
72
|
-
assert_equal [''], body
|
73
|
-
end
|
74
|
-
|
75
|
-
should "reject if given parameter values contain profanity" do
|
76
|
-
app = middleware(reject: { params: [:foo] })
|
77
|
-
[ get(foo: 'ass', baz: 'shit'),
|
78
|
-
post(foo: 'ass').merge(get(foo: 'nice', baz: 'shit'))
|
79
|
-
].each do |options|
|
80
|
-
status, headers, body = app.call(mock_env(options))
|
81
|
-
assert_equal 422, status
|
82
|
-
assert_equal [''], body
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
should "not reject if other parameter values contain profanity" do
|
87
|
-
app = middleware(reject: { params: [:foo] })
|
88
|
-
status, headers, body = app.call(mock_env(get(foo: 'nice', baz: 'shit')))
|
89
|
-
assert_success_response status, headers, body
|
90
|
-
end
|
91
|
-
|
92
|
-
should "reject if parameter values contain profanity" do
|
93
|
-
app = middleware(reject: { params: :all })
|
94
|
-
status, headers, body = app.call(mock_env(get(foo: 'ass')))
|
95
|
-
assert_equal 422, status
|
96
|
-
assert_equal [''], body
|
97
|
-
end
|
98
|
-
|
99
|
-
should "reject if parameter values contain profanity and display a custom message" do
|
100
|
-
app = middleware(reject: { message: "We don't accept profanity" })
|
101
|
-
status, headers, body = app.call(mock_env(get(foo: 'ass')))
|
102
|
-
assert_equal 422, status
|
103
|
-
assert_equal ["We don't accept profanity"], body
|
104
|
-
end
|
105
|
-
|
106
|
-
should "reject if parameter values contain profanity and render a custom file" do
|
107
|
-
app = middleware(reject: { path: "test/static/422.html" })
|
108
|
-
status, headers, body = app.call(mock_env(get(foo: 'ass')))
|
109
|
-
assert_equal 422, status
|
110
|
-
assert_equal ["We don't accept profanity"], body
|
111
|
-
end
|
112
|
-
|
113
|
-
should "reject parameter values when they're a hash and contain profanity" do
|
114
|
-
app = middleware(reject: true)
|
115
|
-
status, headers, body = app.call(mock_env(get(foo: 'clean', bar: {one: 'ass'})))
|
116
|
-
assert_equal 422, status
|
117
|
-
assert_equal [''], body
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
context "sanitizing requests" do
|
122
|
-
should "not sanitize if parameter values don't contain profanity" do
|
123
|
-
app = middleware(sanitize: true)
|
124
|
-
status, headers, body = app.call(mock_env(get(foo: 'bar')))
|
125
|
-
assert_success_response status, headers, body
|
126
|
-
request_params = get_response_params
|
127
|
-
assert_equal 'bar', request_params['foo']
|
128
|
-
end
|
129
|
-
|
130
|
-
should "sanitize if GET parameter values contain profanity" do
|
131
|
-
app = middleware(sanitize: true)
|
132
|
-
status, headers, body = app.call(mock_env(get(foo: 'bar', baz: 'shit')))
|
133
|
-
assert_success_response status, headers, body
|
134
|
-
request_params = get_response_params
|
135
|
-
assert_equal 'bar', request_params['foo']
|
136
|
-
assert_equal '$@!#%', request_params['baz']
|
137
|
-
end
|
138
|
-
|
139
|
-
should "sanitize if POST parameter values contain profanity" do
|
140
|
-
app = middleware(sanitize: true)
|
141
|
-
status, headers, body = app.call(mock_env(post(foo: 'bar', baz: 'ass')))
|
142
|
-
assert_success_response status, headers, body
|
143
|
-
request_params = post_response_params
|
144
|
-
assert_equal 'bar', request_params['foo']
|
145
|
-
assert_equal '$@!#%', request_params['baz']
|
146
|
-
end
|
147
|
-
|
148
|
-
should "not sanitize if other parameter values contain profanity" do
|
149
|
-
app = middleware(sanitize: { params: [:foo] })
|
150
|
-
status, headers, body = app.call(mock_env(get(foo: 'nice', baz: 'shit')))
|
151
|
-
assert_success_response status, headers, body
|
152
|
-
request_params = get_response_params
|
153
|
-
assert_equal 'nice', request_params['foo']
|
154
|
-
assert_equal 'shit', request_params['baz']
|
155
|
-
end
|
156
|
-
|
157
|
-
should "sanitize if parameter values contain profanity" do
|
158
|
-
app = middleware(sanitize: { params: :all })
|
159
|
-
status, headers, body = app.call(mock_env(get(foo: 'ass')))
|
160
|
-
assert_success_response status, headers, body
|
161
|
-
request_params = get_response_params
|
162
|
-
assert_equal '$@!#%', request_params['foo']
|
163
|
-
end
|
164
|
-
|
165
|
-
should "sanitize the title using the :garbled replacement" do
|
166
|
-
app = middleware(sanitize: { replacement: :garbled })
|
167
|
-
status, headers, body = app.call(mock_env(get(foo: 'ass')))
|
168
|
-
assert_success_response status, headers, body
|
169
|
-
request_params = get_response_params
|
170
|
-
assert_equal '$@!#%', request_params['foo']
|
171
|
-
end
|
172
|
-
|
173
|
-
should "sanitize the title using the :stars replacement" do
|
174
|
-
app = middleware(sanitize: { replacement: :stars })
|
175
|
-
status, headers, body = app.call(mock_env(get(foo: 'ass')))
|
176
|
-
assert_success_response status, headers, body
|
177
|
-
request_params = get_response_params
|
178
|
-
assert_equal '***', request_params['foo']
|
179
|
-
end
|
180
|
-
|
181
|
-
should "sanitize the title using the :vowels replacement" do
|
182
|
-
app = middleware(sanitize: { replacement: :vowels })
|
183
|
-
status, headers, body = app.call(mock_env(get(foo: 'ass')))
|
184
|
-
assert_success_response status, headers, body
|
185
|
-
request_params = get_response_params
|
186
|
-
assert_equal '*ss', request_params['foo']
|
187
|
-
end
|
188
|
-
|
189
|
-
should "sanitize the title using the :nonconsonants replacement" do
|
190
|
-
app = middleware(sanitize: { replacement: :nonconsonants })
|
191
|
-
status, headers, body = app.call(mock_env(get(foo: '5hit')))
|
192
|
-
assert_success_response status, headers, body
|
193
|
-
request_params = get_response_params
|
194
|
-
assert_equal '*h*t', request_params['foo']
|
195
|
-
end
|
196
|
-
|
197
|
-
should "sanitize the title using a custom replacement" do
|
198
|
-
app = middleware(sanitize: { replacement: "[censored]" })
|
199
|
-
status, headers, body = app.call(mock_env(get(foo: 'text with ass')))
|
200
|
-
assert_success_response status, headers, body
|
201
|
-
request_params = get_response_params
|
202
|
-
assert_equal 'text with [censored]', request_params['foo']
|
203
|
-
end
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
end
|
data/test/test_test.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
#first test of the gem and rspec
|
2
|
-
require 'rails_helper'
|
3
|
-
|
4
|
-
RSpec.describe Dummy::BaseModel, type: :model do
|
5
|
-
before do
|
6
|
-
Obscenity.configure do |config|
|
7
|
-
config.blacklist = ["badword"]
|
8
|
-
config.replacement = :stars
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
it "validates profanity in the title" do
|
13
|
-
model = Dummy::BaseModel.new(title: "This is a badword")
|
14
|
-
expect(Obscenity.profane?(model.title)).to be true
|
15
|
-
expect(Obscenity.sanitize(model.title)).to eq "This is a *******"
|
16
|
-
end
|
17
|
-
end
|