dodgy_stalker 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49d60a3dcc9fdc99c8ace0e7b52f5c154ff7e789
4
- data.tar.gz: 9f0b6893003afbdbf4b7de4b9b0ea122a74935f7
3
+ metadata.gz: 32289bb020d8d52033f2478858e43fd88db4a31c
4
+ data.tar.gz: 1e18c56fe677b40c5c973de25beaa2f947b89da5
5
5
  SHA512:
6
- metadata.gz: 19eed3bc970fcd54a81bd745522d8d0e2fcd8552c51927d5a8f8d6a5df90a485abcf1ca66668f934dcb13974439947eb746a724493fcba0ae9a8c2dc0a823c13
7
- data.tar.gz: 03d729e57525e13ee9616d5f63e51ea7463c9eb808e8ccb592d4957c937f6d380fb670676cd844304b9d42b4bb3b92c2bb82ca1af944332bd47bf2f0429b0cbf
6
+ metadata.gz: 5c22343a74c9e31f1f26cbf81a0167380047a2396fd33bce1905f042b5e14bd910a4d34aef08e3bf2c175260a50c8d367321b1d396b176bbf68dc57186f10015
7
+ data.tar.gz: fc082d7cc0d8fd820e5983c236067533d8287d411aaded59b1f6977caa7e59d7a9afcc0c369e8413b161c5b6eadc98a4c562027a0d5d563a96fe219344e8159d
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.3
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "pg"
28
28
  spec.add_development_dependency "database_cleaner"
29
29
 
30
- spec.add_dependency "activerecord", "~> 4.0"
30
+ spec.add_dependency "activerecord", ">= 4.0"
31
31
  spec.add_dependency "typhoeus"
32
32
  spec.add_dependency "addressable"
33
33
  end
@@ -4,7 +4,5 @@ module DodgyStalker
4
4
  end
5
5
 
6
6
  require "dodgy_stalker/data_store/common"
7
- require "dodgy_stalker/data_store/blacklist"
8
- require "dodgy_stalker/data_store/whitelist"
9
7
  require "dodgy_stalker/data_store/wordlist"
10
8
 
@@ -4,5 +4,4 @@ module DodgyStalker
4
4
  end
5
5
 
6
6
  require 'dodgy_stalker/engines/banned_words'
7
- require 'dodgy_stalker/engines/blacklist'
8
7
  require 'dodgy_stalker/engines/stop_forum_spam'
@@ -1,3 +1,3 @@
1
1
  module DodgyStalker
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -10,27 +10,5 @@ class CreateDodgyStalkerTables < ActiveRecord::Migration
10
10
  t.datetime "created_at", null: false
11
11
  t.datetime "updated_at", null: false
12
12
  end
13
-
14
- create_table "whitelist", force: true do |t|
15
- t.string "username"
16
- t.string "email"
17
- t.string "ip_address"
18
- t.string "twitter_uid"
19
- t.string "google_uid"
20
- t.string "facebook_uid"
21
- t.datetime "created_at", null: false
22
- t.datetime "updated_at", null: false
23
- end
24
-
25
- create_table "blacklist", force: true do |t|
26
- t.string "username"
27
- t.string "email"
28
- t.string "ip_address"
29
- t.string "twitter_uid"
30
- t.string "google_uid"
31
- t.string "facebook_uid"
32
- t.datetime "created_at", null: false
33
- t.datetime "updated_at", null: false
34
- end
35
13
  end
36
14
  end
@@ -7,14 +7,14 @@ describe DodgyStalker::DataStore::Wordlist do
7
7
  context "attributes :ban, :hold, :notify" do
8
8
  it "toggle one attribute, turn off others" do
9
9
  wordlist.toggle('ban')
10
- wordlist.ban.should be true
11
- wordlist.hold.should be false
12
- wordlist.notify.should be false
10
+ expect(wordlist.ban).to eq(true)
11
+ expect(wordlist.hold).to eq(false)
12
+ expect(wordlist.notify).to eq(false)
13
13
 
14
14
  wordlist.toggle('hold')
15
- wordlist.ban.should be false
16
- wordlist.hold.should be true
17
- wordlist.notify.should be false
15
+ expect(wordlist.ban).to eq(false)
16
+ expect(wordlist.hold).to eq(true)
17
+ expect(wordlist.notify).to eq(false)
18
18
  end
19
19
  end
20
20
  end
@@ -9,53 +9,54 @@ describe DodgyStalker::Engines::BannedWords do
9
9
  it "returns a list of banned words in input" do
10
10
  datastore.create(word: 'fuck!', ban: true)
11
11
  datastore.create(word: 'ass', ban: true)
12
- engine.banned.should =~ ['fuck!', 'ass']
12
+ expect(engine.banned).to include('fuck!', 'ass')
13
13
  end
14
14
  end
15
15
 
16
16
  describe "#blacklisted_email" do
17
17
  it "returns a list of blacklisted emails" do
18
18
  datastore.create(word: '@wp.pl', blacklist_email: true)
19
- described_class.new('piotr@wp.pl').blacklisted_email.should =~ ['@wp.pl']
19
+ engine = described_class.new('piotr@wp.pl')
20
+ expect(engine.blacklisted_email).to include('@wp.pl')
20
21
  end
21
22
  end
22
23
 
23
24
  describe "#on_hold" do
24
25
  it "returns a list of hold words in input" do
25
26
  datastore.create(word: 'viagra', hold: true)
26
- engine.on_hold.should =~ ['viagra']
27
+ expect(engine.on_hold).to include('viagra')
27
28
  end
28
29
  end
29
30
 
30
31
  describe "#notify" do
31
32
  it "returns a list of notify words in input" do
32
33
  datastore.create(word: 'underage', notify: true)
33
- engine.notify.should =~ ['underage']
34
+ expect(engine.notify).to include('underage')
34
35
  end
35
36
  end
36
37
 
37
38
  describe "#match" do
38
39
  it "matches full words (no partials)" do
39
40
  datastore.create(word: 'fuck', ban: true)
40
- engine.banned.should be_empty
41
+ expect(engine.banned.size).to eq(0)
41
42
  end
42
43
 
43
44
  it "ignores quotes on matches" do
44
45
  datastore.create(word: 'quoted', ban: true)
45
- engine.banned.to_a.should have(1).word
46
+ expect(engine.banned.to_a.size).to eq(1)
46
47
  end
47
48
 
48
49
  it "allows to change word separator via config" do
49
50
  old_separator = DodgyStalker::Config.new.word_separator
50
51
  DodgyStalker.configure {|c| c.word_separator = %q{(^|\s|\A|\Z|$|\.|,|\+)} }
51
52
  datastore.create(word: 'plused', ban: true)
52
- engine.banned.to_a.should have(1).word
53
+ expect(engine.banned.to_a.size). to eq(1)
53
54
  DodgyStalker.configure {|c| c.word_separator = old_separator }
54
55
  end
55
56
 
56
57
  it "matches with partials" do
57
58
  datastore.create(word: 'fuck', ban: true)
58
- engine.to_a(true).should have(1).element
59
+ expect(engine.to_a(true).size).to eq(1)
59
60
  end
60
61
  end
61
62
  end
@@ -7,13 +7,13 @@ describe DodgyStalker::Engines::StopForumSpam do
7
7
 
8
8
  context "when user is in sfs database" do
9
9
  it "returns true confidence is above 0.75" do
10
- engine.stub(:confidence_for).and_return(0.76)
11
- engine.on_blacklist?.should be true
10
+ allow(engine).to receive(:confidence_for) { 0.76 }
11
+ expect(engine.on_blacklist?).to eq(true)
12
12
  end
13
13
 
14
14
  it "returns false when confidence is below 0.75" do
15
- engine.stub(:confidence_for).and_return(0.74)
16
- engine.on_blacklist?.should be false
15
+ allow(engine).to receive(:confidence_for) { 0.74 }
16
+ expect(engine.on_blacklist?).to eq(false)
17
17
  end
18
18
  end
19
19
  end
data/spec/policy_spec.rb CHANGED
@@ -6,12 +6,12 @@ describe DodgyStalker::Policy do
6
6
 
7
7
  describe "#validate" do
8
8
  it "returns true if there are any blacklist results" do
9
- policy.validate.should be true
9
+ expect(policy.validate).to eq(true)
10
10
  end
11
11
 
12
12
  it "returns false if there are no blacklist entries" do
13
- policy.stub(:spamcheck_results).and_return([])
14
- policy.validate.should be false
13
+ allow(policy).to receive(:spamcheck_results) { [] }
14
+ expect(policy.validate).to eq(false)
15
15
  end
16
16
  end
17
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dodgy_stalker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - robuye
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-14 00:00:00.000000000 Z
11
+ date: 2016-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -126,14 +126,14 @@ dependencies:
126
126
  name: activerecord
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - "~>"
129
+ - - ">="
130
130
  - !ruby/object:Gem::Version
131
131
  version: '4.0'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - "~>"
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '4.0'
139
139
  - !ruby/object:Gem::Dependency
@@ -172,6 +172,7 @@ extensions: []
172
172
  extra_rdoc_files: []
173
173
  files:
174
174
  - ".gitignore"
175
+ - ".ruby-version"
175
176
  - Gemfile
176
177
  - LICENSE
177
178
  - LICENSE.txt
@@ -181,23 +182,17 @@ files:
181
182
  - lib/dodgy_stalker.rb
182
183
  - lib/dodgy_stalker/config.rb
183
184
  - lib/dodgy_stalker/data_store.rb
184
- - lib/dodgy_stalker/data_store/blacklist.rb
185
185
  - lib/dodgy_stalker/data_store/common.rb
186
- - lib/dodgy_stalker/data_store/whitelist.rb
187
186
  - lib/dodgy_stalker/data_store/wordlist.rb
188
187
  - lib/dodgy_stalker/engines.rb
189
188
  - lib/dodgy_stalker/engines/banned_words.rb
190
- - lib/dodgy_stalker/engines/blacklist.rb
191
189
  - lib/dodgy_stalker/engines/stop_forum_spam.rb
192
190
  - lib/dodgy_stalker/policy.rb
193
191
  - lib/dodgy_stalker/version.rb
194
192
  - lib/generators/dodgy_stalker/migration_generator.rb
195
193
  - lib/generators/dodgy_stalker/templates/migration.rb
196
- - spec/datastores/blacklist_spec.rb
197
- - spec/datastores/whitelist_spec.rb
198
194
  - spec/datastores/wordlist_spec.rb
199
195
  - spec/engines/banned_words_spec.rb
200
- - spec/engines/blacklist_spec.rb
201
196
  - spec/engines/stop_form_spam_spec.rb
202
197
  - spec/migrations/001_create_dodgy_stalker_tables.rb
203
198
  - spec/policy_spec.rb
@@ -222,16 +217,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
217
  version: '0'
223
218
  requirements: []
224
219
  rubyforge_project:
225
- rubygems_version: 2.2.2
220
+ rubygems_version: 2.4.5.1
226
221
  signing_key:
227
222
  specification_version: 4
228
223
  summary: Filters to detect spam, trolls and unwanted content
229
224
  test_files:
230
- - spec/datastores/blacklist_spec.rb
231
- - spec/datastores/whitelist_spec.rb
232
225
  - spec/datastores/wordlist_spec.rb
233
226
  - spec/engines/banned_words_spec.rb
234
- - spec/engines/blacklist_spec.rb
235
227
  - spec/engines/stop_form_spam_spec.rb
236
228
  - spec/migrations/001_create_dodgy_stalker_tables.rb
237
229
  - spec/policy_spec.rb
@@ -1,9 +0,0 @@
1
- module DodgyStalker
2
- module DataStore
3
- class Blacklist < ActiveRecord::Base
4
- self.table_name = 'blacklist'
5
-
6
- include Common
7
- end
8
- end
9
- end
@@ -1,14 +0,0 @@
1
- module DodgyStalker
2
- module DataStore
3
- class Whitelist < ActiveRecord::Base
4
- self.table_name = 'whitelist'
5
-
6
- include Common
7
-
8
- def on_list(attr)
9
- conditions = attributes.with_indifferent_access.except(:id, :created_at, :updated_at).merge(attr)
10
- model.where(conditions)
11
- end
12
- end
13
- end
14
- end
@@ -1,55 +0,0 @@
1
- module DodgyStalker
2
- module Engines
3
- class Blacklist
4
- def initialize(attributes)
5
- @attributes = attributes
6
- end
7
-
8
- def banned_ip?(ip)
9
- return false if ip.nil?
10
- DataStore::Blacklist.where(ip_address: ip).exists?
11
- end
12
-
13
- def on_blacklist?
14
- return false if whitelist.on_list(attributes).exists?
15
-
16
- Policy.new(fetched_results).validate
17
- end
18
-
19
- def blacklist!(opts={})
20
- if (blacklist.add(attributes.merge(opts)) && whitelist.remove(attributes))
21
- true
22
- else
23
- false
24
- end
25
- end
26
-
27
- #Remove attributes from blacklist and add to whitelist
28
- def remove!
29
- if (blacklist.remove(attributes) && whitelist.add(attributes))
30
- true
31
- else
32
- false
33
- end
34
- end
35
-
36
- private
37
-
38
- def fetched_results
39
- @fetched_results ||= blacklist.on_list(attributes).to_a
40
- end
41
-
42
- def blacklist
43
- DataStore::Blacklist.new
44
- end
45
-
46
- def whitelist
47
- DataStore::Whitelist.new
48
- end
49
-
50
- def attributes
51
- @attributes
52
- end
53
- end
54
- end
55
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe DodgyStalker::DataStore::Blacklist do
4
- let(:list) { described_class.new }
5
- let(:user) { double('User', username: 'Rob', email: 'email@domain.com') }
6
- let(:attributes) { { email: user.email, username: user.username } }
7
-
8
- describe "#on_list" do
9
- it "returns matches for any attributes" do
10
- list.add(username: user.username)
11
- list.add(email: user.email)
12
- list.on_list(attributes).should have(2).entries
13
- end
14
- end
15
-
16
- describe "#add" do
17
- it "adds new entry to blacklist" do
18
- expect { list.add(attributes) }.to change { DodgyStalker::DataStore::Blacklist.count }.
19
- from(0).to(1)
20
- end
21
-
22
- it "does not add duplicates" do
23
- list.add(attributes)
24
- expect { list.add(attributes) }.to_not change { DodgyStalker::DataStore::Blacklist.count }
25
- end
26
- end
27
-
28
- describe "#remove" do
29
- it "removes user from blacklist" do
30
- list.add(attributes)
31
- expect { list.remove(attributes) }.to change { DodgyStalker::DataStore::Blacklist.count }.
32
- from(1).to(0)
33
- end
34
-
35
- it "removes only exact matches" do
36
- list.add(attributes.merge(facebook_uid: '123'))
37
- expect { list.remove(attributes) }.to_not change { DodgyStalker::DataStore::Blacklist.count }
38
- end
39
- end
40
- end
@@ -1,44 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe DodgyStalker::DataStore::Whitelist do
4
- let(:list) { described_class.new }
5
- let(:user) { double('User', email: 'rob@example.com', username: 'rob') }
6
- let(:attributes) { { email: user.email, username: user.username } }
7
-
8
- describe "#on_list" do
9
- it "returns only exact matches" do
10
- list.add(username: user.username)
11
- list.add(email: user.email)
12
- list.add(attributes)
13
-
14
- list.on_list(attributes).should have(1).entry
15
-
16
- list.on_list(username: user.username, email: 'mail@domain.com').should have(0).entries
17
- end
18
- end
19
-
20
- describe "#add" do
21
- it "adds new entry to whitelist" do
22
- expect { list.add(attributes) }.to change { DodgyStalker::DataStore::Whitelist.count }.
23
- from(0).to(1)
24
- end
25
-
26
- it "does not add duplicates" do
27
- list.add(attributes)
28
- expect { list.add(attributes) }.to_not change { DodgyStalker::DataStore::Whitelist.count }
29
- end
30
- end
31
-
32
- describe "#remove" do
33
- it "removes user from whitelist" do
34
- list.add(attributes)
35
- expect { list.remove(attributes) }.to change { DodgyStalker::DataStore::Whitelist.count }.
36
- from(1).to(0)
37
- end
38
-
39
- it "removes only exact matches" do
40
- list.add(attributes.merge(facebook_uid: '123'))
41
- expect { list.remove(attributes) }.to_not change { DodgyStalker::DataStore::Whitelist.count }
42
- end
43
- end
44
- end
@@ -1,67 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe DodgyStalker::Engines::Blacklist do
4
- let(:engine) { described_class.new(attributes) }
5
- let(:user) { double('User', username: 'rob', email: 'rob@example.com') }
6
- let(:attributes) { { email: user.email, username: user.username } }
7
-
8
- describe "#on_blacklist?" do
9
- context "when there is no whitelist entry" do
10
- it "returns true when user is on blacklist" do
11
- DodgyStalker::DataStore::Blacklist.new.add(attributes)
12
- engine.on_blacklist?.should be true
13
- end
14
-
15
- it "returns false when user is not on blacklist" do
16
- engine.on_blacklist?.should be false
17
- end
18
- end
19
-
20
- it "returns false when there is whitelist entry" do
21
- DodgyStalker::DataStore::Whitelist.new.add(attributes)
22
- DodgyStalker::DataStore::Blacklist.new.add(attributes)
23
- engine.on_blacklist?.should be false
24
- end
25
- end
26
-
27
- describe "#blacklist!" do
28
- it "adds user to blacklist" do
29
- expect { engine.blacklist! }.to change { DodgyStalker::DataStore::Blacklist.count }.
30
- from(0).to(1)
31
- end
32
-
33
- it "removes user from whitelist" do
34
- DodgyStalker::DataStore::Whitelist.new.add(attributes)
35
- expect { engine.blacklist! }.to change { DodgyStalker::DataStore::Whitelist.count }.
36
- from(1).to(0)
37
- end
38
- end
39
-
40
- describe "#banned_ip?" do
41
- it "returns false if passed ip is nil" do
42
- engine.banned_ip?(nil).should be false
43
- end
44
-
45
- it "returns false if IP is not on blacklist" do
46
- engine.banned_ip?('0.0.0.0').should be false
47
- end
48
-
49
- it "returns true if IP is on blacklist" do
50
- DodgyStalker::DataStore::Blacklist.new.add(ip_address: '1.2.3.4')
51
- engine.banned_ip?('1.2.3.4').should be true
52
- end
53
- end
54
-
55
- describe "#remove!" do
56
- it "removes the user from blacklist" do
57
- DodgyStalker::DataStore::Blacklist.new.add(attributes)
58
- expect { engine.remove! }.to change { DodgyStalker::DataStore::Blacklist.count }.
59
- from(1).to(0)
60
- end
61
-
62
- it "adds the user to whitelist" do
63
- expect { engine.remove! }.to change { DodgyStalker::DataStore::Whitelist.count }.
64
- from(0).to(1)
65
- end
66
- end
67
- end