[DRE-commits] [ruby-recaptcha] 01/03: Imported Upstream version 0.3.6
David Martínez
ender at moszumanska.debian.org
Thu Jan 9 07:38:13 UTC 2014
This is an automated email from the git hooks/post-receive script.
ender pushed a commit to branch master
in repository ruby-recaptcha.
commit 9d6b81fbb27f87ba07dc9a8a2cae8bdfc4a87df3
Author: David Martínez Moreno <ender at debian.org>
Date: Wed Jan 8 01:30:33 2014 -0800
Imported Upstream version 0.3.6
---
.gitignore | 3 +++
CHANGELOG | 7 ++++++-
Gemfile | 2 +-
README.rdoc | 25 +++++++++++++------------
VERSION | 1 -
lib/recaptcha.rb | 3 ++-
lib/recaptcha/client_helper.rb | 20 ++++++++++++++++++--
lib/recaptcha/configuration.rb | 7 +++++--
lib/recaptcha/version.rb | 2 +-
test/recaptcha_test.rb | 12 +++++++++++-
test/verify_recaptcha_test.rb | 2 +-
11 files changed, 61 insertions(+), 23 deletions(-)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0c8ab5e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+rdoc
+pkg
+Gemfile.lock
diff --git a/CHANGELOG b/CHANGELOG
index 101a5d3..9e20eb9 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,8 @@
+== 0.3.5 / 2012-05-02
+
+* I18n for error messages
+* Rails: delete flash keys if unused
+
== 0.3.4 / 2011-12-13
* Rails 3
@@ -25,4 +30,4 @@
== 0.1.0 / 2008-2-8
* 1 major enhancement
- * Initial Gem Release
\ No newline at end of file
+ * Initial Gem Release
diff --git a/Gemfile b/Gemfile
index d65e2a6..fa75df1 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,3 +1,3 @@
-source 'http://rubygems.org'
+source 'https://rubygems.org'
gemspec
diff --git a/README.rdoc b/README.rdoc
index 20817ba..fefb307 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -1,10 +1,9 @@
= reCAPTCHA
Author:: Jason L Perry (http://ambethia.com)
-Copyright:: Copyright (c) 2007 Jason L Perry
+Copyright:: Copyright (c) 2007-2013 Jason L Perry
License:: {MIT}[http://creativecommons.org/licenses/MIT/]
-Info:: http://ambethia.com/recaptcha
-Git:: http://github.com/ambethia/recaptcha/tree/master
+Info:: http://github.com/ambethia/recaptcha
Bugs:: http://github.com/ambethia/recaptcha/issues
This plugin adds helpers for the {reCAPTCHA API}[http://recaptcha.net]. In your
@@ -15,12 +14,6 @@ Beforehand you need to configure Recaptcha with your custom private and public
key. You may find detailed examples below. Exceptions will be raised if you
call these methods and the keys can't be found.
-== About this fork
-
-This fork tries to introduce a more convenient way to configure recaptcha's
-settings. The API will be inspired by {Thoughtbot's
-Hoptoad}[http://robots.thoughtbot.com/post/344833329/mygem-configure-block].
-
== Rails Installation
reCAPTCHA for Rails > 3.0, add this to your Gemfile:
@@ -82,7 +75,15 @@ reCAPTCHA setups.
== To use 'recaptcha'
-Add +recaptcha_tags+ to each form you want to protect.
+Add +recaptcha_tags+ to each form you want to protect. Place it where you want the recaptcha widget to appear.
+
+Example:
+
+ <%= form_for @foo do |f| %>
+ # ... additional lines truncated for brevity ...
+ <%= recaptcha_tags %>
+ # ... additional lines truncated for brevity ...
+ <% end %>
And, add +verify_recaptcha+ logic to each form action that you've protected.
@@ -90,7 +91,7 @@ And, add +verify_recaptcha+ logic to each form action that you've protected.
Some of the options available:
-<tt>:ssl</tt>:: Uses secure http for captcha widget (default +false+)
+<tt>:ssl</tt>:: Uses secure http for captcha widget (default +false+, but can be changed by setting +config.use_ssl_by_default+)
<tt>:noscript</tt>:: Include <noscript> content (default +true+)
<tt>:display</tt>:: Takes a hash containing the +theme+ and +tabindex+ options per the API. (default +nil+), options: 'red', 'white', 'blackglass', 'clean', 'custom'
<tt>:ajax</tt>:: Render the dynamic AJAX captcha per the API. (default +false+)
@@ -129,7 +130,7 @@ to translate the default error message if I18n is available. To customize the me
add these keys to your I18n backend:
<tt>recaptcha.errors.verification_failed</tt>:: error message displayed if the captcha words didn't match
-<tt>recaptcha.errors.recaptcha_unavailable</tt>:: displayed if a timout error occured while attempting to verify the captcha
+<tt>recaptcha.errors.recaptcha_unreachable</tt>:: displayed if a timeout error occured while attempting to verify the captcha
Also you can translate API response errors to human friendly by adding translations to the locale (+config/locales/en.yml+):
diff --git a/VERSION b/VERSION
deleted file mode 100644
index d15723f..0000000
--- a/VERSION
+++ /dev/null
@@ -1 +0,0 @@
-0.3.2
diff --git a/lib/recaptcha.rb b/lib/recaptcha.rb
index d3e4480..d3f30d7 100644
--- a/lib/recaptcha.rb
+++ b/lib/recaptcha.rb
@@ -3,9 +3,10 @@ require 'recaptcha/client_helper'
require 'recaptcha/verify'
module Recaptcha
- RECAPTCHA_API_SERVER_URL = 'http://www.google.com/recaptcha/api'
+ RECAPTCHA_API_SERVER_URL = '//www.google.com/recaptcha/api'
RECAPTCHA_API_SECURE_SERVER_URL = 'https://www.google.com/recaptcha/api'
RECAPTCHA_VERIFY_URL = 'http://www.google.com/recaptcha/api/verify'
+ USE_SSL_BY_DEFAULT = false
HANDLE_TIMEOUTS_GRACEFULLY = true
SKIP_VERIFY_ENV = ['test', 'cucumber']
diff --git a/lib/recaptcha/client_helper.rb b/lib/recaptcha/client_helper.rb
index 467eea2..f6e4038 100644
--- a/lib/recaptcha/client_helper.rb
+++ b/lib/recaptcha/client_helper.rb
@@ -12,7 +12,7 @@ module Recaptcha
html = ""
if options[:display]
html << %{<script type="text/javascript">\n}
- html << %{ var RecaptchaOptions = #{options[:display].to_json};\n}
+ html << %{ var RecaptchaOptions = #{hash_to_json(options[:display])};\n}
html << %{</script>\n}
end
if options[:ajax]
@@ -49,5 +49,21 @@ module Recaptcha
end
return (html.respond_to?(:html_safe) && html.html_safe) || html
end # recaptcha_tags
+
+ private
+
+ def hash_to_json(hash)
+ result = "{"
+ result << hash.map do |k, v|
+ if v.is_a?(Hash)
+ "\"#{k}\": #{hash_to_json(v)}"
+ elsif ! v.is_a?(String) || k.to_s == "callback"
+ "\"#{k}\": #{v}"
+ else
+ "\"#{k}\": \"#{v}\""
+ end
+ end.join(", ")
+ result << "}"
+ end
end # ClientHelper
-end # Recaptcha
\ No newline at end of file
+end # Recaptcha
diff --git a/lib/recaptcha/configuration.rb b/lib/recaptcha/configuration.rb
index d9fd4c3..6c76ef7 100644
--- a/lib/recaptcha/configuration.rb
+++ b/lib/recaptcha/configuration.rb
@@ -35,7 +35,8 @@ module Recaptcha
:private_key,
:public_key,
:proxy,
- :handle_timeouts_gracefully
+ :handle_timeouts_gracefully,
+ :use_ssl_by_default
def initialize #:nodoc:
@nonssl_api_server_url = RECAPTCHA_API_SERVER_URL
@@ -43,12 +44,14 @@ module Recaptcha
@verify_url = RECAPTCHA_VERIFY_URL
@skip_verify_env = SKIP_VERIFY_ENV
@handle_timeouts_gracefully = HANDLE_TIMEOUTS_GRACEFULLY
+ @use_ssl_by_default = USE_SSL_BY_DEFAULT
@private_key = ENV['RECAPTCHA_PRIVATE_KEY']
@public_key = ENV['RECAPTCHA_PUBLIC_KEY']
end
- def api_server_url(ssl = false) #:nodoc:
+ def api_server_url(ssl = nil) #:nodoc:
+ ssl = use_ssl_by_default if ssl.nil?
ssl ? ssl_api_server_url : nonssl_api_server_url
end
end
diff --git a/lib/recaptcha/version.rb b/lib/recaptcha/version.rb
index 0440751..0fa6af6 100644
--- a/lib/recaptcha/version.rb
+++ b/lib/recaptcha/version.rb
@@ -1,3 +1,3 @@
module Recaptcha
- VERSION = "0.3.4"
+ VERSION = "0.3.6"
end
diff --git a/test/recaptcha_test.rb b/test/recaptcha_test.rb
index edcbf6c..052e5da 100644
--- a/test/recaptcha_test.rb
+++ b/test/recaptcha_test.rb
@@ -19,7 +19,17 @@ class RecaptchaClientHelperTest < Test::Unit::TestCase
def test_recaptcha_tags
# Might as well match something...
- assert_match /http:\/\/www.google.com\/recaptcha\/api\/challenge/, recaptcha_tags
+ assert_match /"\/\/www.google.com\/recaptcha\/api\/challenge/, recaptcha_tags
+ end
+
+ def test_ssl_by_default
+ Recaptcha.configuration.use_ssl_by_default = true
+ assert_match /https:\/\/www.google.com\/recaptcha\/api\/challenge/, recaptcha_tags
+ end
+
+ def test_relative_protocol_by_default_without_ssl
+ Recaptcha.configuration.use_ssl_by_default = false
+ assert_match /\/\/www.google.com\/recaptcha\/api\/challenge/, recaptcha_tags(:ssl => false)
end
def test_recaptcha_tags_with_ssl
diff --git a/test/verify_recaptcha_test.rb b/test/verify_recaptcha_test.rb
index 3ae7023..afe1906 100644
--- a/test/verify_recaptcha_test.rb
+++ b/test/verify_recaptcha_test.rb
@@ -4,7 +4,7 @@ require 'test/unit'
require 'rubygems'
require 'active_support'
require 'active_support/core_ext/string'
-require 'mocha'
+require 'mocha/setup'
require 'i18n'
require 'net/http'
require File.dirname(File.expand_path(__FILE__)) + '/../lib/recaptcha'
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-recaptcha.git
More information about the Pkg-ruby-extras-commits
mailing list