is_bot 0.1.0 → 0.2.0
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.
- data/{spec/spec.opts → .rspec} +0 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +83 -0
- data/VERSION +1 -1
- data/is_bot.gemspec +55 -0
- data/lib/is_bot/is_bot.rb +6 -8
- data/pkg/is_bot-0.1.0.gem +0 -0
- data/spec/database.yml +2 -2
- data/spec/is_bot_spec.rb +16 -16
- data/spec/models.rb +1 -1
- data/spec/spec_helper.rb +9 -8
- metadata +67 -11
- data/.gitignore +0 -2
data/{spec/spec.opts → .rspec}
RENAMED
File without changes
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
abstract (1.0.0)
|
5
|
+
actionmailer (3.0.3)
|
6
|
+
actionpack (= 3.0.3)
|
7
|
+
mail (~> 2.2.9)
|
8
|
+
actionpack (3.0.3)
|
9
|
+
activemodel (= 3.0.3)
|
10
|
+
activesupport (= 3.0.3)
|
11
|
+
builder (~> 2.1.2)
|
12
|
+
erubis (~> 2.6.6)
|
13
|
+
i18n (~> 0.4)
|
14
|
+
rack (~> 1.2.1)
|
15
|
+
rack-mount (~> 0.6.13)
|
16
|
+
rack-test (~> 0.5.6)
|
17
|
+
tzinfo (~> 0.3.23)
|
18
|
+
activemodel (3.0.3)
|
19
|
+
activesupport (= 3.0.3)
|
20
|
+
builder (~> 2.1.2)
|
21
|
+
i18n (~> 0.4)
|
22
|
+
activerecord (3.0.3)
|
23
|
+
activemodel (= 3.0.3)
|
24
|
+
activesupport (= 3.0.3)
|
25
|
+
arel (~> 2.0.2)
|
26
|
+
tzinfo (~> 0.3.23)
|
27
|
+
activeresource (3.0.3)
|
28
|
+
activemodel (= 3.0.3)
|
29
|
+
activesupport (= 3.0.3)
|
30
|
+
activesupport (3.0.3)
|
31
|
+
arel (2.0.7)
|
32
|
+
builder (2.1.2)
|
33
|
+
diff-lcs (1.1.2)
|
34
|
+
erubis (2.6.6)
|
35
|
+
abstract (>= 1.0.0)
|
36
|
+
i18n (0.5.0)
|
37
|
+
mail (2.2.14)
|
38
|
+
activesupport (>= 2.3.6)
|
39
|
+
i18n (>= 0.4.0)
|
40
|
+
mime-types (~> 1.16)
|
41
|
+
treetop (~> 1.4.8)
|
42
|
+
mime-types (1.16)
|
43
|
+
polyglot (0.3.1)
|
44
|
+
rack (1.2.1)
|
45
|
+
rack-mount (0.6.13)
|
46
|
+
rack (>= 1.0.0)
|
47
|
+
rack-test (0.5.7)
|
48
|
+
rack (>= 1.0)
|
49
|
+
rails (3.0.3)
|
50
|
+
actionmailer (= 3.0.3)
|
51
|
+
actionpack (= 3.0.3)
|
52
|
+
activerecord (= 3.0.3)
|
53
|
+
activeresource (= 3.0.3)
|
54
|
+
activesupport (= 3.0.3)
|
55
|
+
bundler (~> 1.0)
|
56
|
+
railties (= 3.0.3)
|
57
|
+
railties (3.0.3)
|
58
|
+
actionpack (= 3.0.3)
|
59
|
+
activesupport (= 3.0.3)
|
60
|
+
rake (>= 0.8.7)
|
61
|
+
thor (~> 0.14.4)
|
62
|
+
rake (0.8.7)
|
63
|
+
rspec (2.4.0)
|
64
|
+
rspec-core (~> 2.4.0)
|
65
|
+
rspec-expectations (~> 2.4.0)
|
66
|
+
rspec-mocks (~> 2.4.0)
|
67
|
+
rspec-core (2.4.0)
|
68
|
+
rspec-expectations (2.4.0)
|
69
|
+
diff-lcs (~> 1.1.2)
|
70
|
+
rspec-mocks (2.4.0)
|
71
|
+
sqlite3 (1.3.3)
|
72
|
+
thor (0.14.6)
|
73
|
+
treetop (1.4.9)
|
74
|
+
polyglot (>= 0.3.1)
|
75
|
+
tzinfo (0.3.24)
|
76
|
+
|
77
|
+
PLATFORMS
|
78
|
+
ruby
|
79
|
+
|
80
|
+
DEPENDENCIES
|
81
|
+
rails (= 3.0.3)
|
82
|
+
rspec (= 2.4.0)
|
83
|
+
sqlite3 (= 1.3.3)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/is_bot.gemspec
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{is_bot}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Anuj Dutta"]
|
12
|
+
s.date = %q{2009-11-20}
|
13
|
+
s.description = %q{Simple gem to reduce the spam attacks on sign-up, sign-in and other similar sorts of forms.}
|
14
|
+
s.email = %q{anuj@andhapp.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.markdown",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"init.rb",
|
26
|
+
"lib/is_bot.rb",
|
27
|
+
"lib/is_bot/is_bot.rb",
|
28
|
+
"spec/database.yml",
|
29
|
+
"spec/is_bot_spec.rb",
|
30
|
+
"spec/models.rb",
|
31
|
+
"spec/schema.db",
|
32
|
+
"spec/spec.opts",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/andhapp/is_bot}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.5}
|
39
|
+
s.summary = %q{Fight the bot.}
|
40
|
+
s.test_files = [
|
41
|
+
"spec/is_bot_spec.rb",
|
42
|
+
"spec/models.rb",
|
43
|
+
"spec/spec_helper.rb"
|
44
|
+
]
|
45
|
+
|
46
|
+
if s.respond_to? :specification_version then
|
47
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
48
|
+
s.specification_version = 3
|
49
|
+
|
50
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
51
|
+
else
|
52
|
+
end
|
53
|
+
else
|
54
|
+
end
|
55
|
+
end
|
data/lib/is_bot/is_bot.rb
CHANGED
@@ -4,20 +4,18 @@ module IsBot
|
|
4
4
|
base.class_eval do
|
5
5
|
extend ClassMethods
|
6
6
|
class_inheritable_accessor :captcha_in_reverse
|
7
|
-
end
|
7
|
+
end
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
module ClassMethods
|
11
11
|
def validate_captcha(options = {})
|
12
|
-
|
13
|
-
|
14
|
-
validates_each :captcha_in_reverse, configuration do |record, attr, value|
|
15
|
-
record.errors.add attr, configuration[:message] if not value.blank?
|
12
|
+
validates_each :captcha_in_reverse do |record, attr, value|
|
13
|
+
record.errors[attr] << (options[:message] || "You are a bot!") unless value.blank?
|
16
14
|
end
|
17
15
|
end
|
18
16
|
end
|
19
17
|
end
|
20
|
-
|
18
|
+
|
21
19
|
module ViewHelper
|
22
20
|
def captcha_reverse_field(object, options={})
|
23
21
|
style = (options.delete(:style) || '') << ";"
|
@@ -26,4 +24,4 @@ module IsBot
|
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
29
|
-
end
|
27
|
+
end
|
Binary file
|
data/spec/database.yml
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
test:
|
2
|
-
:adapter:
|
3
|
-
:database:
|
2
|
+
:adapter: sqlite3
|
3
|
+
:database: ':memory:'
|
data/spec/is_bot_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
# ********************* SET-UP **************************
|
4
4
|
# ---------- Models
|
@@ -6,7 +6,7 @@
|
|
6
6
|
# 1. Bot
|
7
7
|
# 2. Robot
|
8
8
|
# Both the models can be found in the models.rb file
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# ---------- Schema
|
11
11
|
# The schema is described in scehma.rb
|
12
12
|
#
|
@@ -16,7 +16,7 @@
|
|
16
16
|
describe IsBot do
|
17
17
|
context "ClassMethods" do
|
18
18
|
context "Set up" do
|
19
|
-
|
19
|
+
|
20
20
|
it "should be in the list of included modules" do
|
21
21
|
Bot.included_modules.should include(IsBot::CaptchaInReverse)
|
22
22
|
end
|
@@ -24,7 +24,7 @@ describe IsBot do
|
|
24
24
|
it "should add a virtual accessor 'captcha_in_reverse' to the class" do
|
25
25
|
bot = Bot.new
|
26
26
|
bot.should.respond_to?(:captcha_in_reverse)
|
27
|
-
bot.should.respond_to?(:captcha_in_reverse=)
|
27
|
+
bot.should.respond_to?(:captcha_in_reverse=)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should add a class method 'validate_captcha'" do
|
@@ -38,13 +38,13 @@ describe IsBot do
|
|
38
38
|
@bot = Bot.new
|
39
39
|
end
|
40
40
|
|
41
|
-
# because a bot would fill in the hidden field
|
41
|
+
# because a bot would fill in the hidden field
|
42
42
|
it "should add to the errors if 'captcha_in_reverse' is not blank?" do
|
43
43
|
lambda {
|
44
44
|
@bot.captcha_in_reverse = "I am a Bot!"
|
45
45
|
@bot.valid?
|
46
46
|
}.should change(@bot.errors, :size).by(1)
|
47
|
-
@bot.errors
|
47
|
+
@bot.errors[:captcha_in_reverse] == "You are a bot!"
|
48
48
|
end
|
49
49
|
|
50
50
|
# because human is not expected to fill this field
|
@@ -53,41 +53,41 @@ describe IsBot do
|
|
53
53
|
@bot.captcha_in_reverse = nil
|
54
54
|
@bot.valid?
|
55
55
|
}.should_not change(@bot.errors, :size).by(1)
|
56
|
-
end
|
56
|
+
end
|
57
57
|
|
58
58
|
context "Custom validation" do
|
59
59
|
it "should accept a custom error message" do
|
60
|
-
robot = Robot.new(:captcha_in_reverse => "I am a Bot!")
|
60
|
+
robot = Robot.new(:captcha_in_reverse => "I am a Bot!")
|
61
61
|
robot.valid?
|
62
|
-
robot.errors
|
62
|
+
robot.errors[:captcha_in_reverse] == "You are a BOT. Go away"
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
end
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
context "Helper" do
|
70
70
|
context "set up" do
|
71
71
|
it "should include the defined custom helper module" do
|
72
72
|
ViewHelper::ViewField.included_modules.should include(IsBot::ViewHelper)
|
73
73
|
end
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
context "input tag" do
|
77
77
|
it "should create one for adding captcha" do
|
78
78
|
ViewHelper::ViewField.new.should.respond_to?(:captcha_reverse_field)
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
it "should be hidden" do
|
82
82
|
captcha_field = ViewHelper::ViewField.new.captcha_reverse_field(:bot)
|
83
83
|
captcha_field.should include("style=\";display: none;\"")
|
84
84
|
end
|
85
|
-
|
85
|
+
|
86
86
|
it "should include the custom defined styles" do
|
87
87
|
captcha_field = ViewHelper::ViewField.new.captcha_reverse_field(:bot, {:style => "color:red"})
|
88
|
-
captcha_field.should include("style=\"color:red;display: none;\"")
|
88
|
+
captcha_field.should include("style=\"color:red;display: none;\"")
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
93
|
-
end
|
92
|
+
|
93
|
+
end
|
data/spec/models.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,20 +1,21 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require 'activerecord'
|
1
|
+
require 'active_record'
|
4
2
|
require 'action_view'
|
5
3
|
require 'yaml'
|
6
|
-
require '
|
7
|
-
|
4
|
+
require 'rspec'
|
5
|
+
|
6
|
+
require File.expand_path("../../init", __FILE__)
|
7
|
+
require File.expand_path("../models", __FILE__)
|
8
|
+
|
8
9
|
def connect(environment)
|
9
10
|
conf = YAML::load(File.open(File.dirname(__FILE__) + '/database.yml'))
|
10
11
|
ActiveRecord::Base.establish_connection(conf[environment])
|
11
12
|
end
|
12
|
-
|
13
|
+
|
13
14
|
connect('test')
|
14
15
|
load(File.join(File.dirname(__FILE__), "schema.db"))
|
15
16
|
|
16
17
|
module ViewHelper; class ViewField < ActionView::Base; end end
|
17
18
|
|
18
|
-
|
19
|
+
RSpec.configure do |config|
|
19
20
|
config.include(ViewHelper)
|
20
|
-
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: is_bot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Anuj Dutta
|
@@ -9,10 +14,54 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2011-01-23 00:00:00 +00:00
|
13
18
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rails
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - "="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 3
|
29
|
+
- 0
|
30
|
+
- 3
|
31
|
+
version: 3.0.3
|
32
|
+
type: :runtime
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - "="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 2
|
44
|
+
- 4
|
45
|
+
- 0
|
46
|
+
version: 2.4.0
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: sqlite3
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - "="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 1
|
59
|
+
- 3
|
60
|
+
- 3
|
61
|
+
version: 1.3.3
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: *id003
|
16
65
|
description: Simple gem to reduce the spam attacks on sign-up, sign-in and other similar sorts of forms.
|
17
66
|
email: anuj@andhapp.com
|
18
67
|
executables: []
|
@@ -23,45 +72,52 @@ extra_rdoc_files:
|
|
23
72
|
- LICENSE
|
24
73
|
- README.markdown
|
25
74
|
files:
|
26
|
-
- .
|
75
|
+
- .rspec
|
76
|
+
- Gemfile
|
77
|
+
- Gemfile.lock
|
27
78
|
- LICENSE
|
28
79
|
- README.markdown
|
29
80
|
- Rakefile
|
30
81
|
- VERSION
|
31
82
|
- init.rb
|
83
|
+
- is_bot.gemspec
|
32
84
|
- lib/is_bot.rb
|
33
85
|
- lib/is_bot/is_bot.rb
|
86
|
+
- pkg/is_bot-0.1.0.gem
|
34
87
|
- spec/database.yml
|
35
88
|
- spec/is_bot_spec.rb
|
36
89
|
- spec/models.rb
|
37
90
|
- spec/schema.db
|
38
|
-
- spec/spec.opts
|
39
91
|
- spec/spec_helper.rb
|
40
92
|
has_rdoc: true
|
41
93
|
homepage: http://github.com/andhapp/is_bot
|
42
94
|
licenses: []
|
43
95
|
|
44
96
|
post_install_message:
|
45
|
-
rdoc_options:
|
46
|
-
|
97
|
+
rdoc_options: []
|
98
|
+
|
47
99
|
require_paths:
|
48
100
|
- lib
|
49
101
|
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
50
103
|
requirements:
|
51
104
|
- - ">="
|
52
105
|
- !ruby/object:Gem::Version
|
106
|
+
segments:
|
107
|
+
- 0
|
53
108
|
version: "0"
|
54
|
-
version:
|
55
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
56
111
|
requirements:
|
57
112
|
- - ">="
|
58
113
|
- !ruby/object:Gem::Version
|
114
|
+
segments:
|
115
|
+
- 0
|
59
116
|
version: "0"
|
60
|
-
version:
|
61
117
|
requirements: []
|
62
118
|
|
63
119
|
rubyforge_project:
|
64
|
-
rubygems_version: 1.3.
|
120
|
+
rubygems_version: 1.3.7
|
65
121
|
signing_key:
|
66
122
|
specification_version: 3
|
67
123
|
summary: Fight the bot.
|
data/.gitignore
DELETED