validates_captcha 0.9.2 → 0.9.3
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/CHANGELOG.rdoc +6 -1
- data/README.rdoc +85 -49
- data/lib/validates_captcha.rb +18 -113
- data/lib/validates_captcha/form_builder.rb +4 -4
- data/lib/validates_captcha/form_helper.rb +13 -25
- data/lib/validates_captcha/image_generator/simple.rb +7 -6
- data/lib/validates_captcha/model_validation.rb +9 -9
- data/lib/validates_captcha/provider/image.rb +244 -0
- data/lib/validates_captcha/provider/question.rb +110 -0
- data/lib/validates_captcha/reversible_encrypter/simple.rb +3 -2
- data/lib/validates_captcha/string_generator/simple.rb +3 -2
- data/lib/validates_captcha/version.rb +1 -1
- data/rails/init.rb +1 -1
- data/test/cases/controller_validation_test.rb +79 -22
- data/test/cases/{image_generator_test.rb → image_generator/simple_test.rb} +11 -10
- data/test/cases/model_validation_test.rb +131 -58
- data/test/cases/provider/image_test.rb +103 -0
- data/test/cases/provider/question_test.rb +41 -0
- data/test/cases/{reversible_encrypter_test.rb → reversible_encrypter/simple_test.rb} +3 -2
- data/test/cases/{string_generator_test.rb → string_generator/simple_test.rb} +1 -0
- data/test/cases/validates_captcha_test.rb +9 -116
- metadata +17 -14
- data/lib/validates_captcha/middleware/simple.rb +0 -108
- data/test/cases/middleware_test.rb +0 -71
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
MW = ValidatesCaptcha::Middleware::Simple
|
4
|
-
|
5
|
-
class MiddlewareTest < ValidatesCaptcha::TestCase
|
6
|
-
test "defines an instance level #image_path method" do
|
7
|
-
assert_respond_to MW.new, :image_path
|
8
|
-
end
|
9
|
-
|
10
|
-
test "instance level #image_path method accepts an argument" do
|
11
|
-
assert_nothing_raised { MW.new.image_path('test') }
|
12
|
-
end
|
13
|
-
|
14
|
-
test "instance level #image_path method returns a string" do
|
15
|
-
assert_kind_of String, MW.new.image_path('test')
|
16
|
-
end
|
17
|
-
|
18
|
-
test "defines an instance level #regenerate_path method" do
|
19
|
-
assert_respond_to MW.new, :image_path
|
20
|
-
end
|
21
|
-
|
22
|
-
test "instance level #regenerate_path method returns a string" do
|
23
|
-
assert_kind_of String, MW.new.regenerate_path
|
24
|
-
end
|
25
|
-
|
26
|
-
test "calling middleware with unrecognized path should have response status 404" do
|
27
|
-
result = MW.new.call 'PATH_INFO' => '/unrecognized'
|
28
|
-
|
29
|
-
assert_equal 404, result.first
|
30
|
-
end
|
31
|
-
|
32
|
-
test "calling middleware with recognized path should not have response status 404" do
|
33
|
-
result = MW.new.call 'PATH_INFO' => ValidatesCaptcha.captcha_image_path('abc123')
|
34
|
-
|
35
|
-
assert_not_equal 404, result.first
|
36
|
-
end
|
37
|
-
|
38
|
-
test "calling middleware with valid encrypted captcha code should have response status 200" do
|
39
|
-
encrypted_code = ValidatesCaptcha.encrypt_captcha_code('hello')
|
40
|
-
result = MW.new.call 'PATH_INFO' => "/captchas/#{encrypted_code}"
|
41
|
-
|
42
|
-
assert_equal 200, result.first
|
43
|
-
end
|
44
|
-
|
45
|
-
test "calling middleware with valid encrypted captcha code should have expected content type response header" do
|
46
|
-
encrypted_code = ValidatesCaptcha.encrypt_captcha_code('hello')
|
47
|
-
result = MW.new.call 'PATH_INFO' => "/captchas/#{encrypted_code}"
|
48
|
-
|
49
|
-
assert result.second.key?('Content-Type')
|
50
|
-
assert_equal ValidatesCaptcha.captcha_image_mime_type, result.second['Content-Type']
|
51
|
-
end
|
52
|
-
|
53
|
-
test "calling middleware with invalid encrypted captcha code should have response status 422" do
|
54
|
-
result = MW.new.call 'PATH_INFO' => "/captchas/invalid123"
|
55
|
-
|
56
|
-
assert_equal 422, result.first
|
57
|
-
end
|
58
|
-
|
59
|
-
test "calling middleware with regenerate path should have response status 200" do
|
60
|
-
result = MW.new.call 'PATH_INFO' => ValidatesCaptcha.regenerate_captcha_path
|
61
|
-
|
62
|
-
assert_equal 200, result.first
|
63
|
-
end
|
64
|
-
|
65
|
-
test "calling middleware with regenerate path should have content type response header set to application/json" do
|
66
|
-
result = MW.new.call 'PATH_INFO' => ValidatesCaptcha.regenerate_captcha_path
|
67
|
-
|
68
|
-
assert result.second.key?('Content-Type')
|
69
|
-
assert_equal 'application/json', result.second['Content-Type']
|
70
|
-
end
|
71
|
-
end
|