ankh 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/.gitignore +18 -0
  2. data/{spec/spec.opts → .rspec} +0 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +4 -2
  6. data/README.rdoc +15 -5
  7. data/Rakefile +6 -84
  8. data/ankh.gemspec +20 -67
  9. data/lib/..rb +5 -0
  10. data/lib/ankh.rb +4 -6
  11. data/lib/ankh/model.rb +18 -10
  12. data/lib/ankh/question.rb +1 -1
  13. data/lib/ankh/railtie.rb +8 -0
  14. data/lib/ankh/validations/{human.rb → human_validator.rb} +0 -12
  15. data/lib/ankh/version.rb +3 -0
  16. data/spec/ankh/model_spec.rb +10 -7
  17. data/spec/dummy/Rakefile +7 -0
  18. data/spec/dummy/api_docs/api_authentication.markdown +70 -0
  19. data/spec/dummy/api_docs/api_user_creates_user.markdown +1170 -0
  20. data/spec/dummy/api_docs/partner_creation.markdown +78 -0
  21. data/spec/dummy/api_docs/topic_creation.markdown +76 -0
  22. data/spec/dummy/api_docs/user_creation.markdown +31 -0
  23. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  24. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  25. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  26. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  27. data/{features/step_definitions/ankh_steps.rb → spec/dummy/app/mailers/.gitkeep} +0 -0
  28. data/spec/dummy/app/models/.gitkeep +0 -0
  29. data/spec/dummy/app/views/devise/confirmations/new.html.erb +15 -0
  30. data/spec/dummy/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  31. data/spec/dummy/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  32. data/spec/dummy/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  33. data/spec/dummy/app/views/devise/passwords/edit.html.erb +19 -0
  34. data/spec/dummy/app/views/devise/passwords/new.html.erb +15 -0
  35. data/spec/dummy/app/views/devise/registrations/edit.html.erb +22 -0
  36. data/spec/dummy/app/views/devise/registrations/new.html.erb +20 -0
  37. data/spec/dummy/app/views/devise/sessions/new.html.erb +15 -0
  38. data/spec/dummy/app/views/devise/sessions/new.mobile.erb +14 -0
  39. data/spec/dummy/app/views/devise/shared/_links.erb +25 -0
  40. data/spec/dummy/app/views/devise/unlocks/new.html.erb +15 -0
  41. data/spec/dummy/config.ru +4 -0
  42. data/spec/dummy/config/application.rb +45 -0
  43. data/spec/dummy/config/boot.rb +10 -0
  44. data/spec/dummy/config/database.yml +20 -0
  45. data/spec/dummy/config/environment.rb +5 -0
  46. data/spec/dummy/config/environments/development.rb +30 -0
  47. data/spec/dummy/config/environments/production.rb +60 -0
  48. data/spec/dummy/config/environments/test.rb +39 -0
  49. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  50. data/spec/dummy/config/initializers/inflections.rb +10 -0
  51. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  52. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  53. data/spec/dummy/config/initializers/session_store.rb +8 -0
  54. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  55. data/spec/dummy/config/locales/en.yml +5 -0
  56. data/spec/dummy/config/routes.rb +3 -0
  57. data/spec/dummy/db/development.sqlite3 +0 -0
  58. data/spec/dummy/db/schema.rb +188 -0
  59. data/spec/dummy/db/test.sqlite3 +0 -0
  60. data/spec/dummy/lib/assets/.gitkeep +0 -0
  61. data/spec/dummy/public/404.html +26 -0
  62. data/spec/dummy/public/422.html +26 -0
  63. data/spec/dummy/public/500.html +26 -0
  64. data/spec/dummy/public/favicon.ico +0 -0
  65. data/spec/dummy/script/rails +6 -0
  66. data/spec/spec_helper.rb +10 -14
  67. metadata +205 -130
  68. data/features/ankh.feature +0 -9
  69. data/features/support/env.rb +0 -4
  70. data/lib/ankh/rails/legacy.rb +0 -41
  71. data/spec/support/active_record_spec_helper.rb +0 -44
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ spec/dummy/log/*
File without changes
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use default@ankh --create
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ..gemspec
4
+ gemspec
data/LICENSE CHANGED
@@ -1,4 +1,6 @@
1
- Copyright (c) 2009 Dan Pickett
1
+ Copyright (c) 2011 Dan Pickett
2
+
3
+ MIT License
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
@@ -17,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -2,12 +2,23 @@
2
2
 
3
3
  Ankh is the ancient Egyptian sign of life.
4
4
 
5
- Use Ankh in your Rails (2.3.x or 3.0) projects to protect against bots and other spam producers. It asks a simple
5
+ Use Ankh in your Rails (>= 3.0) projects to protect against bots and other spam producers. It asks a simple
6
6
  arithmatic question to verify that the poster is human.
7
7
 
8
- In your model:
8
+ In your activerecord model:
9
9
 
10
- validates_human :on => :create
10
+ class Post < ActiveRecord::Base
11
+ validates_human :on => :create
12
+ end
13
+
14
+ Ankh is also available for ActiveModel objects:
15
+
16
+ class Foo
17
+ include ActiveModel::Validations
18
+ extend Ankh::Model
19
+ validates_human :on => :create
20
+ end
21
+
11
22
 
12
23
  In your view (Rails 2 syntax shown below):
13
24
 
@@ -22,7 +33,6 @@ In your view (Rails 2 syntax shown below):
22
33
 
23
34
  * Nice form helpers
24
35
  * I18n support
25
- * automated testing of Rails 2.3.x vs. 3.0
26
36
 
27
37
  == Note on Patches/Pull Requests
28
38
 
@@ -36,4 +46,4 @@ In your view (Rails 2 syntax shown below):
36
46
 
37
47
  == Copyright
38
48
 
39
- Copyright (c) 2010 Dan Pickett. See LICENSE for details.
49
+ Copyright (c) 2011 Dan Pickett. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,91 +1,13 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
3
 
4
4
  begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "ankh"
8
- gem.summary = %Q{Protect against bots and other spam producers with simple mathematical questions}
9
- gem.description = %Q{Use Ankh in your Rails (2.3.x or 3.0) projects to protect against bots and other spam producers. It asks a simple
10
- arithmatic question to verify that the poster is human.}
11
- gem.email = "dpickett@enlightsolutions.com"
12
- gem.homepage = "http://github.com/dpickett/ankh"
13
- gem.authors = ["Dan Pickett"]
14
- gem.add_dependency "activerecord", ">= 2.3.4"
15
- gem.add_dependency "activesupport", ">= 2.3.4"
16
- gem.add_dependency "configatron", "2.6.3"
17
- gem.add_development_dependency "rspec", ">= 1.2.9"
18
- # gem.add_development_dependency "yard", ">= 0"
19
- gem.add_development_dependency "cucumber", ">= 0"
20
- gem.add_development_dependency "mocha"
21
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
22
- end
23
- Jeweler::GemcutterTasks.new
24
- rescue LoadError
25
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
26
- end
27
-
28
- begin
29
- require 'spec/rake/spectask'
30
- Spec::Rake::SpecTask.new(:spec) do |spec|
31
- spec.libs << 'lib' << 'spec'
32
- spec.spec_files = FileList['spec/**/*_spec.rb']
33
- end
34
-
35
- Spec::Rake::SpecTask.new(:rcov) do |spec|
36
- spec.libs << 'lib' << 'spec'
37
- spec.pattern = 'spec/**/*_spec.rb'
38
- spec.rcov = true
39
- end
40
- rescue LoadError
41
- puts "Rspec (or a dependency) not available. gem install rspec"
42
- end
43
-
44
- task :spec => :check_dependencies
45
-
46
- begin
47
- require 'cucumber/rake/task'
48
- Cucumber::Rake::Task.new(:features)
49
-
50
- task :features => :check_dependencies
51
- rescue LoadError
52
- task :features do
53
- abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
54
- end
55
- end
5
+ require 'rspec/core/rake_task'
56
6
 
57
- begin
58
- require 'reek/adapters/rake_task'
59
- Reek::RakeTask.new do |t|
60
- t.fail_on_error = true
61
- t.verbose = false
62
- t.source_files = 'lib/**/*.rb'
63
- end
64
- rescue LoadError
65
- task :reek do
66
- abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
7
+ desc "Run specs"
8
+ RSpec::Core::RakeTask.new do |t|
67
9
  end
68
- end
69
10
 
70
- begin
71
- require 'roodi'
72
- require 'roodi_task'
73
- RoodiTask.new do |t|
74
- t.verbose = false
75
- end
76
11
  rescue LoadError
77
- task :roodi do
78
- abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
79
- end
80
- end
81
-
82
- task :default => :spec
83
-
84
- begin
85
- require 'yard'
86
- YARD::Rake::YardocTask.new
87
- rescue LoadError
88
- task :yardoc do
89
- abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
90
- end
12
+ puts "RSpec is not installed"
91
13
  end
@@ -1,74 +1,27 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/ankh/version', __FILE__)
5
3
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{ankh}
8
- s.version = "0.1.3"
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Dan Pickett"]
6
+ gem.email = ["dpickett@enlightsolutions.com"]
7
+ gem.description = %q{Protect against bots and other spam producers}
8
+ gem.summary = %q{Asks simple randomized questions to detect humans}
9
+ gem.homepage = ""
9
10
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Dan Pickett"]
12
- s.date = %q{2011-10-23}
13
- s.description = %q{Use Ankh in your Rails (2.3.x or 3.0) projects to protect against bots and other spam producers. It asks a simple
14
- arithmatic question to verify that the poster is human.}
15
- s.email = %q{dpickett@enlightsolutions.com}
16
- s.extra_rdoc_files = [
17
- "LICENSE",
18
- "README.rdoc"
19
- ]
20
- s.files = [
21
- ".document",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "ankh.gemspec",
27
- "features/ankh.feature",
28
- "features/step_definitions/ankh_steps.rb",
29
- "features/support/env.rb",
30
- "lib/ankh.rb",
31
- "lib/ankh/model.rb",
32
- "lib/ankh/question.rb",
33
- "lib/ankh/rails/legacy.rb",
34
- "lib/ankh/validations/human.rb",
35
- "spec/ankh/model_spec.rb",
36
- "spec/ankh/question_spec.rb",
37
- "spec/ankh_spec.rb",
38
- "spec/spec.opts",
39
- "spec/spec_helper.rb",
40
- "spec/support/active_record_spec_helper.rb"
41
- ]
42
- s.homepage = %q{http://github.com/dpickett/ankh}
43
- s.require_paths = ["lib"]
44
- s.rubygems_version = %q{1.4.2}
45
- s.summary = %q{Protect against bots and other spam producers with simple mathematical questions}
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "ankh"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Ankh::VERSION
46
17
 
47
- if s.respond_to? :specification_version then
48
- s.specification_version = 3
18
+ gem.add_dependency "activesupport", "> 3.0"
19
+ gem.add_dependency "configatron"
49
20
 
50
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
- s.add_runtime_dependency(%q<activerecord>, [">= 2.3.4"])
52
- s.add_runtime_dependency(%q<activesupport>, [">= 2.3.4"])
53
- s.add_runtime_dependency(%q<configatron>, ["= 2.6.3"])
54
- s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
55
- s.add_development_dependency(%q<cucumber>, [">= 0"])
56
- s.add_development_dependency(%q<mocha>, [">= 0"])
57
- else
58
- s.add_dependency(%q<activerecord>, [">= 2.3.4"])
59
- s.add_dependency(%q<activesupport>, [">= 2.3.4"])
60
- s.add_dependency(%q<configatron>, ["= 2.6.3"])
61
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
62
- s.add_dependency(%q<cucumber>, [">= 0"])
63
- s.add_dependency(%q<mocha>, [">= 0"])
64
- end
65
- else
66
- s.add_dependency(%q<activerecord>, [">= 2.3.4"])
67
- s.add_dependency(%q<activesupport>, [">= 2.3.4"])
68
- s.add_dependency(%q<configatron>, ["= 2.6.3"])
69
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
70
- s.add_dependency(%q<cucumber>, [">= 0"])
71
- s.add_dependency(%q<mocha>, [">= 0"])
72
- end
21
+ gem.add_development_dependency "sqlite3"
22
+ gem.add_development_dependency "rake"
23
+ gem.add_development_dependency "rails"
24
+ gem.add_development_dependency "rspec", "> 1.2.9"
25
+ gem.add_development_dependency "mocha"
73
26
  end
74
27
 
@@ -0,0 +1,5 @@
1
+ require "./version"
2
+
3
+ module .
4
+ # Your code goes here...
5
+ end
@@ -1,14 +1,12 @@
1
- require "rubygems"
2
- require "active_record"
3
1
  require "digest/sha1"
4
2
  require "configatron"
5
3
 
6
- require "ankh/rails/legacy"
7
-
8
4
  require "ankh/question"
9
- require "ankh/validations/human"
5
+
6
+ require "ankh/validations/human_validator"
10
7
 
11
8
  require "ankh/model"
9
+ require "ankh/railtie" if defined?(Rails)
12
10
 
13
11
  module Ankh
14
12
  def self.salt=(salt)
@@ -22,4 +20,4 @@ module Ankh
22
20
  def self.encrypt(item_to_encrypt)
23
21
  Digest::SHA1.hexdigest("--#{salt}--#{item_to_encrypt}")
24
22
  end
25
- end
23
+ end
@@ -1,17 +1,25 @@
1
1
  module Ankh
2
2
  module Model
3
- def self.included(base)
4
- base.send(:attr_accessor, :human_answer)
5
- base.send(:attr_reader, :human_question)
6
- base.send(:attr_accessor, :salted_human_answer)
3
+ def validates_human(options = {})
4
+ include Ankh::Model::HelperMethods
5
+ validates_with Ankh::Validations::HumanValidator, options
7
6
  end
8
-
9
- def generate_human_question
10
- question = Ankh::Question.generate
11
- @human_question = question.question
12
- self.salted_human_answer = Ankh.encrypt(question.answer)
7
+
8
+ module HelperMethods
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+ attr_accessor :human_answer
13
+ attr_accessor :human_question
14
+ attr_accessor :salted_human_answer
15
+ end
16
+
17
+ def generate_human_question
18
+ question = Ankh::Question.generate
19
+ @human_question = question.question
20
+ self.salted_human_answer = Ankh.encrypt(question.answer)
21
+ end
13
22
  end
14
23
  end
15
24
  end
16
25
 
17
- ActiveRecord::Base.extend(Ankh::Validations::HelperMethods)
@@ -20,4 +20,4 @@ module Ankh
20
20
  new
21
21
  end
22
22
  end
23
- end
23
+ end
@@ -0,0 +1,8 @@
1
+ module Ankh
2
+ class Railtie < Rails::Railtie
3
+ initializer "ankh" do
4
+ ActiveRecord::Base.extend Ankh::Model
5
+ end
6
+ end
7
+ end
8
+
@@ -17,17 +17,5 @@ module Ankh
17
17
  record.salted_human_answer.present? && Ankh.encrypt(record.human_answer) != record.salted_human_answer
18
18
  end
19
19
  end
20
-
21
- module HelperMethods
22
- def validates_human(options = {})
23
- self.send(:include, Ankh::Model) unless probably_included_already?
24
- validates_with HumanValidator, options
25
- end
26
-
27
- private
28
- def probably_included_already?
29
- self.respond_to?(:human_question) && self.respond_to?(:human_answer)
30
- end
31
- end
32
20
  end
33
21
  end
@@ -0,0 +1,3 @@
1
+ module Ankh
2
+ VERSION = "0.2.0"
3
+ end
@@ -2,7 +2,9 @@ require "spec_helper"
2
2
 
3
3
  describe Ankh::Model do
4
4
  INVALID_ANSWER = "3241235" #this answer will never be valid due to constraints
5
- class Post < ActiveRecord::Base
5
+ class Post
6
+ include ActiveModel::Validations
7
+ extend Ankh::Model
6
8
  validates_human
7
9
  attr_accessor :name
8
10
  validates_presence_of :name
@@ -26,19 +28,19 @@ describe Ankh::Model do
26
28
 
27
29
  it "should not save if I do not specify a human answer" do
28
30
  subject.human_answer = ""
29
- subject.save.should be_false
31
+ subject.should_not be_valid
30
32
  subject.errors[:human_answer].should_not be_nil
31
33
  end
32
34
 
33
35
  it "should clear out the human answer if validation fails" do
34
36
  subject.human_answer = INVALID_ANSWER
35
- subject.save.should be_false
37
+ subject.should_not be_valid
36
38
  subject.human_answer.should be_blank
37
39
  end
38
40
 
39
41
  it "should not save if I do not match the intended answer" do
40
42
  subject.human_answer = INVALID_ANSWER
41
- subject.save.should be_false
43
+ subject.should_not be_valid
42
44
  subject.errors[:human_answer].should_not be_nil
43
45
  end
44
46
 
@@ -47,7 +49,7 @@ describe Ankh::Model do
47
49
  Ankh::Question.expects(:generate).returns(question)
48
50
 
49
51
  subject.human_answer = question.answer
50
- subject.save.should be_true
52
+ subject.should be_valid
51
53
  end
52
54
 
53
55
  it "should clear the human answer if the model is not valid" do
@@ -55,7 +57,8 @@ describe Ankh::Model do
55
57
  Ankh::Question.expects(:generate).returns(question)
56
58
  subject.name = nil
57
59
  subject.human_answer = question.answer
58
- subject.save.should be_false
60
+ subject.should_not be_valid
59
61
  subject.human_answer.should be_blank
60
62
  end
61
- end
63
+ end
64
+
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks