validates_captcha 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,98 +6,99 @@ class DynamicImageTest < ValidatesCaptcha::TestCase
6
6
  test "defines a class level #string_generator method" do
7
7
  assert_respond_to IMAGE, :string_generator
8
8
  end
9
-
9
+
10
10
  test "defines a class level #string_generator= method" do
11
11
  assert_respond_to IMAGE, :string_generator=
12
12
  end
13
-
13
+
14
14
  test "#string_generator method's return value should equal the value set using the #string_generator= method" do
15
15
  old_string_generator = IMAGE.string_generator
16
-
16
+
17
17
  IMAGE.string_generator = 'abc'
18
18
  assert_equal 'abc', IMAGE.string_generator
19
-
19
+
20
20
  IMAGE.string_generator = old_string_generator
21
21
  end
22
-
22
+
23
23
  test "defines a class level #symmetric_encryptor method" do
24
24
  assert_respond_to IMAGE, :symmetric_encryptor
25
25
  end
26
-
26
+
27
27
  test "defines a class level #symmetric_encryptor= method" do
28
28
  assert_respond_to IMAGE, :symmetric_encryptor=
29
29
  end
30
-
30
+
31
31
  test "#symmetric_encryptor method's return value should equal the value set using the #symmetric_encryptor= method" do
32
32
  old_symmetric_encryptor = IMAGE.symmetric_encryptor
33
-
33
+
34
34
  IMAGE.symmetric_encryptor = 'abc'
35
35
  assert_equal 'abc', IMAGE.symmetric_encryptor
36
-
36
+
37
37
  IMAGE.symmetric_encryptor = old_symmetric_encryptor
38
38
  end
39
-
39
+
40
40
  test "defines a class level #image_generator method" do
41
41
  assert_respond_to IMAGE, :image_generator
42
42
  end
43
-
43
+
44
44
  test "defines a class level #image_generator= method" do
45
45
  assert_respond_to IMAGE, :image_generator=
46
46
  end
47
-
47
+
48
48
  test "#image_generator method's return value should equal the value set using the #image_generator= method" do
49
49
  old_image_generator = IMAGE.image_generator
50
-
50
+
51
51
  IMAGE.image_generator = 'abc'
52
52
  assert_equal 'abc', IMAGE.image_generator
53
-
53
+
54
54
  IMAGE.image_generator = old_image_generator
55
55
  end
56
-
56
+
57
57
  test "calling #call with unrecognized path should have response status 404" do
58
58
  result = IMAGE.new.call 'PATH_INFO' => '/unrecognized'
59
-
59
+
60
60
  assert_equal 404, result.first
61
61
  end
62
-
62
+
63
63
  test "calling #call with recognized path should not have response status 404" do
64
64
  result = IMAGE.new.call 'PATH_INFO' => IMAGE.new.send(:image_path, 'abc123')
65
-
65
+
66
66
  assert_not_equal 404, result.first
67
67
  end
68
-
68
+
69
69
  test "calling #call with valid encrypted captcha code should have response status 200" do
70
70
  encrypted_code = IMAGE.new.generate_challenge
71
71
  result = IMAGE.new.call 'PATH_INFO' => "/captchas/#{encrypted_code}"
72
-
72
+
73
73
  assert_equal 200, result.first
74
74
  end
75
-
75
+
76
76
  test "calling #call with valid encrypted captcha code should have expected content type response header" do
77
77
  encrypted_code = IMAGE.new.generate_challenge
78
78
  result = IMAGE.new.call 'PATH_INFO' => "/captchas/#{encrypted_code}"
79
-
79
+
80
80
  assert result.second.key?('Content-Type')
81
81
  assert_equal IMAGE.image_generator.mime_type, result.second['Content-Type']
82
82
  end
83
-
83
+
84
84
  test "calling #call with invalid encrypted captcha code should have response status 422" do
85
85
  encrypted_code = IMAGE.new.generate_challenge.reverse
86
86
  result = IMAGE.new.call 'PATH_INFO' => "/captchas/#{encrypted_code}"
87
-
87
+
88
88
  assert_equal 422, result.first
89
89
  end
90
-
90
+
91
91
  test "calling #call with regenerate path should have response status 200" do
92
92
  result = IMAGE.new.call 'PATH_INFO' => IMAGE.new.send(:regenerate_path)
93
-
93
+
94
94
  assert_equal 200, result.first
95
95
  end
96
-
96
+
97
97
  test "calling #call with regenerate path should have content type response header set to application/json" do
98
98
  result = IMAGE.new.call 'PATH_INFO' => IMAGE.new.send(:regenerate_path)
99
-
99
+
100
100
  assert result.second.key?('Content-Type')
101
101
  assert_equal 'application/json', result.second['Content-Type']
102
102
  end
103
103
  end
104
+
@@ -6,36 +6,37 @@ class QuestionTest < ValidatesCaptcha::TestCase
6
6
  test "defines a class level #questions_and_answers method" do
7
7
  assert_respond_to QUESTION, :questions_and_answers
8
8
  end
9
-
9
+
10
10
  test "defines a class level #questions_and_answers= method" do
11
11
  assert_respond_to QUESTION, :questions_and_answers=
12
12
  end
13
-
13
+
14
14
  test "#questions_and_answers method's return value should equal the value set using the #questions_and_answers= method" do
15
15
  old_questions_and_answers = QUESTION.questions_and_answers
16
-
16
+
17
17
  QUESTION.questions_and_answers = 'abc'
18
18
  assert_equal 'abc', QUESTION.questions_and_answers
19
-
19
+
20
20
  QUESTION.questions_and_answers = old_questions_and_answers
21
21
  end
22
-
22
+
23
23
  test "calling #call with unrecognized path should have response status 404" do
24
24
  result = QUESTION.new.call 'PATH_INFO' => '/unrecognized'
25
-
25
+
26
26
  assert_equal 404, result.first
27
27
  end
28
-
28
+
29
29
  test "calling #call with regenerate path should have response status 200" do
30
30
  result = QUESTION.new.call 'PATH_INFO' => QUESTION.new.send(:regenerate_path)
31
-
31
+
32
32
  assert_equal 200, result.first
33
33
  end
34
-
34
+
35
35
  test "calling #call with regenerate path should have content type response header set to application/json" do
36
36
  result = QUESTION.new.call 'PATH_INFO' => QUESTION.new.send(:regenerate_path)
37
-
37
+
38
38
  assert result.second.key?('Content-Type')
39
39
  assert_equal 'application/json', result.second['Content-Type']
40
40
  end
41
41
  end
42
+
@@ -14,135 +14,136 @@ class StaticImageTest < ValidatesCaptcha::TestCase
14
14
  test "defines a class level #string_generator method" do
15
15
  assert_respond_to STATIC_IMAGE, :string_generator
16
16
  end
17
-
17
+
18
18
  test "defines a class level #string_generator= method" do
19
19
  assert_respond_to STATIC_IMAGE, :string_generator=
20
20
  end
21
-
21
+
22
22
  test "#string_generator method's return value should equal the value set using the #string_generator= method" do
23
23
  old_string_generator = STATIC_IMAGE.string_generator
24
-
24
+
25
25
  STATIC_IMAGE.string_generator = 'abc'
26
26
  assert_equal 'abc', STATIC_IMAGE.string_generator
27
-
27
+
28
28
  STATIC_IMAGE.string_generator = old_string_generator
29
29
  end
30
-
30
+
31
31
  test "defines a class level #image_generator method" do
32
32
  assert_respond_to STATIC_IMAGE, :image_generator
33
33
  end
34
-
34
+
35
35
  test "defines a class level #image_generator= method" do
36
36
  assert_respond_to STATIC_IMAGE, :image_generator=
37
37
  end
38
-
38
+
39
39
  test "#image_generator method's return value should equal the value set using the #image_generator= method" do
40
40
  old_image_generator = STATIC_IMAGE.image_generator
41
-
41
+
42
42
  STATIC_IMAGE.image_generator = 'abc'
43
43
  assert_equal 'abc', STATIC_IMAGE.image_generator
44
-
44
+
45
45
  STATIC_IMAGE.image_generator = old_image_generator
46
46
  end
47
-
47
+
48
48
  test "defines a class level #salt method" do
49
49
  assert_respond_to STATIC_IMAGE, :salt
50
50
  end
51
-
51
+
52
52
  test "defines a class level #salt= method" do
53
53
  assert_respond_to STATIC_IMAGE, :salt=
54
54
  end
55
-
55
+
56
56
  test "#salt method's return value should equal the value set using the #salt= method" do
57
57
  old_salt = STATIC_IMAGE.salt
58
-
58
+
59
59
  STATIC_IMAGE.salt = 'abc'
60
60
  assert_equal 'abc', STATIC_IMAGE.salt
61
-
61
+
62
62
  STATIC_IMAGE.salt = old_salt
63
63
  end
64
-
64
+
65
65
  test "defines a class level #filesystem_dir method" do
66
66
  assert_respond_to STATIC_IMAGE, :filesystem_dir
67
67
  end
68
-
68
+
69
69
  test "defines a class level #filesystem_dir= method" do
70
70
  assert_respond_to STATIC_IMAGE, :filesystem_dir=
71
71
  end
72
-
72
+
73
73
  test "#filesystem_dir method's return value should equal the value set using the #filesystem_dir= method" do
74
74
  old_filesystem_dir = STATIC_IMAGE.filesystem_dir
75
-
75
+
76
76
  STATIC_IMAGE.filesystem_dir = 'abc'
77
77
  assert_equal 'abc', STATIC_IMAGE.filesystem_dir
78
-
78
+
79
79
  STATIC_IMAGE.filesystem_dir = old_filesystem_dir
80
80
  end
81
-
81
+
82
82
  test "defines a class level #web_dir method" do
83
83
  assert_respond_to STATIC_IMAGE, :web_dir
84
84
  end
85
-
85
+
86
86
  test "defines a class level #web_dir= method" do
87
87
  assert_respond_to STATIC_IMAGE, :web_dir=
88
88
  end
89
-
89
+
90
90
  test "#web_dir method's return value should equal the value set using the #web_dir= method" do
91
91
  old_web_dir = STATIC_IMAGE.web_dir
92
-
92
+
93
93
  STATIC_IMAGE.web_dir = 'abc'
94
94
  assert_equal 'abc', STATIC_IMAGE.web_dir
95
-
95
+
96
96
  STATIC_IMAGE.web_dir = old_web_dir
97
97
  end
98
-
98
+
99
99
  test "calling #call with unrecognized path should have response status 404" do
100
100
  result = STATIC_IMAGE.new.call 'PATH_INFO' => '/unrecognized'
101
-
101
+
102
102
  assert_equal 404, result.first
103
103
  end
104
-
104
+
105
105
  test "calling #call with regenerate path should have response status 200" do
106
106
  si = STATIC_IMAGE.new
107
107
  si.instance_variable_set "@challenges", ['abc']
108
-
108
+
109
109
  result = si.call 'PATH_INFO' => si.send(:regenerate_path)
110
-
110
+
111
111
  assert_equal 200, result.first
112
112
  end
113
-
113
+
114
114
  test "calling #call with regenerate path should have content type response header set to application/json" do
115
115
  si = STATIC_IMAGE.new
116
116
  si.instance_variable_set "@challenges", ['abc']
117
-
117
+
118
118
  result = si.call 'PATH_INFO' => si.send(:regenerate_path)
119
-
119
+
120
120
  assert result.second.key?('Content-Type')
121
121
  assert_equal 'application/json', result.second['Content-Type']
122
122
  end
123
-
123
+
124
124
  test "calling #generate_challenge should raise runtime error if no images are available" do
125
125
  si = STATIC_IMAGE.new
126
126
  si.instance_variable_set "@images", []
127
-
127
+
128
128
  assert_raises RuntimeError do
129
129
  si.generate_challenge
130
130
  end
131
131
  end
132
-
132
+
133
133
  test "calling #generate_challenge should not raise runtime error if an images is available" do
134
134
  si = STATIC_IMAGE.new
135
135
  si.instance_variable_set "@images", ['/path/to/an/image.gif']
136
-
136
+
137
137
  assert_nothing_raised do
138
138
  si.generate_challenge
139
139
  end
140
- end
141
-
140
+ end
141
+
142
142
  test "calling #generate_challenge should return the image file basename without extension" do
143
143
  si = STATIC_IMAGE.new
144
144
  si.instance_variable_set "@images", ["/path/to/an/captcha-image#{si.send(:image_file_extension)}"]
145
-
145
+
146
146
  assert_equal 'captcha-image', si.generate_challenge
147
147
  end
148
148
  end
149
+
@@ -6,110 +6,110 @@ class StringGeneratorTest < ValidatesCaptcha::TestCase
6
6
  test "defines a class level #alphabet method" do
7
7
  assert_respond_to SG, :alphabet
8
8
  end
9
-
9
+
10
10
  test "class level #alphabet method returns a string" do
11
11
  assert_kind_of String, SG.alphabet
12
12
  assert_greater_than 0, SG.alphabet.length
13
13
  end
14
-
14
+
15
15
  test "defines a class level #alphabet= method" do
16
16
  assert_respond_to SG, :alphabet=
17
17
  end
18
-
18
+
19
19
  test "#alphabet method's return value should equal the value set using the #alphabet= method" do
20
20
  old_alphabet = SG.alphabet
21
-
21
+
22
22
  SG.alphabet = 'abc'
23
23
  assert_equal 'abc', SG.alphabet
24
-
24
+
25
25
  SG.alphabet = old_alphabet
26
26
  end
27
-
27
+
28
28
  test "#alphabet= method converts supplied value to a string" do
29
29
  old_alphabet = SG.alphabet
30
-
31
- [:abc, 123, %w(x y z)].each do |value|
30
+
31
+ [:abc, 123, %w(x y z)].each do |value|
32
32
  SG.alphabet = value
33
33
  assert_equal value.to_s, SG.alphabet
34
34
  end
35
-
35
+
36
36
  SG.alphabet = old_alphabet
37
37
  end
38
-
38
+
39
39
  test "#alphabet= method removes whitespace from supplied value" do
40
40
  old_alphabet = SG.alphabet
41
-
41
+
42
42
  SG.alphabet = " abc d ef\n"
43
43
  assert_equal "abcdef", SG.alphabet
44
-
44
+
45
45
  SG.alphabet = old_alphabet
46
46
  end
47
-
47
+
48
48
  test "#alphabet= method raises error if supplied value is blank" do
49
49
  assert_raise RuntimeError do
50
50
  SG.alphabet = ''
51
51
  end
52
52
  end
53
-
53
+
54
54
  test "defines a class level #length method" do
55
55
  assert_respond_to SG, :length
56
56
  end
57
-
57
+
58
58
  test "class level #length method returns a number" do
59
59
  assert_kind_of Fixnum, SG.length
60
60
  end
61
-
61
+
62
62
  test "defines a class level #length= method" do
63
63
  assert_respond_to SG, :length=
64
64
  end
65
-
65
+
66
66
  test "#length method's return value should equal the value set using the #length= method" do
67
67
  old_length = SG.length
68
-
68
+
69
69
  SG.length = 42
70
70
  assert_equal 42, SG.length
71
-
71
+
72
72
  SG.length = old_length
73
73
  end
74
74
 
75
75
  test "defines an instance level #generate method" do
76
76
  assert_respond_to SG.new, :generate
77
77
  end
78
-
78
+
79
79
  test "instance level #generate method returns a string" do
80
80
  assert_kind_of String, SG.new.generate
81
81
  end
82
-
82
+
83
83
  test "calling #generate should return a string of #length size" do
84
84
  10.times do
85
85
  assert_equal SG.length, SG.new.generate.length
86
86
  end
87
87
  end
88
-
88
+
89
89
  test "calling #generate with custom set #length should return a string of #length size" do
90
90
  old_length = SG.length
91
91
  SG.length = 42
92
-
92
+
93
93
  10.times do
94
94
  assert_equal 42, SG.new.generate.length
95
95
  end
96
-
96
+
97
97
  SG.length = old_length
98
98
  end
99
-
99
+
100
100
  test "string returned from #generate should only contain chars from #alphabet" do
101
101
  old_alphabet = SG.alphabet
102
102
  old_length = SG.length
103
-
103
+
104
104
  SG.alphabet = 'Abc123'
105
105
  SG.length = 1000
106
106
  generated = SG.new.generate
107
-
107
+
108
108
  assert generated.tr('Abc123', ' ').blank?
109
109
  assert !generated.tr('abc123', ' ').blank?
110
-
110
+
111
111
  SG.length = old_length
112
- SG.alphabet = old_alphabet
112
+ SG.alphabet = old_alphabet
113
113
  end
114
114
  end
115
115