bcms_feedback_form 1.0.0 → 1.0.1

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/README.markdown ADDED
@@ -0,0 +1,45 @@
1
+ # Feedback form module for BrowserCMS > 3.1.0
2
+
3
+ Provides a feedback form content block protected by Recaptcha. It also:
4
+
5
+ * Allows you to specific the thank you message,
6
+ * Gives you the ability to create a custom form,
7
+ * Requires that you register at recaptcha.net and create an API key,
8
+ * Uses prototype to dynamically swap out the form in-place with a thank you message, allowing this to work fine in a statically cached environment.
9
+ * Includes the recaptcha plugin for you.
10
+
11
+ ## Installation
12
+
13
+ 1. Create a recaptcha.net account and set up a public/private API key.
14
+ 2. Follow the generic module instructions here: http://guides.browsercms.org/installing_modules.html
15
+ 3. Edit BROWSER_CMS_ROOT/config/initializer/recaptcha.rb to include your API keys. Restart your rails app.
16
+ 4. Ensure your application is able to deliver outgoing email.
17
+ 5. Ensure that your page template includes the prototype libraries - this relies on form_remote_for() to handle form submissions.
18
+ 6. Test!
19
+
20
+ ## Uninstallation
21
+
22
+ 1. Remove this entry from config/routes.rb
23
+
24
+ map.routes_for_bcms_feedback_form
25
+
26
+ 2. Remove the "config.gem" line that refers to this plugin from config/environment.
27
+
28
+ 3. Remove config/initializers/recaptcha.rb
29
+
30
+ 4. Remove vendor/plugins/recaptcha
31
+
32
+ 5. Remove the database
33
+
34
+ rake db:migrate:down VERSION=20100312161745_create_feedback_forms
35
+
36
+ 6. Remove db/migration/20100312161745_create_feedback_forms.rb
37
+
38
+ ## Author
39
+
40
+ Dan Collis-Puro
41
+ djcp@cyber.law.harvard.edu
42
+
43
+ ## License
44
+
45
+ LGPL
data/rails/init.rb CHANGED
@@ -2,3 +2,5 @@ gem_root = File.expand_path(File.join(File.dirname(__FILE__), ".."))
2
2
  Cms.add_to_rails_paths gem_root
3
3
  Cms.add_generator_paths gem_root, "db/migrate/[0-9]*_*.rb"
4
4
  Cms.add_generator_paths gem_root, "public/bcms/feedback_form/**/*"
5
+ Cms.add_generator_paths gem_root, 'config/initializers/recaptcha.rb'
6
+ Cms.add_generator_paths gem_root, 'vendor/plugins/recaptcha/**/*'
@@ -0,0 +1,23 @@
1
+ == 0.2.2 / 2009-09-14
2
+
3
+ * Add a timeout to the validator
4
+ * Give the documentation some love
5
+
6
+ == 0.2.1 / 2009-09-14
7
+
8
+ * Removed Ambethia namespace, and restructured classes a bit
9
+ * Added an example rails app in the example-rails branch
10
+
11
+ == 0.2.0 / 2009-09-12
12
+
13
+ * RecaptchaOptions AJAX API Fix
14
+ * Added 'cucumber' as a test environment to skip
15
+ * Ruby 1.9 compat fixes
16
+ * Added option :message => 'Custom error message' to verify_recaptcha
17
+ * Removed dependency on ActiveRecord constant
18
+ * Add I18n
19
+
20
+ == 0.1.0 / 2008-2-8
21
+
22
+ * 1 major enhancement
23
+ * Initial Gem Release
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2007 Jason L Perry
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,101 @@
1
+ = reCAPTCHA
2
+
3
+ Author:: Jason L Perry (http://ambethia.com)
4
+ Copyright:: Copyright (c) 2007 Jason L Perry
5
+ License:: {MIT}[http://creativecommons.org/licenses/MIT/]
6
+ Info:: http://ambethia.com/recaptcha
7
+ Git:: http://github.com/ambethia/recaptcha/tree/master
8
+ Bugs:: http://github.com/ambethia/recaptcha/issues
9
+
10
+ This plugin adds helpers for the {reCAPTCHA API}[http://recaptcha.net]. In your views you can use
11
+ the +recaptcha_tags+ method to embed the needed javascript, and you can validate in your controllers
12
+ with +verify_recaptcha+.
13
+
14
+ You'll want to add your public and private API keys in the environment variables +RECAPTCHA_PUBLIC_KEY+
15
+ and +RECAPTCHA_PRIVATE_KEY+, respectively. You could also specify them in <tt>config/environment.rb</tt> if you
16
+ are so inclined (see below). Exceptions will be raised if you call these methods and the keys can't be found.
17
+
18
+ == Rails Installation
19
+
20
+ reCAPTCHA for Rails can be installed as a gem:
21
+
22
+ config.gem "ambethia-recaptcha", :lib => "recaptcha/rails", :source => "http://gems.github.com"
23
+
24
+ Or, as a standard rails plugin:
25
+
26
+ script/plugin install git://github.com/ambethia/recaptcha.git
27
+
28
+ == Merb Installation
29
+
30
+ reCAPTCHA can also be used in a Merb application when installed as a gem:
31
+
32
+ dependency "alm-recaptcha", ">=0.2.2.1", :require_as => "recaptcha/merb"
33
+
34
+ Initial Merb compatability funded by ALM Labs.
35
+
36
+ == Setting up your API Keys
37
+
38
+ There are two ways to setup your reCAPTCHA API keys once you {obtain}[http://recaptcha.net/whyrecaptcha.html]
39
+ a pair. You can pass in your keys as options at runtime, for example:
40
+
41
+ recaptcha_tags :public_key => '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy'
42
+
43
+ and later,
44
+
45
+ verify_recaptcha :private_key => '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'
46
+
47
+
48
+ Or, preferably, you can keep your keys out of your code base by exporting the environment variables
49
+ mentioned earlier. You might do this in the .profile/rc, or equivalent for the user running your
50
+ application:
51
+
52
+ export RECAPTCHA_PUBLIC_KEY = '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy'
53
+ export RECAPTCHA_PRIVATE_KEY = '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'
54
+
55
+ If that's not your thing, and dropping things into <tt>config/environment.rb</tt> is, you can just do:
56
+
57
+ ENV['RECAPTCHA_PUBLIC_KEY'] = '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy'
58
+ ENV['RECAPTCHA_PRIVATE_KEY'] = '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'
59
+
60
+ == +recaptcha_tags+
61
+
62
+ Some of the options available:
63
+
64
+ <tt>:ssl</tt>:: Uses secure http for captcha widget (default +false+)
65
+ <tt>:noscript</tt>:: Include <noscript> content (default +true+)
66
+ <tt>:display</tt>:: Takes a hash containing the +theme+ and +tabindex+ options per the API. (default +nil+)
67
+ <tt>:ajax</tt>:: Render the dynamic AJAX captcha per the API. (default +false+)
68
+ <tt>:public_key</tt>:: Your public API key, takes precedence over the ENV variable (default +nil+)
69
+ <tt>:error</tt>:: Override the error code returned from the reCAPTCHA API (default +nil+)
70
+
71
+ You can also override the html attributes for the sizes of the generated +textarea+ and +iframe+
72
+ elements, if CSS isn't your thing. Inspect the source of +recaptcha_tags+ to see these options.
73
+
74
+ == +verify_recaptcha+
75
+
76
+ This method returns +true+ or +false+ after processing the parameters from the reCAPTCHA widget. Why
77
+ isn't this a model validation? Because that violates MVC. Use can use it like this, or how ever you
78
+ like. Passing in the ActiveRecord object is optional, if you do--and the captcha fails to verify--an
79
+ error will be added to the object for you to use.
80
+
81
+ Some of the options available:
82
+
83
+ <tt>:model</tt>:: Model to set errors
84
+ <tt>:attribute</tt>:: Model attribute to receive errors (default :base)
85
+ <tt>:message</tt>:: Custom error message
86
+ <tt>:private_key</tt>:: Your private API key, takes precedence over the ENV variable (default +nil+).
87
+ <tt>:timeout</tt>:: The number of seconds to wait for reCAPTCHA servers before give up. (default +3+)
88
+
89
+ respond_to do |format|
90
+ if verify_recaptcha(:model => @post, :message => "Oh! It's error with reCAPTCHA!") && @post.save
91
+ # ...
92
+ else
93
+ # ...
94
+ end
95
+ end
96
+
97
+ == TODO
98
+ * Remove Rails/ActionController dependencies
99
+ * Framework agnostic
100
+ * Add some helpers to use in before_filter and what not
101
+ * Better documentation
@@ -0,0 +1,58 @@
1
+ require 'rake'
2
+
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |gem|
6
+ gem.name = "recaptcha"
7
+ gem.description = "This plugin adds helpers for the reCAPTCHA API "
8
+ gem.summary = "Helpers for the reCAPTCHA API"
9
+ gem.homepage = "http://ambethia.com/recaptcha"
10
+ gem.authors = ["Jason L. Perry"]
11
+ gem.email = "jasper@ambethia.com"
12
+ gem.files.reject! { |fn| fn.include? ".gitignore" }
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'rake/rdoctask'
20
+ Rake::RDocTask.new do |rd|
21
+ if File.exist?('VERSION.yml')
22
+ config = YAML.load(File.read('VERSION.yml'))
23
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
24
+ else
25
+ version = ""
26
+ end
27
+
28
+ rd.main = "README.rdoc"
29
+ rd.rdoc_files.include "README.rdoc", "LICENSE", "lib/**/*.rb"
30
+ rd.rdoc_dir = 'rdoc'
31
+ rd.options << '-N' # line numbers
32
+ rd.options << '-S' # inline source
33
+ end
34
+
35
+ require 'rake/testtask'
36
+ Rake::TestTask.new(:test) do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/*_test.rb'
39
+ # test.verbose = true
40
+ end
41
+
42
+ begin
43
+ require 'rcov/rcovtask'
44
+ Rcov::RcovTask.new do |test|
45
+ test.libs << 'test'
46
+ test.pattern = 'test/**/*_test.rb'
47
+ test.verbose = true
48
+ end
49
+ rescue LoadError
50
+ task :rcov do
51
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
52
+ end
53
+ end
54
+
55
+ task :default => :test
56
+
57
+
58
+
@@ -0,0 +1 @@
1
+ 0.2.3
@@ -0,0 +1,6 @@
1
+ # Rails plugin initialization.
2
+ # You can also install it as a gem:
3
+ # config.gem "ambethia-recaptcha", :lib => "recaptcha/rails", :source => "http://gems.github.com"
4
+
5
+ require 'net/http'
6
+ require 'recaptcha/rails'
@@ -0,0 +1,23 @@
1
+ require 'recaptcha/client_helper'
2
+ require 'recaptcha/verify'
3
+
4
+ module Recaptcha
5
+ module VERSION #:nodoc:
6
+ MAJOR = 0
7
+ MINOR = 2
8
+ TINY = 2
9
+ PATCH = 1
10
+
11
+ STRING = [MAJOR, MINOR, TINY, PATCH].join('.')
12
+ end
13
+
14
+
15
+ RECAPTCHA_API_SERVER = 'http://api.recaptcha.net';
16
+ RECAPTCHA_API_SECURE_SERVER = 'https://api-secure.recaptcha.net';
17
+ RECAPTCHA_VERIFY_SERVER = 'api-verify.recaptcha.net';
18
+
19
+ SKIP_VERIFY_ENV = ['test', 'cucumber']
20
+
21
+ class RecaptchaError < StandardError
22
+ end
23
+ end
@@ -0,0 +1,42 @@
1
+ module Recaptcha
2
+ module ClientHelper
3
+ # Your public API can be specified in the +options+ hash or preferably
4
+ # the environment variable +RECAPTCHA_PUBLIC_KEY+.
5
+ def recaptcha_tags(options = {})
6
+ # Default options
7
+ key = options[:public_key] ||= ENV['RECAPTCHA_PUBLIC_KEY']
8
+ raise RecaptchaError, "No public key specified." unless key
9
+ error = options[:error] ||= (defined? flash ? flash[:recaptcha_error] : "")
10
+ uri = options[:ssl] ? RECAPTCHA_API_SECURE_SERVER : RECAPTCHA_API_SERVER
11
+ html = ""
12
+ if options[:display]
13
+ html << %{<script type="text/javascript">\n}
14
+ html << %{ var RecaptchaOptions = #{options[:display].to_json};\n}
15
+ html << %{</script>\n}
16
+ end
17
+ if options[:ajax]
18
+ html << %{<div id="dynamic_recaptcha"></div>}
19
+ html << %{<script type="text/javascript" src="#{uri}/js/recaptcha_ajax.js"></script>\n}
20
+ html << %{<script type="text/javascript">\n}
21
+ html << %{ Recaptcha.create('#{key}', document.getElementById('dynamic_recaptcha')#{options[:display] ? ',RecaptchaOptions' : ''});}
22
+ html << %{</script>\n}
23
+ else
24
+ html << %{<script type="text/javascript" src="#{uri}/challenge?k=#{key}}
25
+ html << %{#{error ? "&error=#{CGI::escape(error)}" : ""}"></script>\n}
26
+ unless options[:noscript] == false
27
+ html << %{<noscript>\n }
28
+ html << %{<iframe src="#{uri}/noscript?k=#{key}" }
29
+ html << %{height="#{options[:iframe_height] ||= 300}" }
30
+ html << %{width="#{options[:iframe_width] ||= 500}" }
31
+ html << %{frameborder="0"></iframe><br/>\n }
32
+ html << %{<textarea name="recaptcha_challenge_field" }
33
+ html << %{rows="#{options[:textarea_rows] ||= 3}" }
34
+ html << %{cols="#{options[:textarea_cols] ||= 40}"></textarea>\n }
35
+ html << %{<input type="hidden" name="recaptcha_response_field" value="manual_challenge">}
36
+ html << %{</noscript>\n}
37
+ end
38
+ end
39
+ return html
40
+ end # recaptcha_tags
41
+ end # ClientHelper
42
+ end # Recaptcha
@@ -0,0 +1,4 @@
1
+ require 'recaptcha'
2
+
3
+ Merb::GlobalHelpers.send(:include, Recaptcha::ClientHelper)
4
+ Merb::Controller.send(:include, Recaptcha::Verify)
@@ -0,0 +1,4 @@
1
+ require 'recaptcha'
2
+
3
+ ActionView::Base.send(:include, Recaptcha::ClientHelper)
4
+ ActionController::Base.send(:include, Recaptcha::Verify)
@@ -0,0 +1,51 @@
1
+ module Recaptcha
2
+ module Verify
3
+ # Your private API can be specified in the +options+ hash or preferably
4
+ # the environment variable +RECAPTCHA_PUBLIC_KEY+.
5
+ def verify_recaptcha(options = {})
6
+ if !options.is_a? Hash
7
+ options = {:model => options}
8
+ end
9
+
10
+ env = options[:env] || ENV['RAILS_ENV']
11
+ return true if SKIP_VERIFY_ENV.include? env
12
+ model = options[:model]
13
+ attribute = options[:attribute] || :base
14
+ private_key = options[:private_key] || ENV['RECAPTCHA_PRIVATE_KEY']
15
+ raise RecaptchaError, "No private key specified." unless private_key
16
+
17
+ begin
18
+ recaptcha = nil
19
+ Timeout::timeout(options[:timeout] || 3) do
20
+ recaptcha = Net::HTTP.post_form URI.parse("http://#{RECAPTCHA_VERIFY_SERVER}/verify"), {
21
+ "privatekey" => private_key,
22
+ "remoteip" => request.remote_ip,
23
+ "challenge" => params[:recaptcha_challenge_field],
24
+ "response" => params[:recaptcha_response_field]
25
+ }
26
+ end
27
+ answer, error = recaptcha.body.split.map { |s| s.chomp }
28
+ unless answer == 'true'
29
+ flash[:recaptcha_error] = error
30
+ if model
31
+ model.valid?
32
+ model.errors.add attribute, options[:message] || "Word verification response is incorrect, please try again."
33
+ end
34
+ return false
35
+ else
36
+ flash[:recaptcha_error] = nil
37
+ return true
38
+ end
39
+ rescue Timeout::Error
40
+ flash[:recaptcha_error] = "recaptcha-not-reachable"
41
+ if model
42
+ model.valid?
43
+ model.errors.add attribute, options[:message] || "Oops, we failed to validate your word verification response. Please try again."
44
+ end
45
+ return false
46
+ rescue Exception => e
47
+ raise RecaptchaError, e.message, e.backtrace
48
+ end
49
+ end # verify_recaptcha
50
+ end # Verify
51
+ end # Recaptcha
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{recaptcha}
8
+ s.version = "0.2.3"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jason L. Perry"]
12
+ s.date = %q{2009-10-23}
13
+ s.description = %q{This plugin adds helpers for the reCAPTCHA API }
14
+ s.email = %q{jasper@ambethia.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ "CHANGELOG",
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "init.rb",
26
+ "lib/recaptcha.rb",
27
+ "lib/recaptcha/client_helper.rb",
28
+ "lib/recaptcha/merb.rb",
29
+ "lib/recaptcha/rails.rb",
30
+ "lib/recaptcha/verify.rb",
31
+ "recaptcha.gemspec",
32
+ "tasks/recaptcha_tasks.rake",
33
+ "test/recaptcha_test.rb",
34
+ "test/verify_recaptcha_test.rb"
35
+ ]
36
+ s.homepage = %q{http://ambethia.com/recaptcha}
37
+ s.rdoc_options = ["--charset=UTF-8"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.3.5}
40
+ s.summary = %q{Helpers for the reCAPTCHA API}
41
+ s.test_files = [
42
+ "test/recaptcha_test.rb",
43
+ "test/verify_recaptcha_test.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
56
+
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :recaptcha do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,37 @@
1
+ require 'test/unit'
2
+ require 'cgi'
3
+ require File.dirname(__FILE__) + '/../lib/recaptcha'
4
+
5
+ class RecaptchaClientHelperTest < Test::Unit::TestCase
6
+ include Recaptcha
7
+ include Recaptcha::ClientHelper
8
+ include Recaptcha::Verify
9
+
10
+ attr_accessor :session
11
+
12
+ def setup
13
+ @session = {}
14
+ ENV['RECAPTCHA_PUBLIC_KEY'] = '0000000000000000000000000000000000000000'
15
+ ENV['RECAPTCHA_PRIVATE_KEY'] = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
16
+ end
17
+
18
+ def test_recaptcha_tags
19
+ # Might as well match something...
20
+ assert_match /http:\/\/api.recaptcha.net/, recaptcha_tags
21
+ end
22
+
23
+ def test_recaptcha_tags_with_ssl
24
+ assert_match /https:\/\/api-secure.recaptcha.net/, recaptcha_tags(:ssl => true)
25
+ end
26
+
27
+ def test_recaptcha_tags_without_noscript
28
+ assert_no_match /noscript/, recaptcha_tags(:noscript => false)
29
+ end
30
+
31
+ def test_should_raise_exception_without_public_key
32
+ assert_raise RecaptchaError do
33
+ ENV['RECAPTCHA_PUBLIC_KEY'] = nil
34
+ recaptcha_tags
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,96 @@
1
+ require 'test/unit'
2
+ require 'rails/version' # For getting the rails version constants
3
+ require 'active_support/vendor' # For loading I18n
4
+ require 'mocha'
5
+ require 'net/http'
6
+ require File.dirname(__FILE__) + '/../lib/recaptcha'
7
+
8
+ class RecaptchaVerifyTest < Test::Unit::TestCase
9
+ def setup
10
+
11
+ ENV['RECAPTCHA_PRIVATE_KEY'] = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
12
+ @controller = TestController.new
13
+ @controller.request = stub(:remote_ip => "1.1.1.1")
14
+ @controller.params = {:recaptcha_challenge_field => "challenge", :recaptcha_response_field => "response"}
15
+
16
+ @expected_post_data = {}
17
+ @expected_post_data["privatekey"] = ENV['RECAPTCHA_PRIVATE_KEY']
18
+ @expected_post_data["remoteip"] = @controller.request.remote_ip
19
+ @expected_post_data["challenge"] = "challenge"
20
+ @expected_post_data["response"] = "response"
21
+
22
+ @expected_uri = URI.parse("http://#{Recaptcha::RECAPTCHA_VERIFY_SERVER}/verify")
23
+ end
24
+
25
+ def test_should_raise_exception_without_private_key
26
+ assert_raise Recaptcha::RecaptchaError do
27
+ ENV['RECAPTCHA_PRIVATE_KEY'] = nil
28
+ @controller.verify_recaptcha
29
+ end
30
+ end
31
+
32
+ def test_should_return_false_when_key_is_invalid
33
+ expect_http_post(response_with_body("false\ninvalid-site-private-key"))
34
+
35
+ assert !@controller.verify_recaptcha
36
+ assert_equal "invalid-site-private-key", @controller.session[:recaptcha_error]
37
+ end
38
+
39
+ def test_returns_true_on_success
40
+ @controller.session[:recaptcha_error] = "previous error that should be cleared"
41
+ expect_http_post(response_with_body("true\n"))
42
+
43
+ assert @controller.verify_recaptcha
44
+ assert_nil @controller.session[:recaptcha_error]
45
+ end
46
+
47
+ def test_errors_should_be_added_to_model
48
+ expect_http_post(response_with_body("false\nbad-news"))
49
+
50
+ errors = mock
51
+ errors.expects(:add).with(:base, "Captcha response is incorrect, please try again.")
52
+ model = mock(:valid? => false, :errors => errors)
53
+
54
+ assert !@controller.verify_recaptcha(:model => model)
55
+ assert_equal "bad-news", @controller.session[:recaptcha_error]
56
+ end
57
+
58
+ def test_returns_true_on_success_with_optional_key
59
+ @controller.session[:recaptcha_error] = "previous error that should be cleared"
60
+ # reset private key
61
+ @expected_post_data["privatekey"] = 'ADIFFERENTPRIVATEKEYXXXXXXXXXXXXXX'
62
+ expect_http_post(response_with_body("true\n"))
63
+
64
+ assert @controller.verify_recaptcha(:private_key => 'ADIFFERENTPRIVATEKEYXXXXXXXXXXXXXX')
65
+ assert_nil @controller.session[:recaptcha_error]
66
+ end
67
+
68
+ def test_timeout
69
+ expect_http_post(Timeout::Error, :exception => true)
70
+ assert !@controller.verify_recaptcha()
71
+ assert_equal "recaptcha-not-reachable", @controller.session[:recaptcha_error]
72
+ end
73
+
74
+ private
75
+
76
+ class TestController
77
+ include Recaptcha::Verify
78
+ attr_accessor :request, :params, :session
79
+
80
+ def initialize
81
+ @session = {}
82
+ end
83
+ end
84
+
85
+ def expect_http_post(response, options = {})
86
+ unless options[:exception]
87
+ Net::HTTP.expects(:post_form).with(@expected_uri, @expected_post_data).returns(response)
88
+ else
89
+ Net::HTTP.expects(:post_form).raises response
90
+ end
91
+ end
92
+
93
+ def response_with_body(body)
94
+ stub(:body => body)
95
+ end
96
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bcms_feedback_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Collis-Puro
@@ -20,7 +20,7 @@ executables: []
20
20
  extensions: []
21
21
 
22
22
  extra_rdoc_files:
23
- - README
23
+ - README.markdown
24
24
  files:
25
25
  - app/helpers/application_helper.rb
26
26
  - app/helpers/feedback_forms_helper.rb
@@ -40,7 +40,22 @@ files:
40
40
  - rails/init.rb
41
41
  - config/initializers/recaptcha.rb
42
42
  - public/bcms/feedback_form/README
43
- - README
43
+ - vendor/plugins/recaptcha/LICENSE
44
+ - vendor/plugins/recaptcha/lib/recaptcha.rb
45
+ - vendor/plugins/recaptcha/lib/recaptcha/verify.rb
46
+ - vendor/plugins/recaptcha/lib/recaptcha/merb.rb
47
+ - vendor/plugins/recaptcha/lib/recaptcha/rails.rb
48
+ - vendor/plugins/recaptcha/lib/recaptcha/client_helper.rb
49
+ - vendor/plugins/recaptcha/Rakefile
50
+ - vendor/plugins/recaptcha/test/verify_recaptcha_test.rb
51
+ - vendor/plugins/recaptcha/test/recaptcha_test.rb
52
+ - vendor/plugins/recaptcha/tasks/recaptcha_tasks.rake
53
+ - vendor/plugins/recaptcha/init.rb
54
+ - vendor/plugins/recaptcha/VERSION
55
+ - vendor/plugins/recaptcha/recaptcha.gemspec
56
+ - vendor/plugins/recaptcha/README.rdoc
57
+ - vendor/plugins/recaptcha/CHANGELOG
58
+ - README.markdown
44
59
  has_rdoc: true
45
60
  homepage: http://github.com/djcp/bcms_feedback_form
46
61
  licenses: []
data/README DELETED
@@ -1,2 +0,0 @@
1
- == bcms_feedback_form - A Feedback Form module for the BrowserCMS content management system.
2
-