traptcha 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,16 +17,15 @@ module Traptcha
17
17
  end
18
18
 
19
19
  class << self
20
- def generate
21
- new generate_random_captcha
22
- end
20
+ def generate(options = {})
21
+ options.reverse_merge! :valid_chars => Traptcha.valid_chars - Traptcha.ignored_chars,
22
+ :length => Traptcha.default_length
23
23
 
24
- def generate_random_captcha
25
- 3.times.map { valid_chars[rand(valid_chars.length)] }.to_s
24
+ new generate_random_captcha(options)
26
25
  end
27
26
 
28
- def valid_chars
29
- Traptcha.valid_chars - Traptcha.ignored_chars
27
+ def generate_random_captcha(options = {})
28
+ options[:length].times.map { options[:valid_chars][rand(options[:valid_chars].length)] }.to_s
30
29
  end
31
30
  end
32
31
  end
@@ -1,3 +1,3 @@
1
1
  module Traptcha
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/traptcha.rb CHANGED
@@ -17,6 +17,9 @@ module Traptcha
17
17
  autoload :ViewHelpers, 'traptcha/view_helpers'
18
18
  autoload :InvalidCaptcha, 'traptcha/invalid_captcha'
19
19
 
20
+ mattr_accessor :default_length
21
+ @@default_length = 3
22
+
20
23
  mattr_accessor :valid_chars
21
24
  @@valid_chars = ('a'..'z').to_a + (0..9).map(&:to_s).to_a
22
25
 
@@ -0,0 +1,33 @@
1
+ require "spec_helper"
2
+
3
+ describe Traptcha::Captcha do
4
+ describe ".generate" do
5
+ context "when no options are informed" do
6
+ subject { described_class.generate }
7
+
8
+ it "generates a new captcha with the default valid chars" do
9
+ subject.text.chars.all? { |char| Traptcha.valid_chars.include? char }.should be_true
10
+ end
11
+
12
+ it "generates a new captcha with the default length" do
13
+ subject.text.size.should == 3
14
+ end
15
+ end
16
+
17
+ context "informing the valid chars" do
18
+ subject { described_class.generate :valid_chars => %w(a) }
19
+
20
+ it "generates a new captcha with the informed chars" do
21
+ subject.text.chars.all? { |char| char == "a" }.should be_true
22
+ end
23
+ end
24
+
25
+ context "informing the length of 2 chars" do
26
+ subject { described_class.generate :length => 2 }
27
+
28
+ it "generates a new captcha with 2 chars" do
29
+ subject.text.size.should == 2
30
+ end
31
+ end
32
+ end
33
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traptcha
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rodrigo Navarro
@@ -15,13 +15,14 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-20 00:00:00 -03:00
18
+ date: 2011-08-04 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: rmagick
23
22
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
23
+ type: :runtime
24
+ name: rmagick
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
26
  none: false
26
27
  requirements:
27
28
  - - ">="
@@ -30,12 +31,12 @@ dependencies:
30
31
  segments:
31
32
  - 0
32
33
  version: "0"
33
- type: :runtime
34
- version_requirements: *id001
34
+ requirement: *id001
35
35
  - !ruby/object:Gem::Dependency
36
- name: rspec
37
36
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
37
+ type: :development
38
+ name: rspec
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
40
  none: false
40
41
  requirements:
41
42
  - - ~>
@@ -46,8 +47,7 @@ dependencies:
46
47
  - 5
47
48
  - 0
48
49
  version: 2.5.0
49
- type: :development
50
- version_requirements: *id002
50
+ requirement: *id002
51
51
  description: Captcha generator for rails
52
52
  email:
53
53
  - reu@rnavarro.com.br
@@ -74,6 +74,7 @@ files:
74
74
  - lib/traptcha/view_helpers.rb
75
75
  - lib/traptcha/wave_image.rb
76
76
  - spec/spec_helper.rb
77
+ - spec/traptcha/captcha_spec.rb
77
78
  - spec/traptcha/image_spec.rb
78
79
  - spec/traptcha/wave_image_spec.rb
79
80
  - traptcha.gemspec
@@ -113,5 +114,6 @@ specification_version: 3
113
114
  summary: Simple captcha for rails
114
115
  test_files:
115
116
  - spec/spec_helper.rb
117
+ - spec/traptcha/captcha_spec.rb
116
118
  - spec/traptcha/image_spec.rb
117
119
  - spec/traptcha/wave_image_spec.rb