Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit 074f4f4208a37693bbe30c85b7a233ed94faad22 0 parents
@hardbap authored
20 MIT-LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 [name of plugin creator]
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13 README.textile
@@ -0,0 +1,13 @@
+TrapDoor
+========
+
+Introduction goes here.
+
+
+Example
+=======
+
+Example goes here.
+
+
+Copyright (c) 2009 [name of plugin creator], released under the MIT license
23 Rakefile
@@ -0,0 +1,23 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the trap_door plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the trap_door plugin.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'TrapDoor'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
2  init.rb
@@ -0,0 +1,2 @@
+ActionController::Base.send :include, TrapDoor
+ActionView::Base.send :include, TrapDoor::TrapDoorHelper
1  install.rb
@@ -0,0 +1 @@
+# Install hook code here
29 lib/trap_door.rb
@@ -0,0 +1,29 @@
+module TrapDoor
+ mattr_accessor :honeypot_field_name
+
+ def self.included(controller)
+ self.honeypot_field_name = honeypot_field_name || :affiliate_id
+ controller.extend(ClassMethods)
+ end
+
+ module ClassMethods
+ def trap_door(options = {})
+ send :include, InstanceMethods
+ before_filter :check_params, :only => options[:only], :except => options[:except]
+ end
+ end
+
+ module InstanceMethods
+ private
+
+ def check_params
+ redirect_to 'http://en.wikipedia.org/wiki/User:Mike_Rosoft/Spambot' unless params[honeypot_field_name.to_sym].blank?
+ end
+ end
+
+ module TrapDoorHelper
+ def trap_door_field(options = {})
+ hidden_field_tag(TrapDoor.honeypot_field_name, '', options)
+ end
+ end
+end
4 tasks/trap_door_tasks.rake
@@ -0,0 +1,4 @@
+# desc "Explaining what the task does"
+# task :trap_door do
+# # Task goes here
+# end
11 test/test_helper.rb
@@ -0,0 +1,11 @@
+require 'rubygems'
+require 'test/unit'
+require 'active_support'
+require 'action_controller'
+require 'action_view/test_case'
+require 'trap_door'
+
+ActionController::Base.logger = nil
+ActionController::Routing::Routes.reload rescue nil
+
+ActionController::Base.send :include, TrapDoor
64 test/trap_door_test.rb
@@ -0,0 +1,64 @@
+require 'test_helper'
+
+class TrapDoorController < ActionController::Base
+ trap_door :except => :new
+
+ def new
+ render :nothing => true
+ end
+
+ def create
+ render :nothing => true
+ end
+end
+
+class TrapDoorTest < ActionController::TestCase
+ tests TrapDoorController
+
+ def setup
+ TrapDoor.honeypot_field_name = :affiliate_id
+ end
+
+ test "should redirect if the honeypot param is present" do
+ get :create, :affiliate_id => 1
+ assert_response :redirect
+ end
+
+ test "should not redirect if the honeypot param is missing" do
+ get :create
+ assert_response :success
+ end
+
+ test "should not redirect if honypot param is blank" do
+ get :create, :affiliate_id => ""
+ assert_response :success
+ end
+
+ test "should not redirect if action is in :except" do
+ get :new, :affiliate_id => 1
+ assert_response :success
+ end
+
+ test "should check for the user defined honeypot" do
+ TrapDoor.honeypot_field_name = :spambot_id
+ get :create, :spambot_id => 2
+ assert_response :redirect
+ end
+end
+
+class TrapDoorHelperTest < ActionView::TestCase
+ tests TrapDoor::TrapDoorHelper
+
+ def setup
+ TrapDoor.honeypot_field_name = :affiliate_id
+ end
+
+ test "should render the trap door field" do
+ assert_dom_equal('<input name="affiliate_id" id="affiliate_id" value="" type="hidden" />', trap_door_field)
+ end
+
+ test "should use the user defined honeypot field name" do
+ TrapDoor.honeypot_field_name = :spambot_id
+ assert_dom_equal('<input name="spambot_id" id="spambot_id" value="" type="hidden" />', trap_door_field)
+ end
+end
1  uninstall.rb
@@ -0,0 +1 @@
+# Uninstall hook code here
Please sign in to comment.
Something went wrong with that request. Please try again.