molasses_jar 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +42 -0
- data/VERSION +1 -1
- data/lib/molasses_jar/extensions.rb +11 -4
- data/molasses_jar.gemspec +4 -4
- data/spec/molasses_jar_spec.rb +1 -29
- data/spec/spec_helper.rb +75 -1
- metadata +5 -5
- data/README.rdoc +0 -21
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
= molasses_jar
|
2
|
+
|
3
|
+
A simple ActiveRecord extension for creating honeypot style captchas.
|
4
|
+
|
5
|
+
== How To Use
|
6
|
+
|
7
|
+
MolassesJar will add simple honeypot verification to any model you wish. It creates an attribute called :molasses_jar on the desired object and then checks to see if there is a value assigned to it. If there is, then the object does not validate. You will need to add an input to your objects form with the attribute :molasses_jar and then using your css, either display: none or move the form off the screen using absolute positioning.
|
8
|
+
|
9
|
+
class ContactForm < ActiveRecord::Base
|
10
|
+
include MolassesJar::Extensions
|
11
|
+
end
|
12
|
+
|
13
|
+
MolassesJar will look for a boolean attribute called ```spam``` on your model. If it finds it, it will update the attribute to be true if it thinks the record is being submitted by a robot. This method prevents losing legitimate content.
|
14
|
+
|
15
|
+
Coming Soon:
|
16
|
+
|
17
|
+
* Form Helper to create the form input
|
18
|
+
* Database flagging to prevent false positives
|
19
|
+
* Stylesheet generator to create the stylesheet
|
20
|
+
* Accessibility improvements for readers
|
21
|
+
|
22
|
+
|
23
|
+
== Interesting Reads on the Honeypot Approach
|
24
|
+
|
25
|
+
* http://haacked.com/archive/2007/09/11/honeypot-captcha.aspx/
|
26
|
+
* http://www.londonswebdesign.com/articles/Web-articles-Honeypot-CAPTCHA-vs-Spambots.html
|
27
|
+
|
28
|
+
== Contributing to molasses_jar
|
29
|
+
|
30
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
31
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
32
|
+
* Fork the project.
|
33
|
+
* Start a feature/bugfix branch.
|
34
|
+
* Commit and push until you are happy with your contribution.
|
35
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
36
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
37
|
+
|
38
|
+
== Copyright
|
39
|
+
|
40
|
+
Copyright (c) 2012 mindtonic. See LICENSE.txt for
|
41
|
+
further details.
|
42
|
+
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
@@ -3,12 +3,19 @@ module MolassesJar
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
attr_accessor :molasses_jar
|
6
|
+
attr_accessor :molasses_jar, :spam
|
7
7
|
|
8
|
-
|
8
|
+
scope :spammy, where(:spam => true)
|
9
|
+
scope :not_spammy, where(:spam => false)
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
validate :mark_as_spam?
|
12
|
+
|
13
|
+
def mark_as_spam?
|
14
|
+
self.spam = true if self.molasses_jar.present?
|
15
|
+
end
|
16
|
+
|
17
|
+
def spam?
|
18
|
+
self.spam
|
12
19
|
end
|
13
20
|
end
|
14
21
|
end
|
data/molasses_jar.gemspec
CHANGED
@@ -5,22 +5,22 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "molasses_jar"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["mindtonic"]
|
12
|
-
s.date = "2012-07-
|
12
|
+
s.date = "2012-07-31"
|
13
13
|
s.description = "A honeypot style captcha extension for ActiveRecord. Simple one-line inclusion in the model combined with a simple form field should trap the bad guys in the molasses."
|
14
14
|
s.email = "mindtonic@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
|
-
"README.
|
17
|
+
"README.md"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
"Gemfile",
|
22
22
|
"LICENSE.txt",
|
23
|
-
"README.
|
23
|
+
"README.md",
|
24
24
|
"Rakefile",
|
25
25
|
"VERSION",
|
26
26
|
"lib/molasses_jar.rb",
|
data/spec/molasses_jar_spec.rb
CHANGED
@@ -2,34 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe MolassesJar do
|
4
4
|
|
5
|
-
|
6
|
-
before(:each) { @contact_form = ContactForm.new }
|
7
|
-
|
8
|
-
it "should have a molasses_jar attribute" do
|
9
|
-
lambda{ @contact_form.molasses_jar }.should_not raise_error
|
10
|
-
end
|
11
|
-
|
12
|
-
it "should be nil by default" do
|
13
|
-
@contact_form.molasses_jar.nil?.should be true
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "with a molasses_jar value" do
|
18
|
-
before(:each) { @contact_form = ContactForm.new }
|
19
|
-
|
20
|
-
it "should not be valid with a string" do
|
21
|
-
@contact_form.molasses_jar = "I am a robot"
|
22
|
-
@contact_form.should_not be_valid
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "without a molasses_jar value" do
|
27
|
-
before(:each) { @contact_form = ContactForm.new }
|
28
|
-
|
29
|
-
it "should be valid" do
|
30
|
-
@contact_form.molasses_jar = ""
|
31
|
-
@contact_form.should be_valid
|
32
|
-
end
|
33
|
-
end
|
5
|
+
it_should_behave_like "a molasses_jar", :contact_form
|
34
6
|
|
35
7
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -19,7 +19,7 @@ require 'molasses_jar'
|
|
19
19
|
require 'logger'
|
20
20
|
|
21
21
|
|
22
|
-
ActiveRecord::Base.logger = Logger.new(STDERR)
|
22
|
+
#ActiveRecord::Base.logger = Logger.new(STDERR)
|
23
23
|
|
24
24
|
ActiveRecord::Base.establish_connection(
|
25
25
|
:adapter => "sqlite3",
|
@@ -35,4 +35,78 @@ end
|
|
35
35
|
|
36
36
|
class ContactForm < ActiveRecord::Base
|
37
37
|
include MolassesJar::Extensions
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
#
|
42
|
+
# Molasses Jar Example Group
|
43
|
+
#
|
44
|
+
# Usage Example:
|
45
|
+
# In your model spec, it_should_behave_like "a molasses_jar", :singular_model_name
|
46
|
+
#
|
47
|
+
|
48
|
+
shared_examples "a molasses_jar" do |model|
|
49
|
+
|
50
|
+
describe "a Molasses Jar" do
|
51
|
+
before(:each) do
|
52
|
+
eval "@model = #{model.to_s.camelize}.new"
|
53
|
+
end
|
54
|
+
|
55
|
+
context "molasses_jar attributes" do
|
56
|
+
it "should have a molasses_jar attribute" do
|
57
|
+
lambda{ @model.molasses_jar }.should_not raise_error
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should initialize as nil" do
|
61
|
+
@model.molasses_jar.nil?.should be true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "scopes" do
|
66
|
+
it "should respond to spammy" do
|
67
|
+
eval "#{model.to_s.camelize}.respond_to?(:spammy).should be true"
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should respond to not_spammy" do
|
71
|
+
eval "#{model.to_s.camelize}.respond_to?(:not_spammy).should be true"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "with a molasses_jar value" do
|
76
|
+
before(:each) do
|
77
|
+
@model.update_attributes(:molasses_jar => "I am a robot")
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should be valid" do
|
81
|
+
@model.should be_valid
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should be marked as spam" do
|
85
|
+
@model.spam.should be true
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should return true for spam?" do
|
89
|
+
@model.spam?.should be true
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "without a molasses_jar value" do
|
94
|
+
before(:each) do
|
95
|
+
@model.update_attributes(:molasses_jar => "")
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should be valid" do
|
99
|
+
@model.should be_valid
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should not be marked as spam" do
|
103
|
+
@model.spam.should be (false || nil)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should return false for spam?" do
|
107
|
+
@model.spam?.should be (false || nil)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
38
112
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: molasses_jar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -147,12 +147,12 @@ executables: []
|
|
147
147
|
extensions: []
|
148
148
|
extra_rdoc_files:
|
149
149
|
- LICENSE.txt
|
150
|
-
- README.
|
150
|
+
- README.md
|
151
151
|
files:
|
152
152
|
- .document
|
153
153
|
- Gemfile
|
154
154
|
- LICENSE.txt
|
155
|
-
- README.
|
155
|
+
- README.md
|
156
156
|
- Rakefile
|
157
157
|
- VERSION
|
158
158
|
- lib/molasses_jar.rb
|
@@ -176,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
176
176
|
version: '0'
|
177
177
|
segments:
|
178
178
|
- 0
|
179
|
-
hash:
|
179
|
+
hash: 4352536654887980733
|
180
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
181
|
none: false
|
182
182
|
requirements:
|
data/README.rdoc
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
= molasses_jar
|
2
|
-
|
3
|
-
A simple ActiveRecord extension for creating honeypot style captchas.
|
4
|
-
|
5
|
-
UNDER CONSTRUCTION
|
6
|
-
|
7
|
-
== Contributing to molasses_jar
|
8
|
-
|
9
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
10
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
11
|
-
* Fork the project.
|
12
|
-
* Start a feature/bugfix branch.
|
13
|
-
* Commit and push until you are happy with your contribution.
|
14
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
15
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
16
|
-
|
17
|
-
== Copyright
|
18
|
-
|
19
|
-
Copyright (c) 2012 mindtonic. See LICENSE.txt for
|
20
|
-
further details.
|
21
|
-
|