simple_audio_captcha 1.0.0
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.
- checksums.yaml +7 -0
- data/.gitignore +35 -0
- data/.rspec +2 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +2 -0
- data/lib/generators/simple_audio_captcha_generator.rb +14 -0
- data/lib/generators/templates/partial.erb +45 -0
- data/lib/generators/templates/partial.haml +29 -0
- data/lib/simple_audio_captcha.rb +19 -0
- data/lib/simple_audio_captcha/audio_helpers.rb +25 -0
- data/lib/simple_audio_captcha/middleware.rb +69 -0
- data/lib/simple_audio_captcha/version.rb +3 -0
- data/lib/simple_audio_captcha/view.rb +41 -0
- data/lib/tasks/clean.rake +6 -0
- data/simple_audio_captcha.gemspec +32 -0
- data/spec/audio_helpers_spec.rb +21 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/view_spec.rb +47 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8b2d01e6335009965998805d8700036e77b0e4d1
|
4
|
+
data.tar.gz: 8c902b8cea8f550f6dccd4f4647def903fe43d5c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6fbc38dfc9e15763f7a9db3355c761af3736ed9ea5b65310fa9e59c4f052d84a75faedcbbd00b80bfa7edd3474420bc7c9ddfa9dedea7d10883f10422ad749b2
|
7
|
+
data.tar.gz: 2d83043b3098d12c565ea457e436200edfd22c77ffe7a65dc1791c1a708ff6a096cf75ff2622aa81a29dc55f3da122ef38071a13a853732bc12e559b67b56138
|
data/.gitignore
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
# Gemfile.lock
|
31
|
+
# .ruby-version
|
32
|
+
# .ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Aditya Kapoor
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# SimpleAudioCaptcha
|
2
|
+
|
3
|
+
Simple audio support for the `simple_captcha`.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'simple_audio_captcha'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install simple_audio_captcha
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Use ```rails g simple_audio_captcha [templatetype]``` to generate the default template with audio support and overwrite the existing simple captcha template.
|
24
|
+
|
25
|
+
Simple Captcha Audio Utilises Espeak to produce audio. The Espeak configuration for voice, pitch and speed can be added to simple captcha:
|
26
|
+
|
27
|
+
```
|
28
|
+
SimpleCaptcha.setup do |simple_captcha|
|
29
|
+
simple_captcha.voice = 'en'
|
30
|
+
simple_captcha.speed = 100
|
31
|
+
simple_captcha.pitch = 100
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
See espeak documentation for further details for these parameters.
|
36
|
+
|
37
|
+
## Requirements
|
38
|
+
* Ruby >= 1.9.3
|
39
|
+
* Rails >= 3.2
|
40
|
+
* You need to install `espeak` and `lame` system libraries which would help you in the text to speech conversion and exporting the audio to the `mp3` format.
|
41
|
+
|
42
|
+
You can install them on OSX from homebrew:
|
43
|
+
|
44
|
+
```
|
45
|
+
brew install espeak lame
|
46
|
+
```
|
47
|
+
|
48
|
+
or on a linux based system from your package manager.
|
49
|
+
|
50
|
+
## Contributing
|
51
|
+
|
52
|
+
1. Fork it ( https://github.com/[my-github-username]/simple_audio_captcha/fork )
|
53
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
54
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
55
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
56
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
class SimpleAudioCaptchaGenerator < Rails::Generators::Base
|
4
|
+
argument :template_format, :type => :string, :default => 'erb'
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
|
7
|
+
def self.source_root
|
8
|
+
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates/'))
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_partial
|
12
|
+
template "partial.#{template_format}", File.join('app/views', 'simple_captcha', "_simple_captcha.#{template_format}")
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
<style type="text/css">
|
2
|
+
.simple_captcha{border: 1px solid #ccc; padding: 5px !important;}
|
3
|
+
.simple_captcha,
|
4
|
+
.simple_captcha div{display: table;}
|
5
|
+
.simple_captcha .simple_captcha_field,
|
6
|
+
.simple_captcha .simple_captcha_image{
|
7
|
+
border: 1px solid #ccc;
|
8
|
+
margin: 0px 0px 2px 0px !important;
|
9
|
+
padding: 0px !important;
|
10
|
+
}
|
11
|
+
.simple_captcha .simple_captcha_image img{
|
12
|
+
margin: 0px !important;
|
13
|
+
padding: 0px !important;
|
14
|
+
width: 110px !important;
|
15
|
+
}
|
16
|
+
.simple_captcha .simple_captcha_label{font-size: 12px;}
|
17
|
+
.simple_captcha .simple_captcha_field input{
|
18
|
+
width: 150px !important;
|
19
|
+
font-size: 16px;
|
20
|
+
border: none;
|
21
|
+
background-color: #efefef;
|
22
|
+
}
|
23
|
+
</style>
|
24
|
+
|
25
|
+
<div class='simple_captcha'>
|
26
|
+
<div class='simple_captcha_image'>
|
27
|
+
<%%= simple_captcha_options[:image] %>
|
28
|
+
</div>
|
29
|
+
|
30
|
+
<div class='simple_audio_captcha'>
|
31
|
+
<%%= simple_captcha_options[:audio] %>
|
32
|
+
</div>
|
33
|
+
|
34
|
+
<div class='simple_captcha_field'>
|
35
|
+
<%%= simple_captcha_options[:field] %>
|
36
|
+
</div>
|
37
|
+
|
38
|
+
<div class='simple_captcha_label'>
|
39
|
+
<%%= simple_captcha_options[:label] %>
|
40
|
+
</div>
|
41
|
+
|
42
|
+
<div class='simple_captcha_refresh_button'>
|
43
|
+
<%%= simple_captcha_options[:refresh_button] %>
|
44
|
+
</div>
|
45
|
+
</div>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
:css
|
2
|
+
.simple_captcha{border: 1px solid #ccc; padding: 5px !important;}
|
3
|
+
.simple_captcha,
|
4
|
+
.simple_captcha div{display: table;}
|
5
|
+
.simple_captcha .simple_captcha_field,
|
6
|
+
.simple_captcha .simple_captcha_image{
|
7
|
+
border: 1px solid #ccc;
|
8
|
+
margin: 0px 0px 2px 0px !important;
|
9
|
+
padding: 0px !important;
|
10
|
+
}
|
11
|
+
.simple_captcha .simple_captcha_image img{
|
12
|
+
margin: 0px !important;
|
13
|
+
padding: 0px !important;
|
14
|
+
width: 110px !important;
|
15
|
+
}
|
16
|
+
.simple_captcha .simple_captcha_label{font-size: 12px;}
|
17
|
+
.simple_captcha .simple_captcha_field input{
|
18
|
+
width: 150px !important;
|
19
|
+
font-size: 16px;
|
20
|
+
border: none;
|
21
|
+
background-color: #efefef;
|
22
|
+
}
|
23
|
+
|
24
|
+
.simple_captcha
|
25
|
+
.simple_captcha_image= simple_captcha_options[:image]
|
26
|
+
.simple_audio_captcha= simple_captcha_options[:audio]
|
27
|
+
.simple_captcha_field= simple_captcha_options[:field]
|
28
|
+
.simple_captcha_label= simple_captcha_options[:label]
|
29
|
+
.simple_captcha_refresh_button= simple_captcha_options[:refresh_button]
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'simple_audio_captcha/version'
|
2
|
+
|
3
|
+
module SimpleCaptcha
|
4
|
+
autoload :AudioHelpers, 'simple_audio_captcha/audio_helpers'
|
5
|
+
|
6
|
+
# Espeak Configuration
|
7
|
+
mattr_accessor :voice
|
8
|
+
@@voice = 'en'
|
9
|
+
|
10
|
+
mattr_accessor :pitch
|
11
|
+
@@pitch = 50
|
12
|
+
|
13
|
+
mattr_accessor :speed
|
14
|
+
@@speed = 170
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'simple_audio_captcha/middleware'
|
19
|
+
require 'simple_audio_captcha/view'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'espeak'
|
2
|
+
|
3
|
+
module SimpleCaptcha
|
4
|
+
module AudioHelpers
|
5
|
+
include ESpeak
|
6
|
+
|
7
|
+
def generate_simple_audio_captcha(simple_captcha_key)
|
8
|
+
captcha_value = Utils::simple_captcha_value(simple_captcha_key)
|
9
|
+
make_audio_from_captcha(captcha_value)
|
10
|
+
end
|
11
|
+
|
12
|
+
def make_audio_from_captcha(captcha_str)
|
13
|
+
audio = make_audio_from_char(captcha_str.chars.first)
|
14
|
+
captcha_str.chars.drop(1).inject(audio) { |audio_accumalator, char| audio_accumalator << make_audio_from_char(char) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def make_audio_from_char(char)
|
18
|
+
Speech.new(char,
|
19
|
+
voice: SimpleCaptcha.voice,
|
20
|
+
pitch: SimpleCaptcha.pitch,
|
21
|
+
speed: SimpleCaptcha.speed).bytes.force_encoding('ASCII-8BIT')
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module SimpleCaptcha
|
2
|
+
class Middleware
|
3
|
+
include SimpleCaptcha::AudioHelpers
|
4
|
+
|
5
|
+
def call(env) # :nodoc:
|
6
|
+
if env["REQUEST_METHOD"] == "GET" && captcha_path?(env['PATH_INFO'])
|
7
|
+
request = Rack::Request.new(env)
|
8
|
+
if request.params.present? && request.params['code'].present?
|
9
|
+
if request.params['audio'] && request.params['audio'].eql?('true')
|
10
|
+
make_audio(env)
|
11
|
+
else
|
12
|
+
make_image(env)
|
13
|
+
end
|
14
|
+
else
|
15
|
+
refresh_code(env)
|
16
|
+
end
|
17
|
+
else
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
def make_audio(env, headers = {}, status = 404)
|
24
|
+
request = Rack::Request.new(env)
|
25
|
+
code = request.params["code"]
|
26
|
+
body = []
|
27
|
+
|
28
|
+
if Utils::simple_captcha_value(code)
|
29
|
+
#status, headers, body = @app.call(env)
|
30
|
+
#status = 200
|
31
|
+
#body = generate_simple_audio_captcha(code)
|
32
|
+
#headers['Content-Type'] = 'audio/mpeg3'
|
33
|
+
send_data(generate_simple_audio_captcha(code), type: 'audio/mpeg3', disposition: 'inline', filename: 'simple_audio_captcha.mp3', stream: 'true', buffer_size: '4096')
|
34
|
+
else
|
35
|
+
[status, headers, body]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def refresh_code(env)
|
40
|
+
request = Rack::Request.new(env)
|
41
|
+
|
42
|
+
request.session.delete :captcha
|
43
|
+
key = simple_captcha_key(nil, request)
|
44
|
+
options = {}
|
45
|
+
options[:field_value] = set_simple_captcha_data(key, options)
|
46
|
+
url = simple_captcha_image_url(key, options)
|
47
|
+
|
48
|
+
status = 200
|
49
|
+
id = request.params['id']
|
50
|
+
captcha_hidden_field_id = simple_captch_hidden_field_id(id)
|
51
|
+
|
52
|
+
audio_id = generate_audio_id(id)
|
53
|
+
audio_url = simple_audio_captcha_url(key, options)
|
54
|
+
|
55
|
+
body = %Q{
|
56
|
+
$("##{id}").attr('src', '#{url}');
|
57
|
+
$("##{audio_id}").attr('src', '#{audio_url}')
|
58
|
+
$("##{ captcha_hidden_field_id }").attr('value', '#{key}');
|
59
|
+
}
|
60
|
+
headers = {'Content-Type' => 'text/javascript; charset=utf-8', "Content-Disposition" => "inline; filename='captcha.js'", "Content-Length" => body.length.to_s}.merge(SimpleCaptcha.extra_response_headers)
|
61
|
+
[status, headers, [body]]
|
62
|
+
end
|
63
|
+
|
64
|
+
def generate_audio_id(id)
|
65
|
+
return '' if id.nil?
|
66
|
+
id.gsub('simple_captcha', simple_captcha_id_prefix)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module SimpleCaptcha
|
2
|
+
module ViewHelper
|
3
|
+
# TODO: Devise some way to use super here..
|
4
|
+
alias_method :__simple_captcha_options__, :simple_captcha_options
|
5
|
+
|
6
|
+
def simple_captcha_options(options = {})
|
7
|
+
super_options = __simple_captcha_options__(options)
|
8
|
+
|
9
|
+
key = super_options[:field_value]
|
10
|
+
|
11
|
+
super_options.merge({
|
12
|
+
audio: simple_audio_captcha(key, options)
|
13
|
+
})
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def simple_audio_captcha(simple_captcha_key, options = {})
|
18
|
+
url = simple_audio_captcha_url simple_captcha_key, options
|
19
|
+
id = simple_audio_captcha_id(options)
|
20
|
+
tag('audio', :src => url, :id => id, controls: true)
|
21
|
+
end
|
22
|
+
|
23
|
+
def simple_audio_captcha_url(simple_captcha_key, options = {})
|
24
|
+
defaults = {}
|
25
|
+
defaults[:time] = options[:time] || Time.now.to_i
|
26
|
+
|
27
|
+
query = defaults.to_query
|
28
|
+
path = "/simple_captcha?code=#{simple_captcha_key}&#{query}&audio=true"
|
29
|
+
|
30
|
+
build_url(options, path)
|
31
|
+
end
|
32
|
+
|
33
|
+
def simple_audio_captcha_id(options={})
|
34
|
+
"#{ simple_captcha_id_prefix }-#{options[:field_value][0..10]}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def simple_captcha_id_prefix
|
38
|
+
"simple_captcha-audio"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'simple_audio_captcha/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "simple_audio_captcha"
|
8
|
+
spec.version = SimpleAudioCaptcha::VERSION
|
9
|
+
spec.authors = ["Aditya Kapoor, Nimish Mehta"]
|
10
|
+
spec.email = ["adityakapoor.mait@gmail.com", "nimish@vinsol.com"]
|
11
|
+
spec.summary = "Simple Audio Extension to Simple Captcha"
|
12
|
+
spec.description = "adds audio support to simple captcha"
|
13
|
+
spec.homepage = "https://github.com/vinsol/simple-audio-captcha"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
if spec.respond_to?(:metadata)
|
22
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
23
|
+
else
|
24
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", '~> 1.6'
|
28
|
+
spec.add_development_dependency "rake", '~> 10.0'
|
29
|
+
spec.add_development_dependency "rspec", '~> 3.3.0'
|
30
|
+
spec.add_dependency "simple_captcha2", '~> 0.3.4'
|
31
|
+
spec.add_dependency "espeak-ruby", '~> 1.0.2'
|
32
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'simple_captcha/utils'
|
3
|
+
require 'simple_audio_captcha/audio_helpers'
|
4
|
+
|
5
|
+
class TestAudioHelper
|
6
|
+
include SimpleCaptcha::AudioHelpers
|
7
|
+
end
|
8
|
+
|
9
|
+
describe SimpleCaptcha::AudioHelpers do
|
10
|
+
let(:audio_helper_object) { TestAudioHelper.new }
|
11
|
+
|
12
|
+
context 'Constants' do
|
13
|
+
it { expect(SimpleCaptcha::AudioHelpers::TMP_FILES_PATH).to eq 'tmp/simple_captcha' }
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'Instance Methods' do
|
17
|
+
context '#generate_simple_audio_captcha' do
|
18
|
+
pending 'TODO: Write without too much mocks and stubs.'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/view_spec.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'active_support/core_ext/hash'
|
3
|
+
require 'action_view'
|
4
|
+
require 'simple_captcha/view'
|
5
|
+
require 'simple_audio_captcha'
|
6
|
+
|
7
|
+
class TestView < ActionView::Base
|
8
|
+
include SimpleCaptcha::ViewHelper
|
9
|
+
end
|
10
|
+
|
11
|
+
describe SimpleCaptcha::ViewHelper do
|
12
|
+
let(:view_helper_object) { TestView.new }
|
13
|
+
let(:field_value) { '1234567890' }
|
14
|
+
let(:now) { 1440753157 }
|
15
|
+
|
16
|
+
context 'Instance Methods' do
|
17
|
+
context 'simple_captcha_options' do
|
18
|
+
before do
|
19
|
+
expect(view_helper_object).to receive(:__simple_captcha_options__).and_return({})
|
20
|
+
allow(Time.now).to receive(:to_i).and_return(1440753157)
|
21
|
+
end
|
22
|
+
it { expect(view_helper_object.simple_captcha_options(field_value: field_value).keys).to include :audio }
|
23
|
+
it 'generates html audio tag' do
|
24
|
+
expect(view_helper_object.simple_captcha_options(field_value: field_value)[:audio].to_str.start_with?('<audio')).to eq(true)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context '#simple_audio_captcha_id' do
|
29
|
+
it { expect(view_helper_object.send(:simple_audio_captcha_id, field_value: field_value)).to eq "simple_captcha-audio-#{ field_value }" }
|
30
|
+
end
|
31
|
+
|
32
|
+
context '#simple_captcha_id_prefix' do
|
33
|
+
it { expect(view_helper_object.send(:simple_captcha_id_prefix)).to eq 'simple_captcha-audio' }
|
34
|
+
end
|
35
|
+
|
36
|
+
context '#simple_audio_captcha_url' do
|
37
|
+
it { expect(view_helper_object.send(:simple_audio_captcha_url, 'some_dummy_id', time: now)).to eq "/simple_captcha?code=some_dummy_id&time=#{ now }&audio=true" }
|
38
|
+
end
|
39
|
+
|
40
|
+
context '#simple_audio_captcha' do
|
41
|
+
it {
|
42
|
+
expect(view_helper_object.send(:simple_audio_captcha, 'some_dummy_id', time: now, field_value: field_value))
|
43
|
+
.to eq "<audio controls=\"controls\" id=\"simple_captcha-audio-1234567890\" src=\"/simple_captcha?code=some_dummy_id&time=#{ now }&audio=true\" />"
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_audio_captcha
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aditya Kapoor, Nimish Mehta
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.3.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.3.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simple_captcha2
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.3.4
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.3.4
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: espeak-ruby
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.0.2
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.0.2
|
83
|
+
description: adds audio support to simple captcha
|
84
|
+
email:
|
85
|
+
- adityakapoor.mait@gmail.com
|
86
|
+
- nimish@vinsol.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- CHANGELOG.md
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- lib/generators/simple_audio_captcha_generator.rb
|
100
|
+
- lib/generators/templates/partial.erb
|
101
|
+
- lib/generators/templates/partial.haml
|
102
|
+
- lib/simple_audio_captcha.rb
|
103
|
+
- lib/simple_audio_captcha/audio_helpers.rb
|
104
|
+
- lib/simple_audio_captcha/middleware.rb
|
105
|
+
- lib/simple_audio_captcha/version.rb
|
106
|
+
- lib/simple_audio_captcha/view.rb
|
107
|
+
- lib/tasks/clean.rake
|
108
|
+
- simple_audio_captcha.gemspec
|
109
|
+
- spec/audio_helpers_spec.rb
|
110
|
+
- spec/spec_helper.rb
|
111
|
+
- spec/view_spec.rb
|
112
|
+
homepage: https://github.com/vinsol/simple-audio-captcha
|
113
|
+
licenses:
|
114
|
+
- MIT
|
115
|
+
metadata:
|
116
|
+
allowed_push_host: https://rubygems.org
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 2.2.3
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: Simple Audio Extension to Simple Captcha
|
137
|
+
test_files:
|
138
|
+
- spec/audio_helpers_spec.rb
|
139
|
+
- spec/spec_helper.rb
|
140
|
+
- spec/view_spec.rb
|
141
|
+
has_rdoc:
|