lastobelus-merb-recaptcha 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +45 -0
- data/Rakefile +81 -0
- data/TODO +1 -0
- data/lib/merb-recaptcha.rb +30 -0
- data/lib/merb-recaptcha/constants.rb +7 -0
- data/lib/merb-recaptcha/controller_mixin.rb +47 -0
- data/lib/merb-recaptcha/exceptions.rb +30 -0
- data/lib/merb-recaptcha/merbtasks.rb +0 -0
- data/lib/merb-recaptcha/view_helpers.rb +117 -0
- data/merb-recaptcha.gemspec +44 -0
- data/spec/fixture/app/controllers/application.rb +2 -0
- data/spec/fixture/app/controllers/exceptions.rb +13 -0
- data/spec/fixture/app/controllers/recaptcha.rb +29 -0
- data/spec/fixture/app/helpers/global_helpers.rb +5 -0
- data/spec/fixture/app/helpers/recaptcha_helpers.rb +4 -0
- data/spec/fixture/app/views/exceptions/not_acceptable.html.erb +63 -0
- data/spec/fixture/app/views/exceptions/not_found.html.erb +47 -0
- data/spec/fixture/app/views/layout/application.html.erb +10 -0
- data/spec/fixture/app/views/recaptcha/ajax.html.erb +2 -0
- data/spec/fixture/app/views/recaptcha/ajax_with_callback.html.erb +2 -0
- data/spec/fixture/app/views/recaptcha/ajax_with_jquery.html.erb +2 -0
- data/spec/fixture/app/views/recaptcha/ajax_with_options.html.erb +2 -0
- data/spec/fixture/app/views/recaptcha/noajax_with_noscript.html.erb +1 -0
- data/spec/fixture/app/views/recaptcha/noajax_with_options.html.erb +1 -0
- data/spec/fixture/app/views/recaptcha/noajax_without_noscript.html.erb +1 -0
- data/spec/recaptcha_ajax_spec.rb +39 -0
- data/spec/recaptcha_ajax_with_callback_spec.rb +35 -0
- data/spec/recaptcha_ajax_with_jquery_spec.rb +39 -0
- data/spec/recaptcha_ajax_with_options_spec.rb +35 -0
- data/spec/recaptcha_noajax_with_noscript_spec.rb +59 -0
- data/spec/recaptcha_noajax_with_options_spec.rb +39 -0
- data/spec/recaptcha_noajax_without_noscript_spec.rb +39 -0
- data/spec/recaptcha_valid_spec.rb +125 -0
- data/spec/spec_helper.rb +46 -0
- metadata +152 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
class Recaptcha < Application
|
2
|
+
def ajax
|
3
|
+
render
|
4
|
+
end
|
5
|
+
|
6
|
+
def ajax_with_jquery
|
7
|
+
render
|
8
|
+
end
|
9
|
+
|
10
|
+
def ajax_with_callback
|
11
|
+
render
|
12
|
+
end
|
13
|
+
|
14
|
+
def ajax_with_options
|
15
|
+
render
|
16
|
+
end
|
17
|
+
|
18
|
+
def noajax_without_noscript
|
19
|
+
render
|
20
|
+
end
|
21
|
+
|
22
|
+
def noajax_with_noscript
|
23
|
+
render
|
24
|
+
end
|
25
|
+
|
26
|
+
def noajax_with_options
|
27
|
+
render
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
<div id="container">
|
2
|
+
<div id="header-container">
|
3
|
+
<img src="/images/merb.jpg" />
|
4
|
+
<!-- <h1>Mongrel + Erb</h1> -->
|
5
|
+
<h2>pocket rocket web framework</h2>
|
6
|
+
<hr />
|
7
|
+
</div>
|
8
|
+
|
9
|
+
<div id="left-container">
|
10
|
+
<h3>Exception:</h3>
|
11
|
+
<p><%= request.exceptions.first.message %></p>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div id="main-container">
|
15
|
+
<h3>Why am I seeing this page?</h3>
|
16
|
+
<p>Merb couldn't find an appropriate content_type to return,
|
17
|
+
based on what you said was available via provides() and
|
18
|
+
what the client requested.</p>
|
19
|
+
|
20
|
+
<h3>How to add a mime-type</h3>
|
21
|
+
<pre><code>
|
22
|
+
Merb.add_mime_type :pdf, :to_pdf, %w[application/pdf], "Content-Encoding" => "gzip"
|
23
|
+
</code></pre>
|
24
|
+
<h3>What this means is:</h3>
|
25
|
+
<ul>
|
26
|
+
<li>Add a mime-type for :pdf</li>
|
27
|
+
<li>Register the method for converting objects to PDF as <code>#to_pdf</code>.</li>
|
28
|
+
<li>Register the incoming mime-type "Accept" header as <code>application/pdf</code>.</li>
|
29
|
+
<li>Specify a new header for PDF types so it will set <code>Content-Encoding</code> to gzip.</li>
|
30
|
+
</ul>
|
31
|
+
|
32
|
+
<h3>You can then do:</h3>
|
33
|
+
<pre><code>
|
34
|
+
class Foo < Application
|
35
|
+
provides :pdf
|
36
|
+
end
|
37
|
+
</code></pre>
|
38
|
+
|
39
|
+
<h3>Where can I find help?</h3>
|
40
|
+
<p>If you have any questions or if you can't figure something out, please take a
|
41
|
+
look at our <a href="http://merbivore.com/"> project page</a>,
|
42
|
+
feel free to come chat at irc.freenode.net, channel #merb,
|
43
|
+
or post to <a href="http://groups.google.com/group/merb">merb mailing list</a>
|
44
|
+
on Google Groups.</p>
|
45
|
+
|
46
|
+
<h3>What if I've found a bug?</h3>
|
47
|
+
<p>If you want to file a bug or make your own contribution to Merb,
|
48
|
+
feel free to register and create a ticket at our
|
49
|
+
<a href="http://merb.lighthouseapp.com/">project development page</a>
|
50
|
+
on Lighthouse.</p>
|
51
|
+
|
52
|
+
<h3>How do I edit this page?</h3>
|
53
|
+
<p>You can change what people see when this happens by editing <tt>app/views/exceptions/not_acceptable.html.erb</tt>.</p>
|
54
|
+
|
55
|
+
</div>
|
56
|
+
|
57
|
+
<div id="footer-container">
|
58
|
+
<hr />
|
59
|
+
<div class="left"></div>
|
60
|
+
<div class="right">© 2008 the merb dev team</div>
|
61
|
+
<p> </p>
|
62
|
+
</div>
|
63
|
+
</div>
|
@@ -0,0 +1,47 @@
|
|
1
|
+
<div id="container">
|
2
|
+
<div id="header-container">
|
3
|
+
<img src="/images/merb.jpg" />
|
4
|
+
<!-- <h1>Mongrel + Erb</h1> -->
|
5
|
+
<h2>pocket rocket web framework</h2>
|
6
|
+
<hr />
|
7
|
+
</div>
|
8
|
+
|
9
|
+
<div id="left-container">
|
10
|
+
<h3>Exception:</h3>
|
11
|
+
<p><%= request.exceptions.first.message %></p>
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<div id="main-container">
|
15
|
+
<h3>Welcome to Merb!</h3>
|
16
|
+
<p>Merb is a light-weight MVC framework written in Ruby. We hope you enjoy it.</p>
|
17
|
+
|
18
|
+
<h3>Where can I find help?</h3>
|
19
|
+
<p>If you have any questions or if you can't figure something out, please take a
|
20
|
+
look at our <a href="http://merbivore.com/"> project page</a>,
|
21
|
+
feel free to come chat at irc.freenode.net, channel #merb,
|
22
|
+
or post to <a href="http://groups.google.com/group/merb">merb mailing list</a>
|
23
|
+
on Google Groups.</p>
|
24
|
+
|
25
|
+
<h3>What if I've found a bug?</h3>
|
26
|
+
<p>If you want to file a bug or make your own contribution to Merb,
|
27
|
+
feel free to register and create a ticket at our
|
28
|
+
<a href="http://merb.lighthouseapp.com/">project development page</a>
|
29
|
+
on Lighthouse.</p>
|
30
|
+
|
31
|
+
<h3>How do I edit this page?</h3>
|
32
|
+
<p>You're seeing this page because you need to edit the following files:
|
33
|
+
<ul>
|
34
|
+
<li>config/router.rb <strong><em>(recommended)</em></strong></li>
|
35
|
+
<li>app/views/exceptions/not_found.html.erb <strong><em>(recommended)</em></strong></li>
|
36
|
+
<li>app/views/layout/application.html.erb <strong><em>(change this layout)</em></strong></li>
|
37
|
+
</ul>
|
38
|
+
</p>
|
39
|
+
</div>
|
40
|
+
|
41
|
+
<div id="footer-container">
|
42
|
+
<hr />
|
43
|
+
<div class="left"></div>
|
44
|
+
<div class="right">© 2008 the merb dev team</div>
|
45
|
+
<p> </p>
|
46
|
+
</div>
|
47
|
+
</div>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
2
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us">
|
3
|
+
<head>
|
4
|
+
<title>Fresh Merb App</title>
|
5
|
+
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<%= catch_content :for_layout %>
|
9
|
+
</body>
|
10
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= recaptcha_tags :ajax => false, :noscript => true, :iframe_height => 250, :iframe_width => 250 %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= recaptcha_tags :ajax => false, :noscript => false, :theme => "clean", :tabindex => 2 %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= recaptcha_tags :ajax => false, :noscript => false %>
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "Recaptcha#ajax" do
|
4
|
+
describe "HTTP" do
|
5
|
+
before(:each) do
|
6
|
+
@response = dispatch_to(Recaptcha, "ajax")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should load script from api url" do
|
10
|
+
@response.should have_xpath("//script[@src='http://api.recaptcha.net/js/recaptcha_ajax.js']")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should invoke Recaptcha.create using onload event" do
|
14
|
+
@response.should have_xpath("//script[contains(., 'window.onload = function() { Recaptcha.create')]")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should send element_id ('recaptcha_without_callback')" do
|
18
|
+
@response.should have_xpath("//script[contains(., 'Recaptcha.create') and contains(., \"getElementById('recaptcha_without_callback')\")]")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should create empty options array" do
|
22
|
+
@response.should have_xpath("//script[contains(., 'Recaptcha.create') and contains(., 'var options = {};')]")
|
23
|
+
end
|
24
|
+
|
25
|
+
it_should_behave_like "ajax recaptcha"
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "HTTPS" do
|
29
|
+
before(:each) do
|
30
|
+
@response = dispatch_to(Recaptcha, "ajax", {}, { "HTTPS" => "on" })
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should load script from secure api url" do
|
34
|
+
@response.should have_xpath("//script[@src='https://api-secure.recaptcha.net/js/recaptcha_ajax.js']")
|
35
|
+
end
|
36
|
+
|
37
|
+
it_should_behave_like "ajax recaptcha"
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "Recaptcha#ajax_with_callback" do
|
4
|
+
describe "HTTP" do
|
5
|
+
before(:each) do
|
6
|
+
@response = dispatch_to(Recaptcha, "ajax_with_callback")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should load script from api url" do
|
10
|
+
@response.should have_xpath("//script[@src='http://api.recaptcha.net/js/recaptcha_ajax.js']")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should send element_id ('recaptcha_with_callback')" do
|
14
|
+
@response.should have_xpath("//script[contains(., 'Recaptcha.create') and contains(., \"getElementById('recaptcha_with_callback')\")]")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should create options array containing callback value ('test_callback')" do
|
18
|
+
@response.should have_xpath("//script[contains(., 'Recaptcha.create') and contains(., 'var options = {\"callback\": test_callback};')]")
|
19
|
+
end
|
20
|
+
|
21
|
+
it_should_behave_like "ajax recaptcha"
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "HTTPS" do
|
25
|
+
before(:each) do
|
26
|
+
@response = dispatch_to(Recaptcha, "ajax_with_callback", {}, { "HTTPS" => "on" })
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should load script from secure api url" do
|
30
|
+
@response.should have_xpath("//script[@src='https://api-secure.recaptcha.net/js/recaptcha_ajax.js']")
|
31
|
+
end
|
32
|
+
|
33
|
+
it_should_behave_like "ajax recaptcha"
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "Recaptcha#ajax_with_jquery" do
|
4
|
+
describe "HTTP" do
|
5
|
+
before(:each) do
|
6
|
+
@response = dispatch_to(Recaptcha, "ajax_with_jquery")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should load script from api url" do
|
10
|
+
@response.should have_xpath("//script[@src='http://api.recaptcha.net/js/recaptcha_ajax.js']")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should invoke Recaptcha.create using onload event" do
|
14
|
+
@response.should have_xpath("//script[contains(., '$(document).ready(function() { Recaptcha.create')]")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should send element_id ('recaptcha_without_callback')" do
|
18
|
+
@response.should have_xpath("//script[contains(., 'Recaptcha.create') and contains(., \"getElementById('recaptcha_without_callback')\")]")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should create empty options array" do
|
22
|
+
@response.should have_xpath("//script[contains(., 'Recaptcha.create') and contains(., 'var options = {};')]")
|
23
|
+
end
|
24
|
+
|
25
|
+
it_should_behave_like "ajax recaptcha"
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "HTTPS" do
|
29
|
+
before(:each) do
|
30
|
+
@response = dispatch_to(Recaptcha, "ajax_with_jquery", {}, { "HTTPS" => "on" })
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should load script from secure api url" do
|
34
|
+
@response.should have_xpath("//script[@src='https://api-secure.recaptcha.net/js/recaptcha_ajax.js']")
|
35
|
+
end
|
36
|
+
|
37
|
+
it_should_behave_like "ajax recaptcha"
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "Recaptcha#ajax_with_options" do
|
4
|
+
describe "HTTP" do
|
5
|
+
before(:each) do
|
6
|
+
@response = dispatch_to(Recaptcha, "ajax_with_options")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should load script from api url" do
|
10
|
+
@response.should have_xpath("//script[@src='http://api.recaptcha.net/js/recaptcha_ajax.js']")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should send element_id ('recaptcha_without_callback')" do
|
14
|
+
@response.should have_xpath("//script[contains(., 'Recaptcha.create') and contains(., \"getElementById('recaptcha_without_callback')\")]")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should create options array containing custom options (theme = 'clean', tabindex = 2)" do
|
18
|
+
@response.should have_xpath("//script[contains(., 'Recaptcha.create') and (contains(., 'var options = {\"theme\": \"clean\", \"tabindex\": 2};') or contains(., 'var options = {\"tabindex\": 2, \"theme\": \"clean\"};'))]")
|
19
|
+
end
|
20
|
+
|
21
|
+
it_should_behave_like "ajax recaptcha"
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "HTTPS" do
|
25
|
+
before(:each) do
|
26
|
+
@response = dispatch_to(Recaptcha, "ajax_with_options", {}, { "HTTPS" => "on" })
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should load script from secure api url" do
|
30
|
+
@response.should have_xpath("//script[@src='https://api-secure.recaptcha.net/js/recaptcha_ajax.js']")
|
31
|
+
end
|
32
|
+
|
33
|
+
it_should_behave_like "ajax recaptcha"
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "Recaptcha#noajax_with_noscript" do
|
4
|
+
describe "HTTP" do
|
5
|
+
before(:each) do
|
6
|
+
@response = dispatch_to(Recaptcha, "noajax_with_noscript")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should load script from api url" do
|
10
|
+
@response.should have_xpath("//script[@src='http://api.recaptcha.net/challenge?k=#{Merb::Plugins.config[:merb_recaptcha][:public_key]}']")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should not send private key to anything" do
|
14
|
+
@response.should_not have_xpath("//*[contains(., '#{Merb::Plugins.config[:merb_recaptcha][:private_key]}')]")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should not have RecaptchaOptions array initialization" do
|
18
|
+
@response.should_not have_xpath("//script[contains(., 'var RecaptchaOptions')]")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have noscript element" do
|
22
|
+
@response.should have_xpath("//noscript")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have iframe in noscript element" do
|
26
|
+
@response.should have_xpath("//noscript/iframe")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should have iframe with specified height and width (250x250)" do
|
30
|
+
@response.should have_xpath("//noscript/iframe[@height=250 and @width=250]")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should have br element in noscript element" do
|
34
|
+
@response.should have_xpath("//noscript/br")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should have textarea in noscript element" do
|
38
|
+
@response.should have_xpath("//noscript/textarea[@name='recaptcha_challenge_field']")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should have hidden input element in noscript element" do
|
42
|
+
@response.should have_xpath("//noscript/input[@name='recaptcha_response_field' and @type='hidden' and @value='manual_challenge']")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "HTTPS" do
|
47
|
+
before(:each) do
|
48
|
+
@response = dispatch_to(Recaptcha, "noajax_with_noscript", {}, { "HTTPS" => "on" })
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should load script from secure api url" do
|
52
|
+
@response.should have_xpath("//script[@src='https://api-secure.recaptcha.net/challenge?k=#{Merb::Plugins.config[:merb_recaptcha][:public_key]}']")
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should not send private key to anything" do
|
56
|
+
@response.should_not have_xpath("//*[contains(., '#{Merb::Plugins.config[:merb_recaptcha][:private_key]}')]")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "Recaptcha#noajax_with_options" do
|
4
|
+
describe "HTTP" do
|
5
|
+
before(:each) do
|
6
|
+
@response = dispatch_to(Recaptcha, "noajax_with_options")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should load script from api url" do
|
10
|
+
@response.should have_xpath("//script[@src='http://api.recaptcha.net/challenge?k=#{Merb::Plugins.config[:merb_recaptcha][:public_key]}']")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should not send private key to anything" do
|
14
|
+
@response.should_not have_xpath("//*[contains(., '#{Merb::Plugins.config[:merb_recaptcha][:private_key]}')]")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should not have noscript element" do
|
18
|
+
@response.should_not have_xpath("//noscript")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have RecaptchaOptions array intialization (theme = 'clean', tabindex = 2)" do
|
22
|
+
@response.should have_xpath("//script[contains(., 'var RecaptchaOptions = {\"theme\": \"clean\", \"tabindex\": 2};') or contains(., 'var RecaptchaOptions = {\"tabindex\": 2, \"theme\": \"clean\"};')]")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "HTTPS" do
|
27
|
+
before(:each) do
|
28
|
+
@response = dispatch_to(Recaptcha, "noajax_with_options", {}, { "HTTPS" => "on" })
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should load script from secure api url" do
|
32
|
+
@response.should have_xpath("//script[@src='https://api-secure.recaptcha.net/challenge?k=#{Merb::Plugins.config[:merb_recaptcha][:public_key]}']")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should not send private key to anything" do
|
36
|
+
@response.should_not have_xpath("//*[contains(., '#{Merb::Plugins.config[:merb_recaptcha][:private_key]}')]")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|