acts_as_textcaptcha 3.0.3 → 3.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml CHANGED
@@ -2,3 +2,4 @@ rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
4
  - ree
5
+ - rbx
data/README.rdoc CHANGED
@@ -172,8 +172,9 @@ What do you need?
172
172
  * {Rails}[http://github.com/rails/rails] >= 2.3.2 (including Rails 3)
173
173
  * {Ruby}[http://ruby-lang.org/] >= 1.8.7 (also tested with REE and Ruby 1.9.2)
174
174
  * {bcrypt-ruby}[http://bcrypt-ruby.rubyforge.org/] gem (to securely encrypt spam answers)
175
- * {Text CAPTCHA API key}[http://textcaptcha.com/register] (_optional_, since you can define your own logic questions, see below for details)
175
+ * {Text CAPTCHA API key}[http://textcaptcha.com/register] (_optional_, since you can define your own logic questions)
176
176
  * {MiniTest}[https://rubygems.org/gems/minitest] (_optional_ if you want to run the tests, built into Ruby 1.9)
177
+ * {SimpleCov}[https://rubygems.org/gems/simplecov] (_optional_ if you want to run the tests with code coverage reporting)
177
178
 
178
179
  == Links
179
180
 
@@ -92,12 +92,16 @@ module ActsAsTextcaptcha
92
92
  end
93
93
  end
94
94
 
95
- # fall back to textcaptcha_config questions
95
+ # fall back to textcaptcha_config questions if they are configured correctly
96
96
  if textcaptcha_config[:questions]
97
- random_question = textcaptcha_config[:questions][rand(textcaptcha_config[:questions].size)].symbolize_keys!
98
- self.spam_question = random_question[:question]
99
- self.spam_answers = encrypt_answers(random_question[:answers].split(',').map!{ |answer| md5_answer(answer) })
100
- else
97
+ random_question = textcaptcha_config[:questions][rand(textcaptcha_config[:questions].size)].symbolize_keys!
98
+ if random_question[:question] && random_question[:answers]
99
+ self.spam_question = random_question[:question]
100
+ self.spam_answers = encrypt_answers(random_question[:answers].split(',').map!{ |answer| md5_answer(answer) })
101
+ end
102
+ end
103
+
104
+ unless self.spam_question && self.spam_answers
101
105
  self.spam_question = 'ActsAsTextcaptcha >> no API key (or questions) set and/or the textcaptcha service is currently unavailable (answer ok to bypass)'
102
106
  self.spam_answers = 'ok'
103
107
  end
@@ -1,3 +1,3 @@
1
1
  module ActsAsTextcaptcha
2
- VERSION = "3.0.3"
2
+ VERSION = "3.0.4"
3
3
  end
data/test/schema.rb CHANGED
@@ -12,6 +12,10 @@ ActiveRecord::Schema.define(:version => 0) do
12
12
  t.string :name
13
13
  end
14
14
 
15
+ create_table :movie_reviews, :force => true do |t|
16
+ t.string :name
17
+ end
18
+
15
19
  create_table :notes, :force => true do |t|
16
20
  t.string :name
17
21
  end
data/test/test_models.rb CHANGED
@@ -20,6 +20,14 @@ class Review < ActiveRecord::Base
20
20
  'questions' => [{ 'question' => 'The green hat is what color?', 'answers' => 'green' }]
21
21
  end
22
22
 
23
+ class MovieReview < ActiveRecord::Base
24
+ # inline options with all possible options
25
+ acts_as_textcaptcha 'api_key' => '8u5ixtdnq9csc84cok0owswgo',
26
+ 'bcrypt_salt' => '$2a$10$j0bmycH.SVfD1b5mpEGPpe',
27
+ 'bcrypt_cost' => '3',
28
+ 'questions' => [{ 'Question' => 'The green hat is what color?', 'answers' => nil }]
29
+ end
30
+
23
31
  class Note < ActiveRecord::Base
24
32
  # inline options (string keys) with user defined questions only (no textcaptcha service)
25
33
  acts_as_textcaptcha 'questions' => [{ 'question' => '1+1', 'answers' => '2,two' }],
@@ -178,6 +178,15 @@ describe 'Textcaptcha' do
178
178
  @comment.spam_question.must_equal 'ActsAsTextcaptcha >> no API key (or questions) set and/or the textcaptcha service is currently unavailable (answer ok to bypass)'
179
179
  @comment.spam_answers.must_equal 'ok'
180
180
  end
181
+
182
+ it 'should not generate any spam question or answer when user defined questions set incorrectly' do
183
+ @comment = MovieReview.new
184
+
185
+ FakeWeb.register_uri(:get, %r|http://textcaptcha\.com/api/|, :exception => SocketError)
186
+ @comment.textcaptcha
187
+ @comment.spam_question.must_equal 'ActsAsTextcaptcha >> no API key (or questions) set and/or the textcaptcha service is currently unavailable (answer ok to bypass)'
188
+ @comment.spam_answers.must_equal 'ok'
189
+ end
181
190
  end
182
191
 
183
192
  describe 'configuration' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_textcaptcha
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-07 00:00:00.000000000 +01:00
13
- default_executable:
12
+ date: 2011-10-06 00:00:00.000000000Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: bcrypt-ruby
17
- requirement: &2168642840 !ruby/object:Gem::Requirement
16
+ requirement: &2165789020 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ~>
@@ -22,10 +21,10 @@ dependencies:
22
21
  version: 2.1.4
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *2168642840
24
+ version_requirements: *2165789020
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: rails
28
- requirement: &2168779000 !ruby/object:Gem::Requirement
27
+ requirement: &2165788600 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ! '>='
@@ -33,10 +32,10 @@ dependencies:
33
32
  version: '0'
34
33
  type: :development
35
34
  prerelease: false
36
- version_requirements: *2168779000
35
+ version_requirements: *2165788600
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: bundler
39
- requirement: &2168781360 !ruby/object:Gem::Requirement
38
+ requirement: &2165788140 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ! '>='
@@ -44,10 +43,10 @@ dependencies:
44
43
  version: '0'
45
44
  type: :development
46
45
  prerelease: false
47
- version_requirements: *2168781360
46
+ version_requirements: *2165788140
48
47
  - !ruby/object:Gem::Dependency
49
48
  name: minitest
50
- requirement: &2168783060 !ruby/object:Gem::Requirement
49
+ requirement: &2165787720 !ruby/object:Gem::Requirement
51
50
  none: false
52
51
  requirements:
53
52
  - - ! '>='
@@ -55,10 +54,10 @@ dependencies:
55
54
  version: '0'
56
55
  type: :development
57
56
  prerelease: false
58
- version_requirements: *2168783060
57
+ version_requirements: *2165787720
59
58
  - !ruby/object:Gem::Dependency
60
59
  name: simplecov
61
- requirement: &2168798920 !ruby/object:Gem::Requirement
60
+ requirement: &2165787300 !ruby/object:Gem::Requirement
62
61
  none: false
63
62
  requirements:
64
63
  - - ! '>='
@@ -66,10 +65,10 @@ dependencies:
66
65
  version: '0'
67
66
  type: :development
68
67
  prerelease: false
69
- version_requirements: *2168798920
68
+ version_requirements: *2165787300
70
69
  - !ruby/object:Gem::Dependency
71
70
  name: rdoc
72
- requirement: &2168801820 !ruby/object:Gem::Requirement
71
+ requirement: &2165786880 !ruby/object:Gem::Requirement
73
72
  none: false
74
73
  requirements:
75
74
  - - ! '>='
@@ -77,10 +76,10 @@ dependencies:
77
76
  version: '0'
78
77
  type: :development
79
78
  prerelease: false
80
- version_requirements: *2168801820
79
+ version_requirements: *2165786880
81
80
  - !ruby/object:Gem::Dependency
82
81
  name: sqlite3
83
- requirement: &2168797720 !ruby/object:Gem::Requirement
82
+ requirement: &2165786460 !ruby/object:Gem::Requirement
84
83
  none: false
85
84
  requirements:
86
85
  - - ! '>='
@@ -88,10 +87,10 @@ dependencies:
88
87
  version: '0'
89
88
  type: :development
90
89
  prerelease: false
91
- version_requirements: *2168797720
90
+ version_requirements: *2165786460
92
91
  - !ruby/object:Gem::Dependency
93
92
  name: fakeweb
94
- requirement: &2168797300 !ruby/object:Gem::Requirement
93
+ requirement: &2165786040 !ruby/object:Gem::Requirement
95
94
  none: false
96
95
  requirements:
97
96
  - - ! '>='
@@ -99,7 +98,7 @@ dependencies:
99
98
  version: '0'
100
99
  type: :development
101
100
  prerelease: false
102
- version_requirements: *2168797300
101
+ version_requirements: *2165786040
103
102
  description: ! "Simple question/answer based spam protection for your Rails models.\n
104
103
  \ You can define your own logic questions and/or fetch questions from the textcaptcha.com
105
104
  API.\n The questions involve human logic and are tough for spam bots to crack.\n
@@ -133,7 +132,6 @@ files:
133
132
  - test/test_models.rb
134
133
  - test/textcaptcha_helper_test.rb
135
134
  - test/textcaptcha_test.rb
136
- has_rdoc: true
137
135
  homepage: http://github.com/matthutchinson/acts_as_textcaptcha
138
136
  licenses: []
139
137
  post_install_message:
@@ -154,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
152
  version: '0'
155
153
  requirements: []
156
154
  rubyforge_project:
157
- rubygems_version: 1.6.2
155
+ rubygems_version: 1.8.7
158
156
  signing_key:
159
157
  specification_version: 3
160
158
  summary: Spam protection for your models via logic questions and the textcaptcha.com