acts_as_textcaptcha 2.1.3 → 2.1.4

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.
@@ -21,7 +21,7 @@ Here's a {fully working demo on heroku}[http://textcaptcha.heroku.com]!
21
21
  What do you need?
22
22
 
23
23
  * {Rails}[http://github.com/rails/rails] >= 2.3.x (including Rails 3)
24
- * {Ruby}[http://ruby-lang.org/] >= 1.8.7
24
+ * {Ruby}[http://ruby-lang.org/] >= 1.8.7 (also tested with REE and Ruby 1.9.2)
25
25
  * {bcrypt-ruby}[http://bcrypt-ruby.rubyforge.org/] gem (to securely encrypt the spam answers in your session)
26
26
  * {Text CAPTCHA api key}[http://textcaptcha.com/register] (_optional_, since you can define your own logic questions, see below for details)
27
27
  * {Rspec}[http://rspec.info/] (_optional_ if you want to run the tests)
@@ -45,8 +45,9 @@ module ActsAsTextcaptcha
45
45
  # if returning false model.validate will always be false with errors on base
46
46
  def allowed?; true end
47
47
 
48
- def validate_textcaptcha
49
- if new_record?
48
+ def validate_textcaptcha
49
+ # if not new_record? we dont spam check on existing records (ie. no spam check on updates/edits)
50
+ if !respond_to?('new_record?') || new_record?
50
51
  if allowed?
51
52
  if possible_answers && perform_spam_check? && !validate_spam_answer
52
53
  errors.add(:spam_answer, 'is incorrect, try another question instead')
@@ -23,6 +23,14 @@ end
23
23
  class Note < ActiveRecord::Base
24
24
  # inline options with user defined questions only (no textcaptcha service)
25
25
  acts_as_textcaptcha('questions' => [{'question' => '1+1', 'answers' => '2,two'}])
26
+ end
27
+
28
+ class Contact
29
+ # non active record object
30
+ include ActiveModel::Validations
31
+ include ActiveModel::Conversion
32
+ extend ActsAsTextcaptcha::Textcaptcha
33
+ acts_as_textcaptcha('questions' => [{'question' => '1+1', 'answers' => '2,two'}])
26
34
  end
27
35
 
28
36
 
@@ -31,7 +39,8 @@ describe 'ActsAsTextcaptcha' do
31
39
  before(:each) do
32
40
  @comment = Comment.new
33
41
  @review = Review.new
34
- @note = Note.new
42
+ @note = Note.new
43
+ @contact = Contact.new
35
44
  end
36
45
 
37
46
  describe 'validations' do
@@ -40,6 +49,17 @@ describe 'ActsAsTextcaptcha' do
40
49
  @note.generate_spam_question
41
50
  @note.validate_textcaptcha.should be_false
42
51
  @note.should_not be_valid
52
+ end
53
+
54
+ it "should validate non ActiveRecord object" do
55
+ @contact.generate_spam_question
56
+ @contact.spam_answer = 'wrong'
57
+ @contact.validate_textcaptcha.should be_false
58
+ @contact.should_not be_valid
59
+
60
+ @contact.spam_answer = 'two'
61
+ @contact.validate_textcaptcha.should be_true
62
+ @contact.should be_valid
43
63
  end
44
64
 
45
65
  it 'should validate spam answer with possible answers' do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_textcaptcha
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 1
9
- - 3
10
- version: 2.1.3
9
+ - 4
10
+ version: 2.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matthew Hutchinson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-02 00:00:00 +01:00
18
+ date: 2010-09-17 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency