Permalink
Browse files

Created the negative-captcha gem

  • Loading branch information...
stefants committed May 24, 2011
1 parent 5e3c009 commit dc0c1bbde675066ad99e7c701aaac82d789ccf37
Showing with 88 additions and 21 deletions.
  1. +14 −12 README.textile
  2. +18 −2 Rakefile
  3. +1 −6 init.rb
  4. +6 −0 lib/{negative_captcha.rb → negative-captcha.rb}
  5. +46 −0 negative-captcha.gemspec
  6. +1 −0 rails/init.rb
  7. +2 −1 test/negative_captcha_test.rb
View
@@ -1,10 +1,10 @@
-h1. Negative Captcha Plugin
+h1. Negative Captcha
h2. What is a Negative Captcha?
A negative captcha has the exact same purpose as your run-of-the-mill image captcha: To keep bots from submitting forms. Image ("positive") captchas do this by implementing a step which only humans can do, but bots cannot: read jumbled characters from an image. But this is bad. It creates usability problems, it hurts conversion rates, and it confuses the shit out of lots of people. Why not do it the other way around? Negative captchas create a form that has tasks that only bots can perform, but humans cannot. This has the exact same effect, with (anecdotally) a much lower false positive identification rate when compared with positive captchas. All of this comes without making humans go through any extra trouble to submit the form. It really is win-win.
-h2. How does a Negative Captcha Work?
+h2. How does it work?
In a negative captcha form there are two main parts and three ancillary parts. I'll explain them thusly.
@@ -40,23 +40,25 @@ h4. Secret key
This is simply some key that is used in the hashing method to prevent bots from backing out the name of the field from the hashed field name.
-h2. How does the Negative Captcha Plugin Work?
+h2. How does Negative Captcha work?
-h3. Install the plugin
+h3. Installation
-h4. Subversion Installation
+h4. Rails 3
+
+You can let bundler install Negative Captcha by adding this line to your application’s Gemfile:
<pre>
<code>
- script/plugin install http://code.subwindow.com/negative_captcha
+ gem 'negative-captcha', :git => 'git://github.com/stefants/negative-captcha.git'
</code>
</pre>
-
-h4. Git Installation
+
+And then execute:
<pre>
<code>
- git submodule add git://github.com/subwindow/negative-captcha.git vendor/plugins/negative_captcha
+ bundle install
</code>
</pre>
@@ -111,15 +113,15 @@ Modify your form to include the honeypots and other fields. You can probably le
<%= raw negative_captcha(@captcha) %>
<ul class="contact_us">
<li>
- <%= negative_label_tag(@captcha, :name, 'Name:') %>
+ <%= negative_label_tag(@captcha, :name, 'Name:') %>
<%= negative_text_field_tag @captcha, :name %>
</li>
<li>
- <%= negative_label_tag(@captcha, :email, 'Email:') %>
+ <%= negative_label_tag(@captcha, :email, 'Email:') %>
<%= negative_text_field_tag @captcha, :email %>
</li>
<li>
- <%= negative_label_tag(@captcha, :body, 'Your Comment:') %>
+ <%= negative_label_tag(@captcha, :body, 'Your Comment:') %>
<%= negative_text_area_tag @captcha, :body %>
</li>
<li>
View
@@ -5,18 +5,34 @@ require 'rake/rdoctask'
desc 'Default: run unit tests.'
task :default => :test
-desc 'Test the negative_captcha plugin.'
+desc 'Tests negative-captcha.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end
-desc 'Generate documentation for the negative_captcha plugin.'
+desc 'Generates documentation for negative-captcha.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'NegativeCaptcha'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end
+
+desc 'Create the negative-captcha gemspec'
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = 'negative-captcha'
+ gem.summary = %Q{Makes the process of creating a negative captcha in Rails much less painless.}
+ gem.description = %Q{Makes the process of creating a negative captcha in Rails much less painless.}
+ gem.email = 'erik@skribit.com'
+ gem.homepage = 'https://github.com/stefants/negative-captcha'
+ gem.authors = ['subwindow']
+ end
+ Jeweler::GemcutterTasks.new
+rescue LoadError
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
+end
View
@@ -1,6 +1 @@
-require 'negative_captcha'
-if !ActionView::Base.instance_methods.include? 'negative_captcha'
- require 'negative_captcha_view_helpers'
- ActionView::Base.class_eval { include NegativeCaptchaViewHelpers }
-end
-require "negative_captcha_form_builder"
+require 'rails/init'
@@ -60,3 +60,9 @@ def process(params)
end
end
end
+
+if !ActionView::Base.instance_methods.include? 'negative_captcha'
+ require 'negative_captcha_view_helpers'
+ ActionView::Base.class_eval { include NegativeCaptchaViewHelpers }
+end
+require "negative_captcha_form_builder"
View
@@ -0,0 +1,46 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{negative-captcha}
+ s.version = "0.1.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["subwindow"]
+ s.date = %q{2011-05-23}
+ s.description = %q{Makes the process of creating a negative captcha in Rails much less painless.}
+ s.email = %q{erik@skribit.com}
+ s.extra_rdoc_files = [
+ "LICENSE",
+ "README.textile"
+ ]
+ s.files = [
+ "LICENSE",
+ "README.textile",
+ "Rakefile",
+ "init.rb",
+ "lib/negative-captcha.rb",
+ "lib/negative_captcha_form_builder.rb",
+ "lib/negative_captcha_view_helpers.rb",
+ "meta.yml",
+ "negative-captcha.gemspec",
+ "rails/init.rb",
+ "test/negative_captcha_test.rb"
+ ]
+ s.homepage = %q{https://github.com/stefants/negative-captcha}
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.5.2}
+ s.summary = %q{Makes the process of creating a negative captcha in Rails much less painless.}
+
+ if s.respond_to? :specification_version then
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ else
+ end
+ else
+ end
+end
+
View
@@ -0,0 +1 @@
+require 'negative-captcha'
@@ -1,7 +1,8 @@
require 'rubygems'
require 'active_support'
+require 'action_view'
require 'test/unit'
-require File.expand_path(File.join(File.dirname(__FILE__), '../lib/negative_captcha'))
+require File.expand_path(File.join(File.dirname(__FILE__), '../lib/negative-captcha'))
class NegativeCaptchaTest < Test::Unit::TestCase
def test_valid_submission

0 comments on commit dc0c1bb

Please sign in to comment.