From 01f3ef72f5102cf2e722f62f11a54c9236d27c05 Mon Sep 17 00:00:00 2001 From: Azdaroth Date: Thu, 23 May 2013 10:15:51 +0200 Subject: [PATCH 001/115] remove support for set_table_name, attr_accesible, dynamic finders, changed version --- lib/simple_captcha/form_builder.rb | 4 ++-- lib/simple_captcha/simple_captcha_data.rb | 16 +++------------- lib/simple_captcha/version.rb | 2 +- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/lib/simple_captcha/form_builder.rb b/lib/simple_captcha/form_builder.rb index b4323d8..fbae3fb 100644 --- a/lib/simple_captcha/form_builder.rb +++ b/lib/simple_captcha/form_builder.rb @@ -4,8 +4,8 @@ def self.included(base) base.send(:include, SimpleCaptcha::ViewHelper) base.send(:include, SimpleCaptcha::FormBuilder::ClassMethods) base.send(:include, ActionView::Helpers) - base.send(:include, Sprockets::Helpers::RailsHelper) - base.send(:include, Sprockets::Helpers::IsolatedHelper) + base.send(:include, Sprockets::Rails::Helpers::RailsHelper) + base.send(:include, Sprockets::Rails::Helpers::IsolatedHelper) base.delegate :render, :session, :to => :template end diff --git a/lib/simple_captcha/simple_captcha_data.rb b/lib/simple_captcha/simple_captcha_data.rb index 374e698..0fd4ef8 100644 --- a/lib/simple_captcha/simple_captcha_data.rb +++ b/lib/simple_captcha/simple_captcha_data.rb @@ -1,22 +1,12 @@ module SimpleCaptcha class SimpleCaptchaData < ::ActiveRecord::Base - def self.rails3? - ::ActiveRecord::VERSION::MAJOR == 3 - end - - if rails3? - # Fixes deprecation warning in Rails 3.2: - # DEPRECATION WARNING: Calling set_table_name is deprecated. Please use `self.table_name = 'the_name'` instead. - self.table_name = "simple_captcha_data" - else - set_table_name "simple_captcha_data" - end + + self.table_name = "simple_captcha_data" - attr_accessible :key, :value class << self def get_data(key) - data = find_by_key(key) || new(:key => key) + data = where(key: key).first || new(key: key) end def remove_data(key) diff --git a/lib/simple_captcha/version.rb b/lib/simple_captcha/version.rb index 33b2189..7b7571a 100644 --- a/lib/simple_captcha/version.rb +++ b/lib/simple_captcha/version.rb @@ -1,3 +1,3 @@ module SimpleCaptcha - VERSION = "0.1.5".freeze + VERSION = "0.1.6".freeze end From 2457d1913e1dfb26fb3f0c93e4fe5158f36b5868 Mon Sep 17 00:00:00 2001 From: Azdaroth Date: Thu, 23 May 2013 10:21:09 +0200 Subject: [PATCH 002/115] fix including rails helpers --- lib/simple_captcha/form_builder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/simple_captcha/form_builder.rb b/lib/simple_captcha/form_builder.rb index fbae3fb..6f3a43d 100644 --- a/lib/simple_captcha/form_builder.rb +++ b/lib/simple_captcha/form_builder.rb @@ -4,8 +4,8 @@ def self.included(base) base.send(:include, SimpleCaptcha::ViewHelper) base.send(:include, SimpleCaptcha::FormBuilder::ClassMethods) base.send(:include, ActionView::Helpers) - base.send(:include, Sprockets::Rails::Helpers::RailsHelper) - base.send(:include, Sprockets::Rails::Helpers::IsolatedHelper) + base.send(:include, Sprockets::Rails::Helper::RailsHelper) + base.send(:include, Sprockets::Rails::Helper::IsolatedHelper) base.delegate :render, :session, :to => :template end From 4ff33a74eda8d4c44d2a1326e1b217f1e7ade389 Mon Sep 17 00:00:00 2001 From: Azdaroth Date: Thu, 23 May 2013 10:28:56 +0200 Subject: [PATCH 003/115] beack to previous version with rails sprockets --- lib/simple_captcha/form_builder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/simple_captcha/form_builder.rb b/lib/simple_captcha/form_builder.rb index 6f3a43d..fbae3fb 100644 --- a/lib/simple_captcha/form_builder.rb +++ b/lib/simple_captcha/form_builder.rb @@ -4,8 +4,8 @@ def self.included(base) base.send(:include, SimpleCaptcha::ViewHelper) base.send(:include, SimpleCaptcha::FormBuilder::ClassMethods) base.send(:include, ActionView::Helpers) - base.send(:include, Sprockets::Rails::Helper::RailsHelper) - base.send(:include, Sprockets::Rails::Helper::IsolatedHelper) + base.send(:include, Sprockets::Rails::Helpers::RailsHelper) + base.send(:include, Sprockets::Rails::Helpers::IsolatedHelper) base.delegate :render, :session, :to => :template end From 4791570204b460150581e803fdf25c0aed03db26 Mon Sep 17 00:00:00 2001 From: Azdaroth Date: Thu, 23 May 2013 10:32:08 +0200 Subject: [PATCH 004/115] confusing change with rails 4 sprockets --- lib/simple_captcha/form_builder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/simple_captcha/form_builder.rb b/lib/simple_captcha/form_builder.rb index fbae3fb..6f3a43d 100644 --- a/lib/simple_captcha/form_builder.rb +++ b/lib/simple_captcha/form_builder.rb @@ -4,8 +4,8 @@ def self.included(base) base.send(:include, SimpleCaptcha::ViewHelper) base.send(:include, SimpleCaptcha::FormBuilder::ClassMethods) base.send(:include, ActionView::Helpers) - base.send(:include, Sprockets::Rails::Helpers::RailsHelper) - base.send(:include, Sprockets::Rails::Helpers::IsolatedHelper) + base.send(:include, Sprockets::Rails::Helper::RailsHelper) + base.send(:include, Sprockets::Rails::Helper::IsolatedHelper) base.delegate :render, :session, :to => :template end From 02b9c4c7893febae1310864b7f3ca6d65fb53f91 Mon Sep 17 00:00:00 2001 From: Azdaroth Date: Thu, 23 May 2013 10:39:13 +0200 Subject: [PATCH 005/115] lucky try with sprockets --- lib/simple_captcha/form_builder.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/simple_captcha/form_builder.rb b/lib/simple_captcha/form_builder.rb index 6f3a43d..9c8693e 100644 --- a/lib/simple_captcha/form_builder.rb +++ b/lib/simple_captcha/form_builder.rb @@ -4,8 +4,7 @@ def self.included(base) base.send(:include, SimpleCaptcha::ViewHelper) base.send(:include, SimpleCaptcha::FormBuilder::ClassMethods) base.send(:include, ActionView::Helpers) - base.send(:include, Sprockets::Rails::Helper::RailsHelper) - base.send(:include, Sprockets::Rails::Helper::IsolatedHelper) + base.send(:include, Sprockets::Rails::Helper) base.delegate :render, :session, :to => :template end From 486e29672a347c70e0e9d7fe585787b3ab041aa4 Mon Sep 17 00:00:00 2001 From: Vincent Thelang Date: Mon, 24 Jun 2013 15:05:14 +0200 Subject: [PATCH 006/115] fixed ActiveRecord Naming reference for Rails 4.0.0rc2 --- lib/simple_captcha/active_record.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/simple_captcha/active_record.rb b/lib/simple_captcha/active_record.rb index 9a6427e..e864c15 100644 --- a/lib/simple_captcha/active_record.rb +++ b/lib/simple_captcha/active_record.rb @@ -60,7 +60,7 @@ def is_captcha_valid? SimpleCaptcha::Utils::simple_captcha_passed!(captcha_key) return true else - message = simple_captcha_options[:message] || I18n.t(self.class.model_name.downcase, :scope => [:simple_captcha, :message], :default => :default) + message = simple_captcha_options[:message] || I18n.t(self.class.model_name.to_s.downcase, :scope => [:simple_captcha, :message], :default => :default) simple_captcha_options[:add_to_base] ? errors.add(:base, message) : errors.add(:captcha, message) return false end From 16decf3b1bfe628f0800bbc1d8e177091ae1d44c Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Mon, 4 Nov 2013 11:57:08 +0100 Subject: [PATCH 007/115] Dummyapp and integration tests added; SimpleCaptcha.always_pass = Rails.env.test? extracted --- .gitignore | 23 ++--- Gemfile | 4 + README.rdoc | 5 +- Rakefile | 43 ++++++---- lib/simple_captcha.rb | 4 + lib/simple_captcha/active_record.rb | 24 +++--- lib/simple_captcha/controller.rb | 6 +- lib/simple_captcha/form_builder.rb | 2 +- lib/simple_captcha/version.rb | 2 +- simple_captcha.gemspec | 13 ++- test/dummy/README.rdoc | 28 ++++++ test/dummy/Rakefile | 6 ++ test/dummy/app/assets/images/.keep | 0 .../app/assets/javascripts/application.js | 13 +++ .../app/assets/stylesheets/application.css | 13 +++ .../app/controllers/application_controller.rb | 6 ++ test/dummy/app/controllers/concerns/.keep | 0 .../dummy/app/controllers/pages_controller.rb | 12 +++ test/dummy/app/helpers/application_helper.rb | 2 + test/dummy/app/mailers/.keep | 0 test/dummy/app/models/.keep | 0 test/dummy/app/models/concerns/.keep | 0 .../app/views/layouts/application.html.erb | 14 +++ test/dummy/app/views/pages/form_tag.html.erb | 7 ++ .../views/simple_captcha/_simple_captcha.erb | 37 ++++++++ test/dummy/bin/bundle | 3 + test/dummy/bin/rails | 4 + test/dummy/bin/rake | 4 + test/dummy/config.ru | 4 + test/dummy/config/application.rb | 23 +++++ test/dummy/config/boot.rb | 5 ++ test/dummy/config/database.yml | 25 ++++++ test/dummy/config/environment.rb | 5 ++ test/dummy/config/environments/development.rb | 29 +++++++ test/dummy/config/environments/production.rb | 80 ++++++++++++++++++ test/dummy/config/environments/test.rb | 36 ++++++++ .../initializers/backtrace_silencers.rb | 7 ++ .../initializers/filter_parameter_logging.rb | 4 + test/dummy/config/initializers/inflections.rb | 16 ++++ test/dummy/config/initializers/mime_types.rb | 5 ++ .../dummy/config/initializers/secret_token.rb | 12 +++ .../config/initializers/session_store.rb | 3 + .../config/initializers/wrap_parameters.rb | 14 +++ test/dummy/config/locales/en.yml | 23 +++++ test/dummy/config/routes.rb | 6 ++ test/dummy/db/development.sqlite3 | Bin 0 -> 6144 bytes ...131104112427_create_simple_captcha_data.rb | 15 ++++ test/dummy/db/schema.rb | 25 ++++++ test/dummy/db/test.sqlite3 | Bin 0 -> 6144 bytes test/dummy/lib/assets/.keep | 0 test/dummy/log/.keep | 0 test/dummy/public/404.html | 58 +++++++++++++ test/dummy/public/422.html | 58 +++++++++++++ test/dummy/public/500.html | 57 +++++++++++++ test/dummy/public/favicon.ico | 0 test/features/form_helper_test.rb | 25 ++++++ test/simple_captcha_test.rb | 8 -- test/test_helper.rb | 18 ++++ 58 files changed, 770 insertions(+), 66 deletions(-) create mode 100644 Gemfile create mode 100644 test/dummy/README.rdoc create mode 100644 test/dummy/Rakefile create mode 100644 test/dummy/app/assets/images/.keep create mode 100644 test/dummy/app/assets/javascripts/application.js create mode 100644 test/dummy/app/assets/stylesheets/application.css create mode 100644 test/dummy/app/controllers/application_controller.rb create mode 100644 test/dummy/app/controllers/concerns/.keep create mode 100644 test/dummy/app/controllers/pages_controller.rb create mode 100644 test/dummy/app/helpers/application_helper.rb create mode 100644 test/dummy/app/mailers/.keep create mode 100644 test/dummy/app/models/.keep create mode 100644 test/dummy/app/models/concerns/.keep create mode 100644 test/dummy/app/views/layouts/application.html.erb create mode 100644 test/dummy/app/views/pages/form_tag.html.erb create mode 100644 test/dummy/app/views/simple_captcha/_simple_captcha.erb create mode 100755 test/dummy/bin/bundle create mode 100755 test/dummy/bin/rails create mode 100755 test/dummy/bin/rake create mode 100644 test/dummy/config.ru create mode 100644 test/dummy/config/application.rb create mode 100644 test/dummy/config/boot.rb create mode 100644 test/dummy/config/database.yml create mode 100644 test/dummy/config/environment.rb create mode 100644 test/dummy/config/environments/development.rb create mode 100644 test/dummy/config/environments/production.rb create mode 100644 test/dummy/config/environments/test.rb create mode 100644 test/dummy/config/initializers/backtrace_silencers.rb create mode 100644 test/dummy/config/initializers/filter_parameter_logging.rb create mode 100644 test/dummy/config/initializers/inflections.rb create mode 100644 test/dummy/config/initializers/mime_types.rb create mode 100644 test/dummy/config/initializers/secret_token.rb create mode 100644 test/dummy/config/initializers/session_store.rb create mode 100644 test/dummy/config/initializers/wrap_parameters.rb create mode 100644 test/dummy/config/locales/en.yml create mode 100644 test/dummy/config/routes.rb create mode 100644 test/dummy/db/development.sqlite3 create mode 100644 test/dummy/db/migrate/20131104112427_create_simple_captcha_data.rb create mode 100644 test/dummy/db/schema.rb create mode 100644 test/dummy/db/test.sqlite3 create mode 100644 test/dummy/lib/assets/.keep create mode 100644 test/dummy/log/.keep create mode 100644 test/dummy/public/404.html create mode 100644 test/dummy/public/422.html create mode 100644 test/dummy/public/500.html create mode 100644 test/dummy/public/favicon.ico create mode 100644 test/features/form_helper_test.rb delete mode 100644 test/simple_captcha_test.rb create mode 100644 test/test_helper.rb diff --git a/.gitignore b/.gitignore index a2f6bf5..0c95927 100644 --- a/.gitignore +++ b/.gitignore @@ -1,21 +1,8 @@ pkg/ Gemfile.lock .rspec -spec/tmp -spec/dummy/log/*.log -spec/dummy/tmp/ -spec/dummy/config/*.yml -spec/dummy/config/*.conf -spec/dummy/config/logrotate-config -spec/dummy/config/nginx-config -spec/dummy/db/schema.rb -spec/dummy/db/sphinx/ -spec/dummy/public/cache/ -spec/dummy/public/assets/ -spec/dummy/public/ckeditor_assets/ -spec/dummy/public/uploads/ -spec/dummy/vendor/bundle/ -spec/dummy/app/helpers/manage -spec/dummy/config/database.yml -spec/dummy/log/development.log -.svn \ No newline at end of file +test/tmp +test/dummy/log/*.log +test/dummy/tmp/ +test/dummy/db/*sqlite +.svn diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..f68a903 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source "https://rubygems.org" + +gemspec + diff --git a/README.rdoc b/README.rdoc index ad4ca02..854656c 100644 --- a/README.rdoc +++ b/README.rdoc @@ -24,11 +24,8 @@ backward compatibility with previous versions of Rails. ==Installation - gem "galetahub-simple_captcha", :require => "simple_captcha" -or - - gem 'simple_captcha', :git => 'git://github.com/galetahub/simple-captcha.git' + gem 'simple_captcha', :git => 'git://github.com/pludoni/simple-captcha.git' ==Setup diff --git a/Rakefile b/Rakefile index 7901e39..7dbf1a6 100644 --- a/Rakefile +++ b/Rakefile @@ -1,22 +1,35 @@ -require 'rake' -require 'rake/testtask' -require 'rake/rdoctask' +begin + require 'bundler/setup' +rescue LoadError + puts 'You must `gem install bundler` and `bundle install` to run rake tasks' +end + +require 'rdoc/task' + +RDoc::Task.new(:rdoc) do |rdoc| + rdoc.rdoc_dir = 'rdoc' + rdoc.title = 'SimpleCaptcha' + rdoc.options << '--line-numbers' + rdoc.rdoc_files.include('README.rdoc') + rdoc.rdoc_files.include('lib/**/*.rb') +end + +APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__) +load 'rails/tasks/engine.rake' + -desc 'Default: run unit tests.' -task :default => :test -desc 'Test the simple_captcha plugin.' +Bundler::GemHelper.install_tasks + +require 'rake/testtask' + Rake::TestTask.new(:test) do |t| t.libs << 'lib' + t.libs << 'test' t.pattern = 'test/**/*_test.rb' - t.verbose = true + t.verbose = false end -desc 'Generate documentation for the simple_captcha plugin.' -Rake::RDocTask.new(:rdoc) do |rdoc| - rdoc.rdoc_dir = 'rdoc' - rdoc.title = 'SimpleCaptcha' - rdoc.options << '--line-numbers' << '--inline-source' - rdoc.rdoc_files.include('README') - rdoc.rdoc_files.include('lib/**/*.rb') -end + +task default: :test + diff --git a/lib/simple_captcha.rb b/lib/simple_captcha.rb index 995ee1a..cf45462 100644 --- a/lib/simple_captcha.rb +++ b/lib/simple_captcha.rb @@ -1,6 +1,10 @@ # encoding: utf-8 module SimpleCaptcha + class << self + attr_accessor :always_pass + end + self.always_pass = Rails.env.test? autoload :Utils, 'simple_captcha/utils' autoload :ImageHelpers, 'simple_captcha/image' diff --git a/lib/simple_captcha/active_record.rb b/lib/simple_captcha/active_record.rb index e864c15..5695a36 100644 --- a/lib/simple_captcha/active_record.rb +++ b/lib/simple_captcha/active_record.rb @@ -3,7 +3,7 @@ module ModelHelpers #:nodoc def self.included(base) base.extend(SingletonMethods) end - + # To implement model based simple captcha use this method in the model as... # # class User < ActiveRecord::Base @@ -12,13 +12,13 @@ def self.included(base) # # end # - # Customize the error message by using :message, the default message is "Captcha did not match". + # Customize the error message by using :message, the default message is "Captcha did not match". # As in the applications captcha is needed with a very few cases like signing up the new user, but # not every time you need to authenticate the captcha with @user.save. So as to maintain simplicity # here we have the explicit method to save the instace with captcha validation as... # # * to validate the instance - # + # # @user.valid_with_captcha? # whene captcha validation is required. # # @user.valid? # when captcha validation is not required. @@ -31,30 +31,30 @@ def self.included(base) module SingletonMethods def apply_simple_captcha(options = {}) options = { :add_to_base => false }.merge(options) - + class_attribute :simple_captcha_options self.simple_captcha_options = options - + unless self.is_a?(ClassMethods) include InstanceMethods extend ClassMethods - + attr_accessor :captcha, :captcha_key end end end - + module ClassMethods end - + module InstanceMethods - + def valid_with_captcha? [valid?, is_captcha_valid?].all? end - + def is_captcha_valid? - return true if Rails.env.test? + return true if SimpleCaptcha.always_pass if captcha && captcha.upcase.delete(" ") == SimpleCaptcha::Utils::simple_captcha_value(captcha_key) SimpleCaptcha::Utils::simple_captcha_passed!(captcha_key) @@ -65,7 +65,7 @@ def is_captcha_valid? return false end end - + def save_with_captcha valid_with_captcha? && save(:validate => false) end diff --git a/lib/simple_captcha/controller.rb b/lib/simple_captcha/controller.rb index 4000f86..f7fb2ff 100644 --- a/lib/simple_captcha/controller.rb +++ b/lib/simple_captcha/controller.rb @@ -1,4 +1,4 @@ -module SimpleCaptcha #:nodoc +module SimpleCaptcha #:nodoc module ControllerHelpers #:nodoc # This method is to validate the simple captcha in controller. # It means when the captcha is controller based i.e. :object has not been passed to the method show_simple_captcha. @@ -14,8 +14,8 @@ module ControllerHelpers #:nodoc # redirect_to :action => "myaction" # end def simple_captcha_valid? - return true if Rails.env.test? - + return true if SimpleCaptcha.always_pass + if params[:captcha] data = SimpleCaptcha::Utils::simple_captcha_value(params[:captcha_key] || session[:captcha]) result = data == params[:captcha].delete(" ").upcase diff --git a/lib/simple_captcha/form_builder.rb b/lib/simple_captcha/form_builder.rb index c16ccca..e7e34fd 100644 --- a/lib/simple_captcha/form_builder.rb +++ b/lib/simple_captcha/form_builder.rb @@ -4,7 +4,7 @@ def self.included(base) base.send(:include, SimpleCaptcha::ViewHelper) base.send(:include, SimpleCaptcha::FormBuilder::ClassMethods) base.send(:include, ActionView::Helpers) - if defined? Sprockets + if defined? Sprockets::Helpers base.send(:include, Sprockets::Helpers::RailsHelper) base.send(:include, Sprockets::Helpers::IsolatedHelper) end diff --git a/lib/simple_captcha/version.rb b/lib/simple_captcha/version.rb index 7b7571a..a8508da 100644 --- a/lib/simple_captcha/version.rb +++ b/lib/simple_captcha/version.rb @@ -1,3 +1,3 @@ module SimpleCaptcha - VERSION = "0.1.6".freeze + VERSION = "0.2.0".freeze end diff --git a/simple_captcha.gemspec b/simple_captcha.gemspec index 9e7d123..1c59250 100644 --- a/simple_captcha.gemspec +++ b/simple_captcha.gemspec @@ -5,15 +5,20 @@ require "simple_captcha/version" Gem::Specification.new do |s| s.name = "simple_captcha" s.version = SimpleCaptcha::VERSION.dup - s.platform = Gem::Platform::RUBY + s.platform = Gem::Platform::RUBY s.summary = "SimpleCaptcha is the simplest and a robust captcha plugin." s.description = "SimpleCaptcha is available to be used with Rails 3 or above and also it provides the backward compatibility with previous versions of Rails." - s.authors = ["Pavlo Galeta", "Igor Galeta"] + s.authors = ["Pavlo Galeta", "Igor Galeta", 'Stefan Wienert'] s.email = "galeta.igor@gmail.com" s.homepage = "http://github.com/izzm/simple-captcha" - + s.files = Dir["{lib}/**/*"] + ["Rakefile", "README.rdoc"] - s.test_files = Dir["{test}/**/*"] s.extra_rdoc_files = ["README.rdoc"] s.require_paths = ["lib"] + + s.add_dependency 'rails', '>= 3.1' + s.add_development_dependency "sqlite3" + s.add_development_dependency "capybara-mechanize" + s.add_development_dependency "pry" + end diff --git a/test/dummy/README.rdoc b/test/dummy/README.rdoc new file mode 100644 index 0000000..dd4e97e --- /dev/null +++ b/test/dummy/README.rdoc @@ -0,0 +1,28 @@ +== README + +This README would normally document whatever steps are necessary to get the +application up and running. + +Things you may want to cover: + +* Ruby version + +* System dependencies + +* Configuration + +* Database creation + +* Database initialization + +* How to run the test suite + +* Services (job queues, cache servers, search engines, etc.) + +* Deployment instructions + +* ... + + +Please feel free to use a different markup language if you do not plan to run +rake doc:app. diff --git a/test/dummy/Rakefile b/test/dummy/Rakefile new file mode 100644 index 0000000..4135d7a --- /dev/null +++ b/test/dummy/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require File.expand_path('../config/application', __FILE__) + +Dummy::Application.load_tasks diff --git a/test/dummy/app/assets/images/.keep b/test/dummy/app/assets/images/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/app/assets/javascripts/application.js b/test/dummy/app/assets/javascripts/application.js new file mode 100644 index 0000000..5bc2e1c --- /dev/null +++ b/test/dummy/app/assets/javascripts/application.js @@ -0,0 +1,13 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. +// +// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require_tree . diff --git a/test/dummy/app/assets/stylesheets/application.css b/test/dummy/app/assets/stylesheets/application.css new file mode 100644 index 0000000..3192ec8 --- /dev/null +++ b/test/dummy/app/assets/stylesheets/application.css @@ -0,0 +1,13 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the top of the + * compiled file, but it's generally better to create a new file per style scope. + * + *= require_self + *= require_tree . + */ diff --git a/test/dummy/app/controllers/application_controller.rb b/test/dummy/app/controllers/application_controller.rb new file mode 100644 index 0000000..6c1698d --- /dev/null +++ b/test/dummy/app/controllers/application_controller.rb @@ -0,0 +1,6 @@ +class ApplicationController < ActionController::Base + # Prevent CSRF attacks by raising an exception. + # For APIs, you may want to use :null_session instead. + protect_from_forgery with: :exception + include SimpleCaptcha::ControllerHelpers +end diff --git a/test/dummy/app/controllers/concerns/.keep b/test/dummy/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/app/controllers/pages_controller.rb b/test/dummy/app/controllers/pages_controller.rb new file mode 100644 index 0000000..59360a1 --- /dev/null +++ b/test/dummy/app/controllers/pages_controller.rb @@ -0,0 +1,12 @@ +class PagesController < ApplicationController + def form_tag + end + + def form_tag_submit + if simple_captcha_valid? + render text: 'captcha valid!' + else + render text: 'captcha not valid!' + end + end +end diff --git a/test/dummy/app/helpers/application_helper.rb b/test/dummy/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/test/dummy/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/test/dummy/app/mailers/.keep b/test/dummy/app/mailers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/app/models/.keep b/test/dummy/app/models/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/app/models/concerns/.keep b/test/dummy/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/app/views/layouts/application.html.erb b/test/dummy/app/views/layouts/application.html.erb new file mode 100644 index 0000000..670d187 --- /dev/null +++ b/test/dummy/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ + + + + Dummy + <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> + <%= javascript_include_tag "application", "data-turbolinks-track" => true %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/test/dummy/app/views/pages/form_tag.html.erb b/test/dummy/app/views/pages/form_tag.html.erb new file mode 100644 index 0000000..6af13b5 --- /dev/null +++ b/test/dummy/app/views/pages/form_tag.html.erb @@ -0,0 +1,7 @@ +

Pages#index

+ +<%= form_tag '', :method => :post do |f| %> + <%= show_simple_captcha %> + <%= submit_tag %> +<% end %> + diff --git a/test/dummy/app/views/simple_captcha/_simple_captcha.erb b/test/dummy/app/views/simple_captcha/_simple_captcha.erb new file mode 100644 index 0000000..9968910 --- /dev/null +++ b/test/dummy/app/views/simple_captcha/_simple_captcha.erb @@ -0,0 +1,37 @@ + + +
+
+ <%= simple_captcha_options[:image] %> +
+ +
+ <%= simple_captcha_options[:field] %> +
+ +
+ <%= simple_captcha_options[:label] %> +
+
diff --git a/test/dummy/bin/bundle b/test/dummy/bin/bundle new file mode 100755 index 0000000..66e9889 --- /dev/null +++ b/test/dummy/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/test/dummy/bin/rails b/test/dummy/bin/rails new file mode 100755 index 0000000..728cd85 --- /dev/null +++ b/test/dummy/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/test/dummy/bin/rake b/test/dummy/bin/rake new file mode 100755 index 0000000..1724048 --- /dev/null +++ b/test/dummy/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/test/dummy/config.ru b/test/dummy/config.ru new file mode 100644 index 0000000..5bc2a61 --- /dev/null +++ b/test/dummy/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run Rails.application diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb new file mode 100644 index 0000000..6fe074b --- /dev/null +++ b/test/dummy/config/application.rb @@ -0,0 +1,23 @@ +require File.expand_path('../boot', __FILE__) + +require 'rails/all' + +Bundler.require(*Rails.groups) +require "simple_captcha" + +module Dummy + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + + # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. + # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. + # config.time_zone = 'Central Time (US & Canada)' + + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] + # config.i18n.default_locale = :de + end +end + diff --git a/test/dummy/config/boot.rb b/test/dummy/config/boot.rb new file mode 100644 index 0000000..ef36047 --- /dev/null +++ b/test/dummy/config/boot.rb @@ -0,0 +1,5 @@ +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) + +require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) +$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) diff --git a/test/dummy/config/database.yml b/test/dummy/config/database.yml new file mode 100644 index 0000000..51a4dd4 --- /dev/null +++ b/test/dummy/config/database.yml @@ -0,0 +1,25 @@ +# SQLite version 3.x +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem 'sqlite3' +development: + adapter: sqlite3 + database: db/development.sqlite3 + pool: 5 + timeout: 5000 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + adapter: sqlite3 + database: db/test.sqlite3 + pool: 5 + timeout: 5000 + +production: + adapter: sqlite3 + database: db/production.sqlite3 + pool: 5 + timeout: 5000 diff --git a/test/dummy/config/environment.rb b/test/dummy/config/environment.rb new file mode 100644 index 0000000..10e0cad --- /dev/null +++ b/test/dummy/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require File.expand_path('../application', __FILE__) + +# Initialize the Rails application. +Dummy::Application.initialize! diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb new file mode 100644 index 0000000..9d26e12 --- /dev/null +++ b/test/dummy/config/environments/development.rb @@ -0,0 +1,29 @@ +Dummy::Application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations + config.active_record.migration_error = :page_load + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true +end diff --git a/test/dummy/config/environments/production.rb b/test/dummy/config/environments/production.rb new file mode 100644 index 0000000..b690b1c --- /dev/null +++ b/test/dummy/config/environments/production.rb @@ -0,0 +1,80 @@ +Dummy::Application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both thread web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Enable Rack::Cache to put a simple HTTP cache in front of your application + # Add `rack-cache` to your Gemfile before enabling this. + # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. + # config.action_dispatch.rack_cache = true + + # Disable Rails's static asset server (Apache or nginx will already do this). + config.serve_static_assets = false + + # Compress JavaScripts and CSS. + config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + config.assets.compile = false + + # Generate digests for assets URLs. + config.assets.digest = true + + # Version of your assets, change this if you want to expire all your assets. + config.assets.version = '1.0' + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Set to :debug to see everything in the log. + config.log_level = :info + + # Prepend all log lines with the following tags. + # config.log_tags = [ :subdomain, :uuid ] + + # Use a different logger for distributed setups. + # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = "http://assets.example.com" + + # Precompile additional assets. + # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. + # config.assets.precompile += %w( search.js ) + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation can not be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Disable automatic flushing of the log to improve performance. + # config.autoflush_log = false + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new +end diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb new file mode 100644 index 0000000..afbc0ae --- /dev/null +++ b/test/dummy/config/environments/test.rb @@ -0,0 +1,36 @@ +Dummy::Application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure static asset server for tests with Cache-Control for performance. + config.serve_static_assets = true + config.static_cache_control = "public, max-age=3600" + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr +end diff --git a/test/dummy/config/initializers/backtrace_silencers.rb b/test/dummy/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..59385cd --- /dev/null +++ b/test/dummy/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/test/dummy/config/initializers/filter_parameter_logging.rb b/test/dummy/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000..4a994e1 --- /dev/null +++ b/test/dummy/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/test/dummy/config/initializers/inflections.rb b/test/dummy/config/initializers/inflections.rb new file mode 100644 index 0000000..ac033bf --- /dev/null +++ b/test/dummy/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/test/dummy/config/initializers/mime_types.rb b/test/dummy/config/initializers/mime_types.rb new file mode 100644 index 0000000..72aca7e --- /dev/null +++ b/test/dummy/config/initializers/mime_types.rb @@ -0,0 +1,5 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf +# Mime::Type.register_alias "text/html", :iphone diff --git a/test/dummy/config/initializers/secret_token.rb b/test/dummy/config/initializers/secret_token.rb new file mode 100644 index 0000000..6578b84 --- /dev/null +++ b/test/dummy/config/initializers/secret_token.rb @@ -0,0 +1,12 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! + +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +# You can use `rake secret` to generate a secure secret key. + +# Make sure your secret_key_base is kept private +# if you're sharing your code publicly. +Dummy::Application.config.secret_key_base = 'dc42d1e5f6b46ed4067ca613f3ed86c2235a3fe6131553d25f475d7007768154310479912a5847dd18a65ea0f5672ee662359001d6f7fa25a42382a02e948310' diff --git a/test/dummy/config/initializers/session_store.rb b/test/dummy/config/initializers/session_store.rb new file mode 100644 index 0000000..155f7b0 --- /dev/null +++ b/test/dummy/config/initializers/session_store.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Dummy::Application.config.session_store :cookie_store, key: '_dummy_session' diff --git a/test/dummy/config/initializers/wrap_parameters.rb b/test/dummy/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000..33725e9 --- /dev/null +++ b/test/dummy/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] if respond_to?(:wrap_parameters) +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/test/dummy/config/locales/en.yml b/test/dummy/config/locales/en.yml new file mode 100644 index 0000000..0653957 --- /dev/null +++ b/test/dummy/config/locales/en.yml @@ -0,0 +1,23 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb new file mode 100644 index 0000000..7eb13cd --- /dev/null +++ b/test/dummy/config/routes.rb @@ -0,0 +1,6 @@ +Rails.application.routes.draw do + + get "pages/form_tag" + post "pages/form_tag" => 'pages#form_tag_submit' + mount SimpleCaptcha::Engine => "/simple_captcha" +end diff --git a/test/dummy/db/development.sqlite3 b/test/dummy/db/development.sqlite3 new file mode 100644 index 0000000000000000000000000000000000000000..c3790a4ea756dc54ebf38d438b08365ce749b008 GIT binary patch literal 6144 zcmeH}UvJYe5WwxaekEm8*0;Z@PtHx2vv0HR#J&dpvWX1vuLt5ajPMo z$~#|$vp-MngQ>L)K9PpyIQVC98FM?=8}g}c#J(+K6)`B#ci*`q zdNk@E_C^!>-ks3i*dO*i2yy6oKJ|t$#)H8=y(p0`MGBPCX1C43v=q~YWNYK|+!m%% zXc+}UGYT-JR!|FNi&;L|H1k!X(y(5(@Tzsukwu~aR*;3KG8RFszNSK}vn1OxkfOq| z*FPSw`*hp#qH*P@dE1sU&0q({=eS|DAd!ccoXfsj8B|J)%L}dtU-Ri49Pl+!o}W!j z{vr5`7y^dCohI-AS9qswJGR~K+IFYgd2tWw#pEx7&xj#l2;5}?j|j(`#~Cd? 40 + t.string :value, :limit => 6 + t.timestamps + end + + add_index :simple_captcha_data, :key, :name => "idx_key" + end + + def self.down + drop_table :simple_captcha_data + end +end diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb new file mode 100644 index 0000000..5aae878 --- /dev/null +++ b/test/dummy/db/schema.rb @@ -0,0 +1,25 @@ +# encoding: UTF-8 +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 20131104112427) do + + create_table "simple_captcha_data", force: true do |t| + t.string "key", limit: 40 + t.string "value", limit: 6 + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "simple_captcha_data", ["key"], name: "idx_key" + +end diff --git a/test/dummy/db/test.sqlite3 b/test/dummy/db/test.sqlite3 new file mode 100644 index 0000000000000000000000000000000000000000..55e4ed313e7ae1fa8e7b7581e8cca40c973acdc7 GIT binary patch literal 6144 zcmeH|L2uJA6vyqPX(c2i;F1Fu&!bA3~^umWGnWI{p|nGe)5}>kyL_wJj)WUh=&>oWAuU$gpdWb3H8bv z(7;!n8|}Z`m8ONB{Mfkczot_%_6e;8p`=aMBFkX~>MR>Ay8|0} zsQ8DusEw^Tta1mz;N^(@CpcO2EIQ>`ySKmZ5PuvHe>xgD@6D$D*u!5hq|5j`{4BoY zGFi+;81aRI8DY#7Z}O(T(4yJkhq zji2q5Ct?p~I-7U6WqTg}7GB1zFMiARjY@2K%ZOsfGNy2f0ei(J54X4+2 iJ=g8_UANcoJuBXSZ2m-0v}ppGz+EQr$aHWu{qY}iLhu3r literal 0 HcmV?d00001 diff --git a/test/dummy/lib/assets/.keep b/test/dummy/lib/assets/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/log/.keep b/test/dummy/log/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/public/404.html b/test/dummy/public/404.html new file mode 100644 index 0000000..a0daa0c --- /dev/null +++ b/test/dummy/public/404.html @@ -0,0 +1,58 @@ + + + + The page you were looking for doesn't exist (404) + + + + + +
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+

If you are the application owner check the logs for more information.

+ + diff --git a/test/dummy/public/422.html b/test/dummy/public/422.html new file mode 100644 index 0000000..fbb4b84 --- /dev/null +++ b/test/dummy/public/422.html @@ -0,0 +1,58 @@ + + + + The change you wanted was rejected (422) + + + + + +
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

+ + diff --git a/test/dummy/public/500.html b/test/dummy/public/500.html new file mode 100644 index 0000000..e9052d3 --- /dev/null +++ b/test/dummy/public/500.html @@ -0,0 +1,57 @@ + + + + We're sorry, but something went wrong (500) + + + + + +
+

We're sorry, but something went wrong.

+
+

If you are the application owner check the logs for more information.

+ + diff --git a/test/dummy/public/favicon.ico b/test/dummy/public/favicon.ico new file mode 100644 index 0000000..e69de29 diff --git a/test/features/form_helper_test.rb b/test/features/form_helper_test.rb new file mode 100644 index 0000000..aedbb4b --- /dev/null +++ b/test/features/form_helper_test.rb @@ -0,0 +1,25 @@ +require 'test_helper' + +class FormHelperTest < ActionDispatch::IntegrationTest + include Capybara::DSL + + setup do + SimpleCaptcha.always_pass = false + end + + test 'displays captcha and passes' do + visit '/pages/form_tag' + assert_equal 1, SimpleCaptcha::SimpleCaptchaData.count + fill_in 'captcha', with: SimpleCaptcha::SimpleCaptchaData.first.value + click_on 'Save changes' + assert page.has_content? 'captcha valid' + end + + test 'captcha fails' do + visit '/pages/form_tag' + assert_equal 1, SimpleCaptcha::SimpleCaptchaData.count + fill_in 'captcha', with: 'something else' + click_on 'Save changes' + assert page.has_content? 'captcha not valid' + end +end diff --git a/test/simple_captcha_test.rb b/test/simple_captcha_test.rb deleted file mode 100644 index ec88ad1..0000000 --- a/test/simple_captcha_test.rb +++ /dev/null @@ -1,8 +0,0 @@ -require 'test/unit' - -class SimpleCaptchaTest < Test::Unit::TestCase - # Replace this with your real tests. - def test_this_plugin - flunk - end -end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..04e8888 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,18 @@ +# Configure Rails Environment +ENV["RAILS_ENV"] = "test" + +require File.expand_path("../dummy/config/environment.rb", __FILE__) +require "rails/test_help" + +require 'capybara/rails' +require 'pry' +Rails.backtrace_cleaner.remove_silencers! + +# Load support files +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } + +# Load fixtures from the engine +if ActiveSupport::TestCase.method_defined?(:fixture_path=) + ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__) +end + From 014243bdd48af85b2a2c72783a967ae297a1b6d1 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Mon, 4 Nov 2013 12:12:58 +0100 Subject: [PATCH 008/115] additional test with model based methods --- .../dummy/app/controllers/pages_controller.rb | 13 ++++++++++++ test/dummy/app/models/user.rb | 0 test/dummy/app/views/pages/model_tag.html.erb | 8 +++++++ test/dummy/config/routes.rb | 3 ++- test/features/form_helper_test.rb | 21 +++++++++++++++++++ 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 test/dummy/app/models/user.rb create mode 100644 test/dummy/app/views/pages/model_tag.html.erb diff --git a/test/dummy/app/controllers/pages_controller.rb b/test/dummy/app/controllers/pages_controller.rb index 59360a1..814f4dd 100644 --- a/test/dummy/app/controllers/pages_controller.rb +++ b/test/dummy/app/controllers/pages_controller.rb @@ -9,4 +9,17 @@ def form_tag_submit render text: 'captcha not valid!' end end + + def model_tag + @user = User.new + end + + def model_tag_submit + @model = User.new(params[:user]) + if @model.valid_with_captcha? + render text: 'captcha valid!' + else + render text: 'captcha not valid!' + end + end end diff --git a/test/dummy/app/models/user.rb b/test/dummy/app/models/user.rb new file mode 100644 index 0000000..e69de29 diff --git a/test/dummy/app/views/pages/model_tag.html.erb b/test/dummy/app/views/pages/model_tag.html.erb new file mode 100644 index 0000000..f0bf787 --- /dev/null +++ b/test/dummy/app/views/pages/model_tag.html.erb @@ -0,0 +1,8 @@ +

Pages#index

+ +<%= form_for @user, :url => '', :method => :post do |f| %> + <%=f.simple_captcha :label => 'Captcha' %> + <%= submit_tag %> +<% end %> + + diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb index 7eb13cd..30c4aee 100644 --- a/test/dummy/config/routes.rb +++ b/test/dummy/config/routes.rb @@ -2,5 +2,6 @@ get "pages/form_tag" post "pages/form_tag" => 'pages#form_tag_submit' - mount SimpleCaptcha::Engine => "/simple_captcha" + get "pages/model_tag" + post "pages/model_tag" => 'pages#model_tag_submit' end diff --git a/test/features/form_helper_test.rb b/test/features/form_helper_test.rb index aedbb4b..365aa13 100644 --- a/test/features/form_helper_test.rb +++ b/test/features/form_helper_test.rb @@ -1,5 +1,11 @@ require 'test_helper' +class User + include ActiveModel::Model + include SimpleCaptcha::ModelHelpers + apply_simple_captcha +end + class FormHelperTest < ActionDispatch::IntegrationTest include Capybara::DSL @@ -22,4 +28,19 @@ class FormHelperTest < ActionDispatch::IntegrationTest click_on 'Save changes' assert page.has_content? 'captcha not valid' end + + test 'also works with model based' do + visit '/pages/model_tag' + assert_equal 1, SimpleCaptcha::SimpleCaptchaData.count + fill_in 'user[captcha]', with: SimpleCaptcha::SimpleCaptchaData.first.value + click_on 'Save changes' + assert page.has_content? 'captcha valid' + end + test 'model based failure' do + visit '/pages/model_tag' + assert_equal 1, SimpleCaptcha::SimpleCaptchaData.count + fill_in 'user[captcha]', with: 'wrong captcha' + click_on 'Save changes' + assert page.has_content? 'captcha not valid' + end end From fcc38b258e50a084462cb77d522118fa90e42cb9 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Mon, 4 Nov 2013 12:20:41 +0100 Subject: [PATCH 009/115] travis.ci first try --- .travis.yml | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e470abd --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +--- +language: ruby +script: + - 'cd test/dummy && rake db:migrate db:test:prepare' + - rake test +rvm: + - '1.9.2' + - '2.0.0' From 35e4444ef7fce84e29676b7bcb40c90daa319e12 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Mon, 4 Nov 2013 12:22:39 +0100 Subject: [PATCH 010/115] ruby 1.9.3 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e470abd..8a7ae77 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,5 +4,5 @@ script: - 'cd test/dummy && rake db:migrate db:test:prepare' - rake test rvm: - - '1.9.2' + - '1.9.3' - '2.0.0' From f77b7e2b055ccfcf45f8f5cf459c426f954e6b0b Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Mon, 4 Nov 2013 12:28:29 +0100 Subject: [PATCH 011/115] Also added pg and mysql to test spec --- .travis.yml | 9 +++++++ Gemfile | 3 +++ test/dummy/config/database.yml | 44 ++++++++++++++++++---------------- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8a7ae77..40d50bc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,3 +6,12 @@ script: rvm: - '1.9.3' - '2.0.0' + +env: + - DB=sqlite + - DB=mysql + - DB=postgresql + +before_script: + - mysql -e 'create database myapp_test' + - psql -c 'create database myapp_test' -U postgres diff --git a/Gemfile b/Gemfile index f68a903..b5c92ab 100644 --- a/Gemfile +++ b/Gemfile @@ -2,3 +2,6 @@ source "https://rubygems.org" gemspec +gem 'mysql' +gem 'pg' +gem 'sqlite3' diff --git a/test/dummy/config/database.yml b/test/dummy/config/database.yml index 51a4dd4..72a0482 100644 --- a/test/dummy/config/database.yml +++ b/test/dummy/config/database.yml @@ -1,25 +1,29 @@ -# SQLite version 3.x -# gem install sqlite3 -# -# Ensure the SQLite 3 gem is defined in your Gemfile -# gem 'sqlite3' -development: - adapter: sqlite3 - database: db/development.sqlite3 - pool: 5 - timeout: 5000 -# Warning: The database defined as "test" will be erased and -# re-generated from your development database when you run "rake". -# Do not set this db to the same as development or production. -test: +sqlite: &sqlite adapter: sqlite3 - database: db/test.sqlite3 - pool: 5 - timeout: 5000 + database: db/<%= Rails.env %>.sqlite3 -production: - adapter: sqlite3 - database: db/production.sqlite3 +mysql: &mysql + adapter: mysql2 + username: root + password: + database: myapp_<%= Rails.env %> + +postgresql: &postgresql + adapter: postgresql + username: postgres + password: + database: myapp_<%= Rails.env %> + min_messages: ERROR + +defaults: &defaults pool: 5 timeout: 5000 + host: localhost + <<: *<%= ENV['DB'] || "sqlite" %> + +development: + <<: *defaults + +test: + <<: *defaults From 9751cb47d231cb2316e183509fea904cb64dc055 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Mon, 4 Nov 2013 12:39:33 +0100 Subject: [PATCH 012/115] mysql2 instead of mysql --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index b5c92ab..c848148 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,6 @@ source "https://rubygems.org" gemspec -gem 'mysql' +gem 'mysql2' gem 'pg' gem 'sqlite3' From 943815180f965ccbf16eaac2c3984f0f50859195 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Mon, 4 Nov 2013 21:12:29 +0100 Subject: [PATCH 013/115] Dummy app not static anymore: rake task for dynamic generation of dummy app --- .gitignore | 5 +- .travis.yml | 14 +++- Rakefile | 14 +++- gemfiles/Gemfile.default | 8 ++ gemfiles/Gemfile.rails32 | 6 ++ simple_captcha.gemspec | 6 +- test/dummy/app/assets/images/.keep | 0 .../app/assets/javascripts/application.js | 13 --- .../app/assets/stylesheets/application.css | 13 --- test/dummy/app/controllers/concerns/.keep | 0 test/dummy/app/helpers/application_helper.rb | 2 - test/dummy/app/mailers/.keep | 0 test/dummy/app/models/.keep | 0 test/dummy/app/models/concerns/.keep | 0 test/dummy/app/models/user.rb | 0 test/dummy/config/application.rb | 6 +- test/dummy/config/boot.rb | 3 +- .../dummy/config/initializers/secret_token.rb | 2 +- test/dummy/config/routes.rb | 59 ++++++++++++-- test/dummy/db/development.sqlite3 | Bin 6144 -> 0 bytes ...131104112427_create_simple_captcha_data.rb | 15 ---- test/dummy/db/schema.rb | 25 ------ test/dummy/db/test.sqlite3 | Bin 6144 -> 0 bytes .../simple_captcha/dummy/dummy_generator.rb | 75 ++++++++++++++++++ .../app/controllers/application_controller.rb | 6 ++ .../app/controllers/pages_controller.rb | 25 ++++++ .../views}/views/layouts/application.html.erb | 0 .../app/views}/views/pages/form_tag.html.erb | 0 .../app/views}/views/pages/model_tag.html.erb | 0 .../views/simple_captcha/_simple_captcha.erb | 0 .../dummy/templates/config/database.yml | 29 +++++++ .../dummy/templates/config/routes.rb | 6 ++ 32 files changed, 243 insertions(+), 89 deletions(-) create mode 100644 gemfiles/Gemfile.default create mode 100644 gemfiles/Gemfile.rails32 delete mode 100644 test/dummy/app/assets/images/.keep delete mode 100644 test/dummy/app/assets/javascripts/application.js delete mode 100644 test/dummy/app/assets/stylesheets/application.css delete mode 100644 test/dummy/app/controllers/concerns/.keep delete mode 100644 test/dummy/app/helpers/application_helper.rb delete mode 100644 test/dummy/app/mailers/.keep delete mode 100644 test/dummy/app/models/.keep delete mode 100644 test/dummy/app/models/concerns/.keep delete mode 100644 test/dummy/app/models/user.rb delete mode 100644 test/dummy/db/development.sqlite3 delete mode 100644 test/dummy/db/migrate/20131104112427_create_simple_captcha_data.rb delete mode 100644 test/dummy/db/schema.rb delete mode 100644 test/dummy/db/test.sqlite3 create mode 100644 test/lib/generators/simple_captcha/dummy/dummy_generator.rb create mode 100644 test/lib/generators/simple_captcha/dummy/templates/app/controllers/application_controller.rb create mode 100644 test/lib/generators/simple_captcha/dummy/templates/app/controllers/pages_controller.rb rename test/{dummy/app => lib/generators/simple_captcha/dummy/templates/app/views}/views/layouts/application.html.erb (100%) rename test/{dummy/app => lib/generators/simple_captcha/dummy/templates/app/views}/views/pages/form_tag.html.erb (100%) rename test/{dummy/app => lib/generators/simple_captcha/dummy/templates/app/views}/views/pages/model_tag.html.erb (100%) rename test/{dummy/app => lib/generators/simple_captcha/dummy/templates/app/views}/views/simple_captcha/_simple_captcha.erb (100%) create mode 100644 test/lib/generators/simple_captcha/dummy/templates/config/database.yml create mode 100644 test/lib/generators/simple_captcha/dummy/templates/config/routes.rb diff --git a/.gitignore b/.gitignore index 0c95927..56813f6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,5 @@ pkg/ Gemfile.lock .rspec -test/tmp -test/dummy/log/*.log -test/dummy/tmp/ -test/dummy/db/*sqlite +test/dummy .svn diff --git a/.travis.yml b/.travis.yml index 40d50bc..f4a672e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,10 +7,20 @@ rvm: - '1.9.3' - '2.0.0' +gemfile: + - gemfiles/Gemfile.default + - gemfiles/Gemfile.rails32 + env: - DB=sqlite - - DB=mysql - - DB=postgresql + # - DB=mysql + # - DB=postgresql + +matrix: + exclude: + - rvm: 1.9.3 + gemfile: gemfiles/Gemfile.rails32 + env: DB=sqlite before_script: - mysql -e 'create database myapp_test' diff --git a/Rakefile b/Rakefile index 7dbf1a6..896ae61 100644 --- a/Rakefile +++ b/Rakefile @@ -15,7 +15,19 @@ RDoc::Task.new(:rdoc) do |rdoc| end APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__) -load 'rails/tasks/engine.rake' +if File.exists? APP_RAKEFILE + load 'rails/tasks/engine.rake' +end + + +desc 'Setup dummy Rails app for test purpose' +task :setup_dummy_app do + require 'rails' + require 'simple_captcha' + require File.expand_path('../test/lib/generators/simple_captcha/dummy/dummy_generator', __FILE__) + + SimpleCaptcha::DummyGenerator.start %w(--quiet) +end diff --git a/gemfiles/Gemfile.default b/gemfiles/Gemfile.default new file mode 100644 index 0000000..4e52ac6 --- /dev/null +++ b/gemfiles/Gemfile.default @@ -0,0 +1,8 @@ +source "https://rubygems.org" + +gemspec :path => '../' + +gem 'mysql2' +gem 'pg' +gem 'sqlite3' +gem 'rails', '~> 4.0' diff --git a/gemfiles/Gemfile.rails32 b/gemfiles/Gemfile.rails32 new file mode 100644 index 0000000..e6373b8 --- /dev/null +++ b/gemfiles/Gemfile.rails32 @@ -0,0 +1,6 @@ +source "https://rubygems.org" + +gemspec :path => '../' + +gem 'sqlite3' +gem 'rails', '~> 3.2' diff --git a/simple_captcha.gemspec b/simple_captcha.gemspec index 1c59250..501d66a 100644 --- a/simple_captcha.gemspec +++ b/simple_captcha.gemspec @@ -7,10 +7,10 @@ Gem::Specification.new do |s| s.version = SimpleCaptcha::VERSION.dup s.platform = Gem::Platform::RUBY s.summary = "SimpleCaptcha is the simplest and a robust captcha plugin." - s.description = "SimpleCaptcha is available to be used with Rails 3 or above and also it provides the backward compatibility with previous versions of Rails." + s.description = "SimpleCaptcha is available to be used with Rails 3 + 4 or above and also it provides the backward compatibility with previous versions of Rails." s.authors = ["Pavlo Galeta", "Igor Galeta", 'Stefan Wienert'] - s.email = "galeta.igor@gmail.com" - s.homepage = "http://github.com/izzm/simple-captcha" + s.email = "stwienert@gmail.com" + s.homepage = "http://github.com/pludoni/simple-captcha" s.files = Dir["{lib}/**/*"] + ["Rakefile", "README.rdoc"] s.extra_rdoc_files = ["README.rdoc"] diff --git a/test/dummy/app/assets/images/.keep b/test/dummy/app/assets/images/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/dummy/app/assets/javascripts/application.js b/test/dummy/app/assets/javascripts/application.js deleted file mode 100644 index 5bc2e1c..0000000 --- a/test/dummy/app/assets/javascripts/application.js +++ /dev/null @@ -1,13 +0,0 @@ -// This is a manifest file that'll be compiled into application.js, which will include all the files -// listed below. -// -// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, -// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. -// -// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the -// compiled file. -// -// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details -// about supported directives. -// -//= require_tree . diff --git a/test/dummy/app/assets/stylesheets/application.css b/test/dummy/app/assets/stylesheets/application.css deleted file mode 100644 index 3192ec8..0000000 --- a/test/dummy/app/assets/stylesheets/application.css +++ /dev/null @@ -1,13 +0,0 @@ -/* - * This is a manifest file that'll be compiled into application.css, which will include all the files - * listed below. - * - * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, - * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. - * - * You're free to add application-wide styles to this file and they'll appear at the top of the - * compiled file, but it's generally better to create a new file per style scope. - * - *= require_self - *= require_tree . - */ diff --git a/test/dummy/app/controllers/concerns/.keep b/test/dummy/app/controllers/concerns/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/dummy/app/helpers/application_helper.rb b/test/dummy/app/helpers/application_helper.rb deleted file mode 100644 index de6be79..0000000 --- a/test/dummy/app/helpers/application_helper.rb +++ /dev/null @@ -1,2 +0,0 @@ -module ApplicationHelper -end diff --git a/test/dummy/app/mailers/.keep b/test/dummy/app/mailers/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/dummy/app/models/.keep b/test/dummy/app/models/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/dummy/app/models/concerns/.keep b/test/dummy/app/models/concerns/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/dummy/app/models/user.rb b/test/dummy/app/models/user.rb deleted file mode 100644 index e69de29..0000000 diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index 6fe074b..4cd6683 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -2,8 +2,9 @@ require 'rails/all' -Bundler.require(*Rails.groups) -require "simple_captcha" +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(:default, Rails.env) module Dummy class Application < Rails::Application @@ -20,4 +21,3 @@ class Application < Rails::Application # config.i18n.default_locale = :de end end - diff --git a/test/dummy/config/boot.rb b/test/dummy/config/boot.rb index ef36047..3596736 100644 --- a/test/dummy/config/boot.rb +++ b/test/dummy/config/boot.rb @@ -1,5 +1,4 @@ # Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) -$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) diff --git a/test/dummy/config/initializers/secret_token.rb b/test/dummy/config/initializers/secret_token.rb index 6578b84..7ccb405 100644 --- a/test/dummy/config/initializers/secret_token.rb +++ b/test/dummy/config/initializers/secret_token.rb @@ -9,4 +9,4 @@ # Make sure your secret_key_base is kept private # if you're sharing your code publicly. -Dummy::Application.config.secret_key_base = 'dc42d1e5f6b46ed4067ca613f3ed86c2235a3fe6131553d25f475d7007768154310479912a5847dd18a65ea0f5672ee662359001d6f7fa25a42382a02e948310' +Dummy::Application.config.secret_key_base = '3148ae1cfa150b3aa3c294c988dfda9e1f34df4726ce8141c73cfda1b71a139ab8b1a0068f8ec195e74ae076c60b5bbbcfeb3b7d208cfac775edf8b48ed43f32' diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb index 30c4aee..268779b 100644 --- a/test/dummy/config/routes.rb +++ b/test/dummy/config/routes.rb @@ -1,7 +1,56 @@ -Rails.application.routes.draw do +Dummy::Application.routes.draw do + # The priority is based upon order of creation: first created -> highest priority. + # See how all your routes lay out with "rake routes". - get "pages/form_tag" - post "pages/form_tag" => 'pages#form_tag_submit' - get "pages/model_tag" - post "pages/model_tag" => 'pages#model_tag_submit' + # You can have the root of your site routed with "root" + # root 'welcome#index' + + # Example of regular route: + # get 'products/:id' => 'catalog#view' + + # Example of named route that can be invoked with purchase_url(id: product.id) + # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase + + # Example resource route (maps HTTP verbs to controller actions automatically): + # resources :products + + # Example resource route with options: + # resources :products do + # member do + # get 'short' + # post 'toggle' + # end + # + # collection do + # get 'sold' + # end + # end + + # Example resource route with sub-resources: + # resources :products do + # resources :comments, :sales + # resource :seller + # end + + # Example resource route with more complex sub-resources: + # resources :products do + # resources :comments + # resources :sales do + # get 'recent', on: :collection + # end + # end + + # Example resource route with concerns: + # concern :toggleable do + # post 'toggle' + # end + # resources :posts, concerns: :toggleable + # resources :photos, concerns: :toggleable + + # Example resource route within a namespace: + # namespace :admin do + # # Directs /admin/products/* to Admin::ProductsController + # # (app/controllers/admin/products_controller.rb) + # resources :products + # end end diff --git a/test/dummy/db/development.sqlite3 b/test/dummy/db/development.sqlite3 deleted file mode 100644 index c3790a4ea756dc54ebf38d438b08365ce749b008..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6144 zcmeH}UvJYe5WwxaekEm8*0;Z@PtHx2vv0HR#J&dpvWX1vuLt5ajPMo z$~#|$vp-MngQ>L)K9PpyIQVC98FM?=8}g}c#J(+K6)`B#ci*`q zdNk@E_C^!>-ks3i*dO*i2yy6oKJ|t$#)H8=y(p0`MGBPCX1C43v=q~YWNYK|+!m%% zXc+}UGYT-JR!|FNi&;L|H1k!X(y(5(@Tzsukwu~aR*;3KG8RFszNSK}vn1OxkfOq| z*FPSw`*hp#qH*P@dE1sU&0q({=eS|DAd!ccoXfsj8B|J)%L}dtU-Ri49Pl+!o}W!j z{vr5`7y^dCohI-AS9qswJGR~K+IFYgd2tWw#pEx7&xj#l2;5}?j|j(`#~Cd? 40 - t.string :value, :limit => 6 - t.timestamps - end - - add_index :simple_captcha_data, :key, :name => "idx_key" - end - - def self.down - drop_table :simple_captcha_data - end -end diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb deleted file mode 100644 index 5aae878..0000000 --- a/test/dummy/db/schema.rb +++ /dev/null @@ -1,25 +0,0 @@ -# encoding: UTF-8 -# This file is auto-generated from the current state of the database. Instead -# of editing this file, please use the migrations feature of Active Record to -# incrementally modify your database, and then regenerate this schema definition. -# -# Note that this schema.rb definition is the authoritative source for your -# database schema. If you need to create the application database on another -# system, you should be using db:schema:load, not running all the migrations -# from scratch. The latter is a flawed and unsustainable approach (the more migrations -# you'll amass, the slower it'll run and the greater likelihood for issues). -# -# It's strongly recommended that you check this file into your version control system. - -ActiveRecord::Schema.define(version: 20131104112427) do - - create_table "simple_captcha_data", force: true do |t| - t.string "key", limit: 40 - t.string "value", limit: 6 - t.datetime "created_at" - t.datetime "updated_at" - end - - add_index "simple_captcha_data", ["key"], name: "idx_key" - -end diff --git a/test/dummy/db/test.sqlite3 b/test/dummy/db/test.sqlite3 deleted file mode 100644 index 55e4ed313e7ae1fa8e7b7581e8cca40c973acdc7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6144 zcmeH|L2uJA6vyqPX(c2i;F1Fu&!bA3~^umWGnWI{p|nGe)5}>kyL_wJj)WUh=&>oWAuU$gpdWb3H8bv z(7;!n8|}Z`m8ONB{Mfkczot_%_6e;8p`=aMBFkX~>MR>Ay8|0} zsQ8DusEw^Tta1mz;N^(@CpcO2EIQ>`ySKmZ5PuvHe>xgD@6D$D*u!5hq|5j`{4BoY zGFi+;81aRI8DY#7Z}O(T(4yJkhq zji2q5Ct?p~I-7U6WqTg}7GB1zFMiARjY@2K%ZOsfGNy2f0ei(J54X4+2 iJ=g8_UANcoJuBXSZ2m-0v}ppGz+EQr$aHWu{qY}iLhu3r diff --git a/test/lib/generators/simple_captcha/dummy/dummy_generator.rb b/test/lib/generators/simple_captcha/dummy/dummy_generator.rb new file mode 100644 index 0000000..6acc2ff --- /dev/null +++ b/test/lib/generators/simple_captcha/dummy/dummy_generator.rb @@ -0,0 +1,75 @@ +require 'rails/generators' +require 'rails/generators/rails/app/app_generator' + +# stolen from https://github.com/radar/forem/blob/master/spec/lib/generators/forem/dummy/dummy_generator.rb +module SimpleCaptcha + class DummyGenerator < Rails::Generators::Base + desc "Creates dummy test Rails application" + + def self.source_paths + paths = self.superclass.source_paths + paths << File.expand_path('../templates', __FILE__) + paths.flatten + end + + PASSTHROUGH_OPTIONS = [ + :skip_active_record, :skip_javascript, :database, :javascript, :quiet, :pretend, :force, :skip + ] + + def generate_test_dummy + opts = (options || {}).slice(*PASSTHROUGH_OPTIONS) + opts[:force] = true + opts[:skip_bundle] = true + opts[:old_style_hash] = true + + invoke Rails::Generators::AppGenerator, [ File.expand_path(dummy_path, destination_root) ], opts + run "rails generate simple_captcha" + end + + def test_dummy_clean + inside dummy_path do + remove_file ".gitignore" + remove_file "doc" + remove_file "Gemfile" + remove_file "lib/tasks" + remove_file "app" + remove_file "public/index.html" + remove_file "public/robots.txt" + remove_file "README" + remove_file "test" + remove_file "vendor" + end + end + + def test_dummy_config + directory "app", "#{dummy_path}/app" + copy_file "config/database.yml", "#{dummy_path}/config/database.yml", :force => true + template "config/routes.rb", "#{dummy_path}/config/routes.rb", :force => true + end + + protected + + def dummy_path + 'test/dummy' + end + + def module_name + 'Dummy' + end + + def application_definition + @application_definition ||= begin + dummy_application_path = File.expand_path("#{dummy_path}/config/application.rb", destination_root) + unless options[:pretend] || !File.exists?(dummy_application_path) + contents = File.read(dummy_application_path) + contents[(contents.index("module #{module_name}"))..-1] + end + end + end + alias :store_application_definition! :application_definition + + def gemfile_path + '../../../../Gemfile' + end + end +end diff --git a/test/lib/generators/simple_captcha/dummy/templates/app/controllers/application_controller.rb b/test/lib/generators/simple_captcha/dummy/templates/app/controllers/application_controller.rb new file mode 100644 index 0000000..6c1698d --- /dev/null +++ b/test/lib/generators/simple_captcha/dummy/templates/app/controllers/application_controller.rb @@ -0,0 +1,6 @@ +class ApplicationController < ActionController::Base + # Prevent CSRF attacks by raising an exception. + # For APIs, you may want to use :null_session instead. + protect_from_forgery with: :exception + include SimpleCaptcha::ControllerHelpers +end diff --git a/test/lib/generators/simple_captcha/dummy/templates/app/controllers/pages_controller.rb b/test/lib/generators/simple_captcha/dummy/templates/app/controllers/pages_controller.rb new file mode 100644 index 0000000..814f4dd --- /dev/null +++ b/test/lib/generators/simple_captcha/dummy/templates/app/controllers/pages_controller.rb @@ -0,0 +1,25 @@ +class PagesController < ApplicationController + def form_tag + end + + def form_tag_submit + if simple_captcha_valid? + render text: 'captcha valid!' + else + render text: 'captcha not valid!' + end + end + + def model_tag + @user = User.new + end + + def model_tag_submit + @model = User.new(params[:user]) + if @model.valid_with_captcha? + render text: 'captcha valid!' + else + render text: 'captcha not valid!' + end + end +end diff --git a/test/dummy/app/views/layouts/application.html.erb b/test/lib/generators/simple_captcha/dummy/templates/app/views/views/layouts/application.html.erb similarity index 100% rename from test/dummy/app/views/layouts/application.html.erb rename to test/lib/generators/simple_captcha/dummy/templates/app/views/views/layouts/application.html.erb diff --git a/test/dummy/app/views/pages/form_tag.html.erb b/test/lib/generators/simple_captcha/dummy/templates/app/views/views/pages/form_tag.html.erb similarity index 100% rename from test/dummy/app/views/pages/form_tag.html.erb rename to test/lib/generators/simple_captcha/dummy/templates/app/views/views/pages/form_tag.html.erb diff --git a/test/dummy/app/views/pages/model_tag.html.erb b/test/lib/generators/simple_captcha/dummy/templates/app/views/views/pages/model_tag.html.erb similarity index 100% rename from test/dummy/app/views/pages/model_tag.html.erb rename to test/lib/generators/simple_captcha/dummy/templates/app/views/views/pages/model_tag.html.erb diff --git a/test/dummy/app/views/simple_captcha/_simple_captcha.erb b/test/lib/generators/simple_captcha/dummy/templates/app/views/views/simple_captcha/_simple_captcha.erb similarity index 100% rename from test/dummy/app/views/simple_captcha/_simple_captcha.erb rename to test/lib/generators/simple_captcha/dummy/templates/app/views/views/simple_captcha/_simple_captcha.erb diff --git a/test/lib/generators/simple_captcha/dummy/templates/config/database.yml b/test/lib/generators/simple_captcha/dummy/templates/config/database.yml new file mode 100644 index 0000000..72a0482 --- /dev/null +++ b/test/lib/generators/simple_captcha/dummy/templates/config/database.yml @@ -0,0 +1,29 @@ + +sqlite: &sqlite + adapter: sqlite3 + database: db/<%= Rails.env %>.sqlite3 + +mysql: &mysql + adapter: mysql2 + username: root + password: + database: myapp_<%= Rails.env %> + +postgresql: &postgresql + adapter: postgresql + username: postgres + password: + database: myapp_<%= Rails.env %> + min_messages: ERROR + +defaults: &defaults + pool: 5 + timeout: 5000 + host: localhost + <<: *<%= ENV['DB'] || "sqlite" %> + +development: + <<: *defaults + +test: + <<: *defaults diff --git a/test/lib/generators/simple_captcha/dummy/templates/config/routes.rb b/test/lib/generators/simple_captcha/dummy/templates/config/routes.rb new file mode 100644 index 0000000..08eb576 --- /dev/null +++ b/test/lib/generators/simple_captcha/dummy/templates/config/routes.rb @@ -0,0 +1,6 @@ +Rails.application.routes.draw do + get "pages/form_tag" + post "pages/form_tag" => 'pages#form_tag_submit' + get "pages/model_tag" + post "pages/model_tag" => 'pages#model_tag_submit' +end From 3eddeb1b77fc9fca4a92070d534b1fbc5e377a9a Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Mon, 4 Nov 2013 21:22:16 +0100 Subject: [PATCH 014/115] removed dummy app from VCS --- test/dummy/README.rdoc | 28 ------- test/dummy/Rakefile | 6 -- .../app/controllers/application_controller.rb | 6 -- .../dummy/app/controllers/pages_controller.rb | 25 ------ test/dummy/bin/bundle | 3 - test/dummy/bin/rails | 4 - test/dummy/bin/rake | 4 - test/dummy/config.ru | 4 - test/dummy/config/application.rb | 23 ------ test/dummy/config/boot.rb | 4 - test/dummy/config/database.yml | 29 ------- test/dummy/config/environment.rb | 5 -- test/dummy/config/environments/development.rb | 29 ------- test/dummy/config/environments/production.rb | 80 ------------------- test/dummy/config/environments/test.rb | 36 --------- .../initializers/backtrace_silencers.rb | 7 -- .../initializers/filter_parameter_logging.rb | 4 - test/dummy/config/initializers/inflections.rb | 16 ---- test/dummy/config/initializers/mime_types.rb | 5 -- .../dummy/config/initializers/secret_token.rb | 12 --- .../config/initializers/session_store.rb | 3 - .../config/initializers/wrap_parameters.rb | 14 ---- test/dummy/config/locales/en.yml | 23 ------ test/dummy/config/routes.rb | 56 ------------- test/dummy/lib/assets/.keep | 0 test/dummy/log/.keep | 0 test/dummy/public/404.html | 58 -------------- test/dummy/public/422.html | 58 -------------- test/dummy/public/500.html | 57 ------------- test/dummy/public/favicon.ico | 0 .../simple_captcha/dummy/dummy_generator.rb | 38 ++++----- .../{views => }/layouts/application.html.erb | 0 .../views/{views => }/pages/form_tag.html.erb | 0 .../{views => }/pages/model_tag.html.erb | 0 .../simple_captcha/_simple_captcha.erb | 0 35 files changed, 19 insertions(+), 618 deletions(-) delete mode 100644 test/dummy/README.rdoc delete mode 100644 test/dummy/Rakefile delete mode 100644 test/dummy/app/controllers/application_controller.rb delete mode 100644 test/dummy/app/controllers/pages_controller.rb delete mode 100755 test/dummy/bin/bundle delete mode 100755 test/dummy/bin/rails delete mode 100755 test/dummy/bin/rake delete mode 100644 test/dummy/config.ru delete mode 100644 test/dummy/config/application.rb delete mode 100644 test/dummy/config/boot.rb delete mode 100644 test/dummy/config/database.yml delete mode 100644 test/dummy/config/environment.rb delete mode 100644 test/dummy/config/environments/development.rb delete mode 100644 test/dummy/config/environments/production.rb delete mode 100644 test/dummy/config/environments/test.rb delete mode 100644 test/dummy/config/initializers/backtrace_silencers.rb delete mode 100644 test/dummy/config/initializers/filter_parameter_logging.rb delete mode 100644 test/dummy/config/initializers/inflections.rb delete mode 100644 test/dummy/config/initializers/mime_types.rb delete mode 100644 test/dummy/config/initializers/secret_token.rb delete mode 100644 test/dummy/config/initializers/session_store.rb delete mode 100644 test/dummy/config/initializers/wrap_parameters.rb delete mode 100644 test/dummy/config/locales/en.yml delete mode 100644 test/dummy/config/routes.rb delete mode 100644 test/dummy/lib/assets/.keep delete mode 100644 test/dummy/log/.keep delete mode 100644 test/dummy/public/404.html delete mode 100644 test/dummy/public/422.html delete mode 100644 test/dummy/public/500.html delete mode 100644 test/dummy/public/favicon.ico rename test/lib/generators/simple_captcha/dummy/templates/app/views/{views => }/layouts/application.html.erb (100%) rename test/lib/generators/simple_captcha/dummy/templates/app/views/{views => }/pages/form_tag.html.erb (100%) rename test/lib/generators/simple_captcha/dummy/templates/app/views/{views => }/pages/model_tag.html.erb (100%) rename test/lib/generators/simple_captcha/dummy/templates/app/views/{views => }/simple_captcha/_simple_captcha.erb (100%) diff --git a/test/dummy/README.rdoc b/test/dummy/README.rdoc deleted file mode 100644 index dd4e97e..0000000 --- a/test/dummy/README.rdoc +++ /dev/null @@ -1,28 +0,0 @@ -== README - -This README would normally document whatever steps are necessary to get the -application up and running. - -Things you may want to cover: - -* Ruby version - -* System dependencies - -* Configuration - -* Database creation - -* Database initialization - -* How to run the test suite - -* Services (job queues, cache servers, search engines, etc.) - -* Deployment instructions - -* ... - - -Please feel free to use a different markup language if you do not plan to run -rake doc:app. diff --git a/test/dummy/Rakefile b/test/dummy/Rakefile deleted file mode 100644 index 4135d7a..0000000 --- a/test/dummy/Rakefile +++ /dev/null @@ -1,6 +0,0 @@ -# Add your own tasks in files placed in lib/tasks ending in .rake, -# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. - -require File.expand_path('../config/application', __FILE__) - -Dummy::Application.load_tasks diff --git a/test/dummy/app/controllers/application_controller.rb b/test/dummy/app/controllers/application_controller.rb deleted file mode 100644 index 6c1698d..0000000 --- a/test/dummy/app/controllers/application_controller.rb +++ /dev/null @@ -1,6 +0,0 @@ -class ApplicationController < ActionController::Base - # Prevent CSRF attacks by raising an exception. - # For APIs, you may want to use :null_session instead. - protect_from_forgery with: :exception - include SimpleCaptcha::ControllerHelpers -end diff --git a/test/dummy/app/controllers/pages_controller.rb b/test/dummy/app/controllers/pages_controller.rb deleted file mode 100644 index 814f4dd..0000000 --- a/test/dummy/app/controllers/pages_controller.rb +++ /dev/null @@ -1,25 +0,0 @@ -class PagesController < ApplicationController - def form_tag - end - - def form_tag_submit - if simple_captcha_valid? - render text: 'captcha valid!' - else - render text: 'captcha not valid!' - end - end - - def model_tag - @user = User.new - end - - def model_tag_submit - @model = User.new(params[:user]) - if @model.valid_with_captcha? - render text: 'captcha valid!' - else - render text: 'captcha not valid!' - end - end -end diff --git a/test/dummy/bin/bundle b/test/dummy/bin/bundle deleted file mode 100755 index 66e9889..0000000 --- a/test/dummy/bin/bundle +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env ruby -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -load Gem.bin_path('bundler', 'bundle') diff --git a/test/dummy/bin/rails b/test/dummy/bin/rails deleted file mode 100755 index 728cd85..0000000 --- a/test/dummy/bin/rails +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env ruby -APP_PATH = File.expand_path('../../config/application', __FILE__) -require_relative '../config/boot' -require 'rails/commands' diff --git a/test/dummy/bin/rake b/test/dummy/bin/rake deleted file mode 100755 index 1724048..0000000 --- a/test/dummy/bin/rake +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env ruby -require_relative '../config/boot' -require 'rake' -Rake.application.run diff --git a/test/dummy/config.ru b/test/dummy/config.ru deleted file mode 100644 index 5bc2a61..0000000 --- a/test/dummy/config.ru +++ /dev/null @@ -1,4 +0,0 @@ -# This file is used by Rack-based servers to start the application. - -require ::File.expand_path('../config/environment', __FILE__) -run Rails.application diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb deleted file mode 100644 index 4cd6683..0000000 --- a/test/dummy/config/application.rb +++ /dev/null @@ -1,23 +0,0 @@ -require File.expand_path('../boot', __FILE__) - -require 'rails/all' - -# Require the gems listed in Gemfile, including any gems -# you've limited to :test, :development, or :production. -Bundler.require(:default, Rails.env) - -module Dummy - class Application < Rails::Application - # Settings in config/environments/* take precedence over those specified here. - # Application configuration should go into files in config/initializers - # -- all .rb files in that directory are automatically loaded. - - # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. - # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. - # config.time_zone = 'Central Time (US & Canada)' - - # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. - # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] - # config.i18n.default_locale = :de - end -end diff --git a/test/dummy/config/boot.rb b/test/dummy/config/boot.rb deleted file mode 100644 index 3596736..0000000 --- a/test/dummy/config/boot.rb +++ /dev/null @@ -1,4 +0,0 @@ -# Set up gems listed in the Gemfile. -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) - -require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) diff --git a/test/dummy/config/database.yml b/test/dummy/config/database.yml deleted file mode 100644 index 72a0482..0000000 --- a/test/dummy/config/database.yml +++ /dev/null @@ -1,29 +0,0 @@ - -sqlite: &sqlite - adapter: sqlite3 - database: db/<%= Rails.env %>.sqlite3 - -mysql: &mysql - adapter: mysql2 - username: root - password: - database: myapp_<%= Rails.env %> - -postgresql: &postgresql - adapter: postgresql - username: postgres - password: - database: myapp_<%= Rails.env %> - min_messages: ERROR - -defaults: &defaults - pool: 5 - timeout: 5000 - host: localhost - <<: *<%= ENV['DB'] || "sqlite" %> - -development: - <<: *defaults - -test: - <<: *defaults diff --git a/test/dummy/config/environment.rb b/test/dummy/config/environment.rb deleted file mode 100644 index 10e0cad..0000000 --- a/test/dummy/config/environment.rb +++ /dev/null @@ -1,5 +0,0 @@ -# Load the Rails application. -require File.expand_path('../application', __FILE__) - -# Initialize the Rails application. -Dummy::Application.initialize! diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb deleted file mode 100644 index 9d26e12..0000000 --- a/test/dummy/config/environments/development.rb +++ /dev/null @@ -1,29 +0,0 @@ -Dummy::Application.configure do - # Settings specified here will take precedence over those in config/application.rb. - - # In the development environment your application's code is reloaded on - # every request. This slows down response time but is perfect for development - # since you don't have to restart the web server when you make code changes. - config.cache_classes = false - - # Do not eager load code on boot. - config.eager_load = false - - # Show full error reports and disable caching. - config.consider_all_requests_local = true - config.action_controller.perform_caching = false - - # Don't care if the mailer can't send. - config.action_mailer.raise_delivery_errors = false - - # Print deprecation notices to the Rails logger. - config.active_support.deprecation = :log - - # Raise an error on page load if there are pending migrations - config.active_record.migration_error = :page_load - - # Debug mode disables concatenation and preprocessing of assets. - # This option may cause significant delays in view rendering with a large - # number of complex assets. - config.assets.debug = true -end diff --git a/test/dummy/config/environments/production.rb b/test/dummy/config/environments/production.rb deleted file mode 100644 index b690b1c..0000000 --- a/test/dummy/config/environments/production.rb +++ /dev/null @@ -1,80 +0,0 @@ -Dummy::Application.configure do - # Settings specified here will take precedence over those in config/application.rb. - - # Code is not reloaded between requests. - config.cache_classes = true - - # Eager load code on boot. This eager loads most of Rails and - # your application in memory, allowing both thread web servers - # and those relying on copy on write to perform better. - # Rake tasks automatically ignore this option for performance. - config.eager_load = true - - # Full error reports are disabled and caching is turned on. - config.consider_all_requests_local = false - config.action_controller.perform_caching = true - - # Enable Rack::Cache to put a simple HTTP cache in front of your application - # Add `rack-cache` to your Gemfile before enabling this. - # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. - # config.action_dispatch.rack_cache = true - - # Disable Rails's static asset server (Apache or nginx will already do this). - config.serve_static_assets = false - - # Compress JavaScripts and CSS. - config.assets.js_compressor = :uglifier - # config.assets.css_compressor = :sass - - # Do not fallback to assets pipeline if a precompiled asset is missed. - config.assets.compile = false - - # Generate digests for assets URLs. - config.assets.digest = true - - # Version of your assets, change this if you want to expire all your assets. - config.assets.version = '1.0' - - # Specifies the header that your server uses for sending files. - # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache - # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx - - # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - # config.force_ssl = true - - # Set to :debug to see everything in the log. - config.log_level = :info - - # Prepend all log lines with the following tags. - # config.log_tags = [ :subdomain, :uuid ] - - # Use a different logger for distributed setups. - # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) - - # Use a different cache store in production. - # config.cache_store = :mem_cache_store - - # Enable serving of images, stylesheets, and JavaScripts from an asset server. - # config.action_controller.asset_host = "http://assets.example.com" - - # Precompile additional assets. - # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. - # config.assets.precompile += %w( search.js ) - - # Ignore bad email addresses and do not raise email delivery errors. - # Set this to true and configure the email server for immediate delivery to raise delivery errors. - # config.action_mailer.raise_delivery_errors = false - - # Enable locale fallbacks for I18n (makes lookups for any locale fall back to - # the I18n.default_locale when a translation can not be found). - config.i18n.fallbacks = true - - # Send deprecation notices to registered listeners. - config.active_support.deprecation = :notify - - # Disable automatic flushing of the log to improve performance. - # config.autoflush_log = false - - # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = ::Logger::Formatter.new -end diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb deleted file mode 100644 index afbc0ae..0000000 --- a/test/dummy/config/environments/test.rb +++ /dev/null @@ -1,36 +0,0 @@ -Dummy::Application.configure do - # Settings specified here will take precedence over those in config/application.rb. - - # The test environment is used exclusively to run your application's - # test suite. You never need to work with it otherwise. Remember that - # your test database is "scratch space" for the test suite and is wiped - # and recreated between test runs. Don't rely on the data there! - config.cache_classes = true - - # Do not eager load code on boot. This avoids loading your whole application - # just for the purpose of running a single test. If you are using a tool that - # preloads Rails for running tests, you may have to set it to true. - config.eager_load = false - - # Configure static asset server for tests with Cache-Control for performance. - config.serve_static_assets = true - config.static_cache_control = "public, max-age=3600" - - # Show full error reports and disable caching. - config.consider_all_requests_local = true - config.action_controller.perform_caching = false - - # Raise exceptions instead of rendering exception templates. - config.action_dispatch.show_exceptions = false - - # Disable request forgery protection in test environment. - config.action_controller.allow_forgery_protection = false - - # Tell Action Mailer not to deliver emails to the real world. - # The :test delivery method accumulates sent emails in the - # ActionMailer::Base.deliveries array. - config.action_mailer.delivery_method = :test - - # Print deprecation notices to the stderr. - config.active_support.deprecation = :stderr -end diff --git a/test/dummy/config/initializers/backtrace_silencers.rb b/test/dummy/config/initializers/backtrace_silencers.rb deleted file mode 100644 index 59385cd..0000000 --- a/test/dummy/config/initializers/backtrace_silencers.rb +++ /dev/null @@ -1,7 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. -# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } - -# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. -# Rails.backtrace_cleaner.remove_silencers! diff --git a/test/dummy/config/initializers/filter_parameter_logging.rb b/test/dummy/config/initializers/filter_parameter_logging.rb deleted file mode 100644 index 4a994e1..0000000 --- a/test/dummy/config/initializers/filter_parameter_logging.rb +++ /dev/null @@ -1,4 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Configure sensitive parameters which will be filtered from the log file. -Rails.application.config.filter_parameters += [:password] diff --git a/test/dummy/config/initializers/inflections.rb b/test/dummy/config/initializers/inflections.rb deleted file mode 100644 index ac033bf..0000000 --- a/test/dummy/config/initializers/inflections.rb +++ /dev/null @@ -1,16 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Add new inflection rules using the following format. Inflections -# are locale specific, and you may define rules for as many different -# locales as you wish. All of these examples are active by default: -# ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.plural /^(ox)$/i, '\1en' -# inflect.singular /^(ox)en/i, '\1' -# inflect.irregular 'person', 'people' -# inflect.uncountable %w( fish sheep ) -# end - -# These inflection rules are supported but not enabled by default: -# ActiveSupport::Inflector.inflections(:en) do |inflect| -# inflect.acronym 'RESTful' -# end diff --git a/test/dummy/config/initializers/mime_types.rb b/test/dummy/config/initializers/mime_types.rb deleted file mode 100644 index 72aca7e..0000000 --- a/test/dummy/config/initializers/mime_types.rb +++ /dev/null @@ -1,5 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Add new mime types for use in respond_to blocks: -# Mime::Type.register "text/richtext", :rtf -# Mime::Type.register_alias "text/html", :iphone diff --git a/test/dummy/config/initializers/secret_token.rb b/test/dummy/config/initializers/secret_token.rb deleted file mode 100644 index 7ccb405..0000000 --- a/test/dummy/config/initializers/secret_token.rb +++ /dev/null @@ -1,12 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# Your secret key is used for verifying the integrity of signed cookies. -# If you change this key, all old signed cookies will become invalid! - -# Make sure the secret is at least 30 characters and all random, -# no regular words or you'll be exposed to dictionary attacks. -# You can use `rake secret` to generate a secure secret key. - -# Make sure your secret_key_base is kept private -# if you're sharing your code publicly. -Dummy::Application.config.secret_key_base = '3148ae1cfa150b3aa3c294c988dfda9e1f34df4726ce8141c73cfda1b71a139ab8b1a0068f8ec195e74ae076c60b5bbbcfeb3b7d208cfac775edf8b48ed43f32' diff --git a/test/dummy/config/initializers/session_store.rb b/test/dummy/config/initializers/session_store.rb deleted file mode 100644 index 155f7b0..0000000 --- a/test/dummy/config/initializers/session_store.rb +++ /dev/null @@ -1,3 +0,0 @@ -# Be sure to restart your server when you modify this file. - -Dummy::Application.config.session_store :cookie_store, key: '_dummy_session' diff --git a/test/dummy/config/initializers/wrap_parameters.rb b/test/dummy/config/initializers/wrap_parameters.rb deleted file mode 100644 index 33725e9..0000000 --- a/test/dummy/config/initializers/wrap_parameters.rb +++ /dev/null @@ -1,14 +0,0 @@ -# Be sure to restart your server when you modify this file. - -# This file contains settings for ActionController::ParamsWrapper which -# is enabled by default. - -# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. -ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] if respond_to?(:wrap_parameters) -end - -# To enable root element in JSON for ActiveRecord objects. -# ActiveSupport.on_load(:active_record) do -# self.include_root_in_json = true -# end diff --git a/test/dummy/config/locales/en.yml b/test/dummy/config/locales/en.yml deleted file mode 100644 index 0653957..0000000 --- a/test/dummy/config/locales/en.yml +++ /dev/null @@ -1,23 +0,0 @@ -# Files in the config/locales directory are used for internationalization -# and are automatically loaded by Rails. If you want to use locales other -# than English, add the necessary files in this directory. -# -# To use the locales, use `I18n.t`: -# -# I18n.t 'hello' -# -# In views, this is aliased to just `t`: -# -# <%= t('hello') %> -# -# To use a different locale, set it with `I18n.locale`: -# -# I18n.locale = :es -# -# This would use the information in config/locales/es.yml. -# -# To learn more, please read the Rails Internationalization guide -# available at http://guides.rubyonrails.org/i18n.html. - -en: - hello: "Hello world" diff --git a/test/dummy/config/routes.rb b/test/dummy/config/routes.rb deleted file mode 100644 index 268779b..0000000 --- a/test/dummy/config/routes.rb +++ /dev/null @@ -1,56 +0,0 @@ -Dummy::Application.routes.draw do - # The priority is based upon order of creation: first created -> highest priority. - # See how all your routes lay out with "rake routes". - - # You can have the root of your site routed with "root" - # root 'welcome#index' - - # Example of regular route: - # get 'products/:id' => 'catalog#view' - - # Example of named route that can be invoked with purchase_url(id: product.id) - # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase - - # Example resource route (maps HTTP verbs to controller actions automatically): - # resources :products - - # Example resource route with options: - # resources :products do - # member do - # get 'short' - # post 'toggle' - # end - # - # collection do - # get 'sold' - # end - # end - - # Example resource route with sub-resources: - # resources :products do - # resources :comments, :sales - # resource :seller - # end - - # Example resource route with more complex sub-resources: - # resources :products do - # resources :comments - # resources :sales do - # get 'recent', on: :collection - # end - # end - - # Example resource route with concerns: - # concern :toggleable do - # post 'toggle' - # end - # resources :posts, concerns: :toggleable - # resources :photos, concerns: :toggleable - - # Example resource route within a namespace: - # namespace :admin do - # # Directs /admin/products/* to Admin::ProductsController - # # (app/controllers/admin/products_controller.rb) - # resources :products - # end -end diff --git a/test/dummy/lib/assets/.keep b/test/dummy/lib/assets/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/dummy/log/.keep b/test/dummy/log/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/dummy/public/404.html b/test/dummy/public/404.html deleted file mode 100644 index a0daa0c..0000000 --- a/test/dummy/public/404.html +++ /dev/null @@ -1,58 +0,0 @@ - - - - The page you were looking for doesn't exist (404) - - - - - -
-

The page you were looking for doesn't exist.

-

You may have mistyped the address or the page may have moved.

-
-

If you are the application owner check the logs for more information.

- - diff --git a/test/dummy/public/422.html b/test/dummy/public/422.html deleted file mode 100644 index fbb4b84..0000000 --- a/test/dummy/public/422.html +++ /dev/null @@ -1,58 +0,0 @@ - - - - The change you wanted was rejected (422) - - - - - -
-

The change you wanted was rejected.

-

Maybe you tried to change something you didn't have access to.

-
-

If you are the application owner check the logs for more information.

- - diff --git a/test/dummy/public/500.html b/test/dummy/public/500.html deleted file mode 100644 index e9052d3..0000000 --- a/test/dummy/public/500.html +++ /dev/null @@ -1,57 +0,0 @@ - - - - We're sorry, but something went wrong (500) - - - - - -
-

We're sorry, but something went wrong.

-
-

If you are the application owner check the logs for more information.

- - diff --git a/test/dummy/public/favicon.ico b/test/dummy/public/favicon.ico deleted file mode 100644 index e69de29..0000000 diff --git a/test/lib/generators/simple_captcha/dummy/dummy_generator.rb b/test/lib/generators/simple_captcha/dummy/dummy_generator.rb index 6acc2ff..e6819b4 100644 --- a/test/lib/generators/simple_captcha/dummy/dummy_generator.rb +++ b/test/lib/generators/simple_captcha/dummy/dummy_generator.rb @@ -49,27 +49,27 @@ def test_dummy_config protected - def dummy_path - 'test/dummy' - end + def dummy_path + 'test/dummy' + end - def module_name - 'Dummy' - end + def module_name + 'Dummy' + end - def application_definition - @application_definition ||= begin - dummy_application_path = File.expand_path("#{dummy_path}/config/application.rb", destination_root) - unless options[:pretend] || !File.exists?(dummy_application_path) - contents = File.read(dummy_application_path) - contents[(contents.index("module #{module_name}"))..-1] - end - end - end - alias :store_application_definition! :application_definition + def application_definition + @application_definition ||= begin + dummy_application_path = File.expand_path("#{dummy_path}/config/application.rb", destination_root) + unless options[:pretend] || !File.exists?(dummy_application_path) + contents = File.read(dummy_application_path) + contents[(contents.index("module #{module_name}"))..-1] + end + end + end + alias :store_application_definition! :application_definition - def gemfile_path - '../../../../Gemfile' - end + def gemfile_path + '../../../../Gemfile' + end end end diff --git a/test/lib/generators/simple_captcha/dummy/templates/app/views/views/layouts/application.html.erb b/test/lib/generators/simple_captcha/dummy/templates/app/views/layouts/application.html.erb similarity index 100% rename from test/lib/generators/simple_captcha/dummy/templates/app/views/views/layouts/application.html.erb rename to test/lib/generators/simple_captcha/dummy/templates/app/views/layouts/application.html.erb diff --git a/test/lib/generators/simple_captcha/dummy/templates/app/views/views/pages/form_tag.html.erb b/test/lib/generators/simple_captcha/dummy/templates/app/views/pages/form_tag.html.erb similarity index 100% rename from test/lib/generators/simple_captcha/dummy/templates/app/views/views/pages/form_tag.html.erb rename to test/lib/generators/simple_captcha/dummy/templates/app/views/pages/form_tag.html.erb diff --git a/test/lib/generators/simple_captcha/dummy/templates/app/views/views/pages/model_tag.html.erb b/test/lib/generators/simple_captcha/dummy/templates/app/views/pages/model_tag.html.erb similarity index 100% rename from test/lib/generators/simple_captcha/dummy/templates/app/views/views/pages/model_tag.html.erb rename to test/lib/generators/simple_captcha/dummy/templates/app/views/pages/model_tag.html.erb diff --git a/test/lib/generators/simple_captcha/dummy/templates/app/views/views/simple_captcha/_simple_captcha.erb b/test/lib/generators/simple_captcha/dummy/templates/app/views/simple_captcha/_simple_captcha.erb similarity index 100% rename from test/lib/generators/simple_captcha/dummy/templates/app/views/views/simple_captcha/_simple_captcha.erb rename to test/lib/generators/simple_captcha/dummy/templates/app/views/simple_captcha/_simple_captcha.erb From 264db563b39fac112dfa7a3a28ffaef77df80770 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Mon, 4 Nov 2013 21:25:41 +0100 Subject: [PATCH 015/115] finalized dummy rake task and travis build command --- .travis.yml | 3 +++ Rakefile | 21 ++++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index f4a672e..d055dff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,3 +25,6 @@ matrix: before_script: - mysql -e 'create database myapp_test' - psql -c 'create database myapp_test' -U postgres + - rake dummy:setup + - rake app:db:migrate + - rake app:db:migrate RAILS_ENV=test diff --git a/Rakefile b/Rakefile index 896ae61..2232273 100644 --- a/Rakefile +++ b/Rakefile @@ -19,18 +19,25 @@ if File.exists? APP_RAKEFILE load 'rails/tasks/engine.rake' end +namespace :dummy do + desc 'Setup dummy Rails app for test purpose' + task :setup do + require 'rails' + require 'simple_captcha' + require File.expand_path('../test/lib/generators/simple_captcha/dummy/dummy_generator', __FILE__) + SimpleCaptcha::DummyGenerator.start %w(--quiet) + end + + desc 'destroy dummy Rails app under test/dummy' + task :destroy do + FileUtils.rm_rf "test/dummy" if File.exists?("test/dummy") + end -desc 'Setup dummy Rails app for test purpose' -task :setup_dummy_app do - require 'rails' - require 'simple_captcha' - require File.expand_path('../test/lib/generators/simple_captcha/dummy/dummy_generator', __FILE__) - - SimpleCaptcha::DummyGenerator.start %w(--quiet) end + Bundler::GemHelper.install_tasks require 'rake/testtask' From e70d34d25e77292b713831c709bbd80220ac001e Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Mon, 4 Nov 2013 22:28:36 +0100 Subject: [PATCH 016/115] Formtastic version 2.2 and Rails 3.2 tested and supported with new custom input. --- .travis.yml | 16 +++--------- Gemfile | 7 +++-- gemfiles/Gemfile.default | 8 ------ gemfiles/Gemfile.rails32 | 6 ----- lib/simple_captcha/engine.rb | 6 +---- lib/simple_captcha/formtastic.rb | 16 +++++++----- lib/simple_captcha/simple_captcha_data.rb | 5 +++- test/features/form_helper_test.rb | 6 ----- test/features/formtastic_test.rb | 26 +++++++++++++++++++ .../simple_captcha/dummy/dummy_generator.rb | 2 +- .../app/controllers/pages_controller.rb | 13 ++++++++++ .../app/views/pages/formtastic_tag.html.erb | 8 ++++++ .../dummy/templates/config/routes.rb | 2 ++ test/model.rb | 24 +++++++++++++++++ test/test_helper.rb | 1 + 15 files changed, 99 insertions(+), 47 deletions(-) delete mode 100644 gemfiles/Gemfile.default delete mode 100644 gemfiles/Gemfile.rails32 create mode 100644 test/features/formtastic_test.rb create mode 100644 test/lib/generators/simple_captcha/dummy/templates/app/views/pages/formtastic_tag.html.erb create mode 100644 test/model.rb diff --git a/.travis.yml b/.travis.yml index d055dff..0a9dd00 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,20 +7,12 @@ rvm: - '1.9.3' - '2.0.0' -gemfile: - - gemfiles/Gemfile.default - - gemfiles/Gemfile.rails32 - env: - - DB=sqlite - # - DB=mysql - # - DB=postgresql + - DB=sqlite RAILS='~> 4.0' + - DB=mysql RAILS='~> 4.0' + - DB=sqlite FORMTASTIC='~> 2.2' RAILS='~> 3.2' + - DB=sqlite FORMTASTIC='~> 2.2' RAILS='~> 4.0' -matrix: - exclude: - - rvm: 1.9.3 - gemfile: gemfiles/Gemfile.rails32 - env: DB=sqlite before_script: - mysql -e 'create database myapp_test' diff --git a/Gemfile b/Gemfile index c848148..b50716b 100644 --- a/Gemfile +++ b/Gemfile @@ -2,6 +2,9 @@ source "https://rubygems.org" gemspec -gem 'mysql2' -gem 'pg' gem 'sqlite3' +gem 'rails', ENV['RAILS'] || '~> 4.0' + +if ENV['FORMTASTIC'] + gem 'formtastic', ENV['FORMTASTIC'] +end diff --git a/gemfiles/Gemfile.default b/gemfiles/Gemfile.default deleted file mode 100644 index 4e52ac6..0000000 --- a/gemfiles/Gemfile.default +++ /dev/null @@ -1,8 +0,0 @@ -source "https://rubygems.org" - -gemspec :path => '../' - -gem 'mysql2' -gem 'pg' -gem 'sqlite3' -gem 'rails', '~> 4.0' diff --git a/gemfiles/Gemfile.rails32 b/gemfiles/Gemfile.rails32 deleted file mode 100644 index e6373b8..0000000 --- a/gemfiles/Gemfile.rails32 +++ /dev/null @@ -1,6 +0,0 @@ -source "https://rubygems.org" - -gemspec :path => '../' - -gem 'sqlite3' -gem 'rails', '~> 3.2' diff --git a/lib/simple_captcha/engine.rb b/lib/simple_captcha/engine.rb index 7a7ecfd..5f1382c 100644 --- a/lib/simple_captcha/engine.rb +++ b/lib/simple_captcha/engine.rb @@ -15,11 +15,7 @@ class Engine < ::Rails::Engine ActionView::Helpers::FormBuilder.send(:include, SimpleCaptcha::FormBuilder) if Object.const_defined?("Formtastic") - if Formtastic.const_defined?("Helpers") - Formtastic::Helpers::FormHelper.builder = SimpleCaptcha::CustomFormBuilder - else - Formtastic::SemanticFormHelper.builder = SimpleCaptcha::CustomFormBuilder - end + require 'simple_captcha/formtastic' end end diff --git a/lib/simple_captcha/formtastic.rb b/lib/simple_captcha/formtastic.rb index a149ca9..1f4efd6 100644 --- a/lib/simple_captcha/formtastic.rb +++ b/lib/simple_captcha/formtastic.rb @@ -1,11 +1,15 @@ -module SimpleCaptcha - class CustomFormBuilder < (defined?(::Formtastic::FormBuilder) ? Formtastic::FormBuilder : ::Formtastic::SemanticFormBuilder) - - private +if defined? Formtastic + require 'formtastic/version' + if Formtastic::VERSION < '2.2' + raise 'Only Formtastic Version 2.2 or greater is supported by SimpleCaptcha' + end - def simple_captcha_input(method, options) + class SimpleCaptchaInput + include Formtastic::Inputs::Base + def to_html options.update :object => sanitized_object_name - self.send(:show_simple_captcha, options) + builder.send(:show_simple_captcha, options) end end + end diff --git a/lib/simple_captcha/simple_captcha_data.rb b/lib/simple_captcha/simple_captcha_data.rb index 37b5b28..12bf89f 100644 --- a/lib/simple_captcha/simple_captcha_data.rb +++ b/lib/simple_captcha/simple_captcha_data.rb @@ -8,11 +8,14 @@ class SimpleCaptchaData < ::ActiveRecord::Base else set_table_name "simple_captcha_data" end + if defined? attr_protected + attr_protected + end class << self def get_data(key) - data = where(key: key).first || new(key: key) + where(key: key).first || new(key: key) end def remove_data(key) diff --git a/test/features/form_helper_test.rb b/test/features/form_helper_test.rb index 365aa13..d9e3b4f 100644 --- a/test/features/form_helper_test.rb +++ b/test/features/form_helper_test.rb @@ -1,11 +1,5 @@ require 'test_helper' -class User - include ActiveModel::Model - include SimpleCaptcha::ModelHelpers - apply_simple_captcha -end - class FormHelperTest < ActionDispatch::IntegrationTest include Capybara::DSL diff --git a/test/features/formtastic_test.rb b/test/features/formtastic_test.rb new file mode 100644 index 0000000..e824538 --- /dev/null +++ b/test/features/formtastic_test.rb @@ -0,0 +1,26 @@ +if defined? Formtastic + require 'test_helper' + class FormtasticTest < ActionDispatch::IntegrationTest + include Capybara::DSL + + setup do + SimpleCaptcha.always_pass = false + end + + test 'displays captcha and passes' do + visit '/pages/formtastic_tag' + assert_equal 1, SimpleCaptcha::SimpleCaptchaData.count + fill_in 'user[captcha]', with: SimpleCaptcha::SimpleCaptchaData.first.value + find('input[type=submit]').click + assert page.has_content? 'captcha valid' + end + + test 'captcha fails' do + visit '/pages/formtastic_tag' + assert_equal 1, SimpleCaptcha::SimpleCaptchaData.count + fill_in 'user[captcha]', with: 'something else' + find('input[type=submit]').click + assert page.has_no_content? 'captcha not valid' + end + end +end diff --git a/test/lib/generators/simple_captcha/dummy/dummy_generator.rb b/test/lib/generators/simple_captcha/dummy/dummy_generator.rb index e6819b4..d753485 100644 --- a/test/lib/generators/simple_captcha/dummy/dummy_generator.rb +++ b/test/lib/generators/simple_captcha/dummy/dummy_generator.rb @@ -17,7 +17,7 @@ def self.source_paths ] def generate_test_dummy - opts = (options || {}).slice(*PASSTHROUGH_OPTIONS) + opts = (options || {}).slice(*PASSTHROUGH_OPTIONS) || {} # rails 3.2 ? -> slice is nil opts[:force] = true opts[:skip_bundle] = true opts[:old_style_hash] = true diff --git a/test/lib/generators/simple_captcha/dummy/templates/app/controllers/pages_controller.rb b/test/lib/generators/simple_captcha/dummy/templates/app/controllers/pages_controller.rb index 814f4dd..7824f56 100644 --- a/test/lib/generators/simple_captcha/dummy/templates/app/controllers/pages_controller.rb +++ b/test/lib/generators/simple_captcha/dummy/templates/app/controllers/pages_controller.rb @@ -22,4 +22,17 @@ def model_tag_submit render text: 'captcha not valid!' end end + + def formtastic_tag + @user = User.new + end + + def formtastic_tag_submit + @user = User.new(params[:user]) + if @user.valid_with_captcha? + render text: 'captcha valid!' + else + render :formtastic_tag + end + end end diff --git a/test/lib/generators/simple_captcha/dummy/templates/app/views/pages/formtastic_tag.html.erb b/test/lib/generators/simple_captcha/dummy/templates/app/views/pages/formtastic_tag.html.erb new file mode 100644 index 0000000..d688478 --- /dev/null +++ b/test/lib/generators/simple_captcha/dummy/templates/app/views/pages/formtastic_tag.html.erb @@ -0,0 +1,8 @@ + +

Pages#index

+ +<%= semantic_form_for @user, url: '', :method => :post do |f| %> + <%= f.input :capcha, as: :simple_captcha %> + <%= f.submit %> +<% end %> + diff --git a/test/lib/generators/simple_captcha/dummy/templates/config/routes.rb b/test/lib/generators/simple_captcha/dummy/templates/config/routes.rb index 08eb576..c77c724 100644 --- a/test/lib/generators/simple_captcha/dummy/templates/config/routes.rb +++ b/test/lib/generators/simple_captcha/dummy/templates/config/routes.rb @@ -3,4 +3,6 @@ post "pages/form_tag" => 'pages#form_tag_submit' get "pages/model_tag" post "pages/model_tag" => 'pages#model_tag_submit' + get "pages/formtastic_tag" + post "pages/formtastic_tag" => 'pages#formtastic_tag_submit' end diff --git a/test/model.rb b/test/model.rb new file mode 100644 index 0000000..90aad13 --- /dev/null +++ b/test/model.rb @@ -0,0 +1,24 @@ + +if Rails.version > '4.0' + class User + include ActiveModel::Model + include SimpleCaptcha::ModelHelpers + apply_simple_captcha + end +else + class User + include ActiveModel::Validations + include ActiveModel::Conversion + extend ActiveModel::Naming + include SimpleCaptcha::ModelHelpers + include ActiveModel::MassAssignmentSecurity + apply_simple_captcha + attr_accessible :key + def persisted?; false; end + def initialize(params={}) + params.each do |attr, value| + self.public_send("#{attr}=", value) + end if params + end + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 04e8888..26b9e35 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -6,6 +6,7 @@ require 'capybara/rails' require 'pry' +require 'model' Rails.backtrace_cleaner.remove_silencers! # Load support files From 03f99e73046f6bde0da03d9e2b02623768336c80 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Mon, 4 Nov 2013 22:32:10 +0100 Subject: [PATCH 017/115] attr_protected only for Rails 3 --- README.rdoc | 11 +++++++++++ lib/simple_captcha/simple_captcha_data.rb | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.rdoc b/README.rdoc index 854656c..35e6fc5 100644 --- a/README.rdoc +++ b/README.rdoc @@ -211,6 +211,17 @@ You can change the CSS of the SimpleCaptcha DOM elements as per your need in thi default: "Secret Code did not match with the Image" user: "The secret Image and code were different" +==Contributing + +For testing, generate a temporary Rails dummy app inside test: + + rake dummy:setup + rake app:db:migrate + rake app:db:migrate RAILS_ENV=test + rake test + +Please add test cases when adding new functionality. I started with some basic example integration tests for a very basic coverage. + ==Who's who? Enjoy the simplest captcha implementation. diff --git a/lib/simple_captcha/simple_captcha_data.rb b/lib/simple_captcha/simple_captcha_data.rb index 12bf89f..703d130 100644 --- a/lib/simple_captcha/simple_captcha_data.rb +++ b/lib/simple_captcha/simple_captcha_data.rb @@ -8,7 +8,7 @@ class SimpleCaptchaData < ::ActiveRecord::Base else set_table_name "simple_captcha_data" end - if defined? attr_protected + if ::ActiveRecord::VERSION::MAJOR == 3 and defined? attr_protected attr_protected end From 133946578053123b73ddf33831a847657e413951 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Mon, 4 Nov 2013 22:54:42 +0100 Subject: [PATCH 018/115] mysql support --- .travis.yml | 7 +++++++ Gemfile | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/.travis.yml b/.travis.yml index 0a9dd00..59d0354 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,13 @@ env: - DB=sqlite FORMTASTIC='~> 2.2' RAILS='~> 3.2' - DB=sqlite FORMTASTIC='~> 2.2' RAILS='~> 4.0' +matrix: + exclude: + - rvm: 1.9.3 + env: DB=mysql RAILS='~> 4.0' + - rvm: 1.9.3 + env: DB=sqlite FORMTASTIC='~> 2.2' RAILS='~> 4.0' + before_script: - mysql -e 'create database myapp_test' diff --git a/Gemfile b/Gemfile index b50716b..4c59138 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,10 @@ gemspec gem 'sqlite3' gem 'rails', ENV['RAILS'] || '~> 4.0' +if ENV['DB'] and ENV['DB']['mysql'] + gem 'mysql2' +end + if ENV['FORMTASTIC'] gem 'formtastic', ENV['FORMTASTIC'] end From cc68800aa90ee077c3cc375f14681f9c16a53151 Mon Sep 17 00:00:00 2001 From: freemanoid Date: Sat, 30 Nov 2013 23:40:55 +0300 Subject: [PATCH 019/115] Add refresh button --- README.rdoc | 1 + lib/generators/templates/partial.erb | 4 +++ lib/simple_captcha/middleware.rb | 40 ++++++++++++++++++++++------ lib/simple_captcha/view.rb | 35 +++++++++++++++++------- 4 files changed, 63 insertions(+), 17 deletions(-) diff --git a/README.rdoc b/README.rdoc index 35e6fc5..c19e4b3 100644 --- a/README.rdoc +++ b/README.rdoc @@ -14,6 +14,7 @@ backward compatibility with previous versions of Rails. * Implementation is as easy as just writing a single line in your view. "<%= show_simple_captcha %>" within the 'form' tags. * Flexible DOM and CSS handling(There is a separate view partial for rednering SimpleCaptcha DOM elements). * Automated removal of 1 hour old unmatched simple_captcha data. +* Refresh button to refresh captcha ==Requirements diff --git a/lib/generators/templates/partial.erb b/lib/generators/templates/partial.erb index 3ad8590..37bcd8a 100644 --- a/lib/generators/templates/partial.erb +++ b/lib/generators/templates/partial.erb @@ -34,4 +34,8 @@
<%%= simple_captcha_options[:label] %>
+ +
+ <%%= simple_captcha_options[:refresh_button] %> +
diff --git a/lib/simple_captcha/middleware.rb b/lib/simple_captcha/middleware.rb index cd10455..7430505 100644 --- a/lib/simple_captcha/middleware.rb +++ b/lib/simple_captcha/middleware.rb @@ -2,7 +2,8 @@ module SimpleCaptcha class Middleware include SimpleCaptcha::ImageHelpers - + include SimpleCaptcha::ViewHelper + DEFAULT_SEND_FILE_OPTIONS = { :type => 'application/octet-stream'.freeze, :disposition => 'attachment'.freeze, @@ -15,7 +16,12 @@ def initialize(app, options={}) def call(env) # :nodoc: if env["REQUEST_METHOD"] == "GET" && captcha_path?(env['PATH_INFO']) - make_image(env) + request = Rack::Request.new(env) + if request.params.present? && request.params['code'].present? + make_image(env) + else + refresh_code(env) + end else @app.call(env) end @@ -26,17 +32,17 @@ def make_image(env, headers = {}, status = 404) request = Rack::Request.new(env) code = request.params["code"] body = [] - - if !code.blank? && Utils::simple_captcha_value(code) + + if Utils::simple_captcha_value(code) #status, headers, body = @app.call(env) #status = 200 #body = generate_simple_captcha_image(code) #headers['Content-Type'] = 'image/jpeg' - - return send_file(generate_simple_captcha_image(code), :type => 'image/jpeg', :disposition => 'inline', :filename => 'simple_captcha.jpg') + + send_file(generate_simple_captcha_image(code), :type => 'image/jpeg', :disposition => 'inline', :filename => 'simple_captcha.jpg') + else + [status, headers, body] end - - [status, headers, body] end def captcha_path?(request_path) @@ -54,5 +60,23 @@ def send_file(path, options = {}) [status, headers, response_body] end + + def refresh_code(env) + request = Rack::Request.new(env) + + request.session.delete :captcha + key = simple_captcha_key(nil, request) + options = {} + options[:field_value] = set_simple_captcha_data(key, options) + url = simple_captcha_image_url(key, options) + + status = 200 + body = %Q{ + $("#captcha_image").attr('src', '#{url}'); + $("#captcha_key").attr('value', '#{key}'); + } + headers = {'Content-Type' => 'text/javascript; charset=utf-8', "Content-Disposition" => "inline; filename='captcha.js'", "Content-Length" => body.length.to_s} + [status, headers, [body]] + end end end diff --git a/lib/simple_captcha/view.rb b/lib/simple_captcha/view.rb index fc57080..0363d85 100644 --- a/lib/simple_captcha/view.rb +++ b/lib/simple_captcha/view.rb @@ -49,7 +49,8 @@ def show_simple_captcha(options={}) defaults = { :image => simple_captcha_image(key, options), :label => options[:label] || I18n.t('simple_captcha.label'), - :field => simple_captcha_field(options) + :field => simple_captcha_field(options), + :refresh_button => simple_captcha_refresh_button(options) } render :partial => 'simple_captcha/simple_captcha', :locals => { :simple_captcha_options => defaults } @@ -63,10 +64,18 @@ def simple_captcha_image(simple_captcha_key, options = {}) query = defaults.collect{ |key, value| "#{key}=#{value}" }.join('&') url = "#{ENV['RAILS_RELATIVE_URL_ROOT']}/simple_captcha?code=#{simple_captcha_key}&#{query}" - - tag('img', :src => url, :alt => 'captcha') + + tag('img', :src => url, :alt => 'captcha', :id => 'captcha_image') end - + + def simple_captcha_image_url(simple_captcha_key, options = {}) + defaults = {} + defaults[:time] = options[:time] || Time.now.to_i + + query = defaults.collect{ |key, value| "#{key}=#{value}" }.join('&') + "#{ENV['RAILS_RELATIVE_URL_ROOT']}/simple_captcha?code=#{simple_captcha_key}&#{query}" + end + def simple_captcha_field(options={}) html = {:autocomplete => 'off', :required => 'required'} html.merge!(options[:input_html] || {}) @@ -81,6 +90,14 @@ def simple_captcha_field(options={}) end end + def simple_captcha_refresh_button(options={}) + html = {remote: true} + html.merge!(options[:refresh_button_html] || {}) + text = options[:refresh_button_text] || :refresh + + link_to(text, "#{ENV['RAILS_RELATIVE_URL_ROOT']}/simple_captcha", html) + end + def set_simple_captcha_data(key, options={}) code_type = options[:code_type] @@ -103,13 +120,13 @@ def generate_simple_captcha_data(code) return value end - - def simple_captcha_key(key_name = nil) + + def simple_captcha_key(key_name = nil, request = request) if key_name.nil? - session[:captcha] ||= SimpleCaptcha::Utils.generate_key(session[:id].to_s, 'captcha') + request.session[:captcha] ||= SimpleCaptcha::Utils.generate_key(request.session[:id].to_s, 'captcha') else - SimpleCaptcha::Utils.generate_key(session[:id].to_s, key_name) + SimpleCaptcha::Utils.generate_key(request.session[:id].to_s, key_name) end - end + end end end From 1b396cd371563fe127575653a18890c8b12edba4 Mon Sep 17 00:00:00 2001 From: Alexandr Elhovenko Date: Sun, 1 Dec 2013 14:32:51 +0200 Subject: [PATCH 020/115] Correct contributing part of README according to travis config As I can see we _always_ need to use dummy app for testing. --- README.rdoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.rdoc b/README.rdoc index 35e6fc5..868c30c 100644 --- a/README.rdoc +++ b/README.rdoc @@ -218,6 +218,8 @@ For testing, generate a temporary Rails dummy app inside test: rake dummy:setup rake app:db:migrate rake app:db:migrate RAILS_ENV=test + export BUNDLE_GEMFILE=$PWD/Gemfile + cd test/dummy && rake db:migrate db:test:prepare rake test Please add test cases when adding new functionality. I started with some basic example integration tests for a very basic coverage. From 08f977c5f2b07958593f5dea67b03bdd7d307b89 Mon Sep 17 00:00:00 2001 From: freemanoid Date: Sun, 1 Dec 2013 16:33:10 +0300 Subject: [PATCH 021/115] Add boot.rb with custom Gemfile path --- test/lib/generators/simple_captcha/dummy/dummy_generator.rb | 1 + .../generators/simple_captcha/dummy/templates/config/boot.rb | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 test/lib/generators/simple_captcha/dummy/templates/config/boot.rb diff --git a/test/lib/generators/simple_captcha/dummy/dummy_generator.rb b/test/lib/generators/simple_captcha/dummy/dummy_generator.rb index d753485..782221d 100644 --- a/test/lib/generators/simple_captcha/dummy/dummy_generator.rb +++ b/test/lib/generators/simple_captcha/dummy/dummy_generator.rb @@ -45,6 +45,7 @@ def test_dummy_config directory "app", "#{dummy_path}/app" copy_file "config/database.yml", "#{dummy_path}/config/database.yml", :force => true template "config/routes.rb", "#{dummy_path}/config/routes.rb", :force => true + copy_file "config/boot.rb", "#{dummy_path}/config/boot.rb", :force => true end protected diff --git a/test/lib/generators/simple_captcha/dummy/templates/config/boot.rb b/test/lib/generators/simple_captcha/dummy/templates/config/boot.rb new file mode 100644 index 0000000..acb11b9 --- /dev/null +++ b/test/lib/generators/simple_captcha/dummy/templates/config/boot.rb @@ -0,0 +1,4 @@ +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) + +require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) From 161fe63562c84619ad43020f76d9180ebe14ce90 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Mon, 2 Dec 2013 00:15:16 +0100 Subject: [PATCH 022/115] renamed gem to pludoni-simple_captcha for now --- Gemfile | 2 +- Rakefile | 2 +- pludoni-simple_captcha.gemspec | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 pludoni-simple_captcha.gemspec diff --git a/Gemfile b/Gemfile index 4c59138..1402fd8 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source "https://rubygems.org" -gemspec +gemspec :name => 'pludoni-simple_captcha' gem 'sqlite3' gem 'rails', ENV['RAILS'] || '~> 4.0' diff --git a/Rakefile b/Rakefile index 2232273..2c0a93c 100644 --- a/Rakefile +++ b/Rakefile @@ -38,7 +38,7 @@ end -Bundler::GemHelper.install_tasks +Bundler::GemHelper.install_tasks :name => 'pludoni-simple_captcha' require 'rake/testtask' diff --git a/pludoni-simple_captcha.gemspec b/pludoni-simple_captcha.gemspec new file mode 100644 index 0000000..b9cbb32 --- /dev/null +++ b/pludoni-simple_captcha.gemspec @@ -0,0 +1,24 @@ +# -*- encoding: utf-8 -*- +$:.push File.expand_path("../lib", __FILE__) +require "simple_captcha/version" + +Gem::Specification.new do |s| + s.name = "pludoni-simple_captcha" + s.version = SimpleCaptcha::VERSION.dup + s.platform = Gem::Platform::RUBY + s.summary = "SimpleCaptcha is the simplest and a robust captcha plugin." + s.description = "SimpleCaptcha is available to be used with Rails 3 + 4 or above and also it provides the backward compatibility with previous versions of Rails." + s.authors = ["Pavlo Galeta", "Igor Galeta", 'Stefan Wienert'] + s.email = "stwienert@gmail.com" + s.homepage = "http://github.com/pludoni/simple-captcha" + + s.files = Dir["{lib}/**/*"] + ["Rakefile", "README.rdoc"] + s.extra_rdoc_files = ["README.rdoc"] + s.require_paths = ["lib"] + + s.add_dependency 'rails', '>= 3.1' + s.add_development_dependency "sqlite3" + s.add_development_dependency "capybara-mechanize" + s.add_development_dependency "pry" + +end From d0852427674136dcd69802e48e6f081c37adf060 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Mon, 2 Dec 2013 00:25:55 +0100 Subject: [PATCH 023/115] renamed to simple_captcha2 --- Gemfile | 2 +- README.rdoc | 15 +++++++++------ Rakefile | 2 +- ...ple_captcha.gemspec => simple_captcha2.gemspec | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) rename pludoni-simple_captcha.gemspec => simple_captcha2.gemspec (96%) diff --git a/Gemfile b/Gemfile index 1402fd8..850ef6b 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source "https://rubygems.org" -gemspec :name => 'pludoni-simple_captcha' +gemspec :name => 'simple_captcha2' gem 'sqlite3' gem 'rails', ENV['RAILS'] || '~> 4.0' diff --git a/README.rdoc b/README.rdoc index 868c30c..1193da4 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,18 +1,18 @@ -=SimpleCaptcha +=SimpleCaptcha2 -SimpleCaptcha is the simplest and a robust captcha plugin. Its implementation requires +SimpleCaptcha(2) is the simplest and a robust captcha plugin. Its implementation requires adding up a single line in views and in controllers/models. -SimpleCaptcha is available to be used with Rails 3 or above and also it provides the -backward compatibility with previous versions of Rails. +SimpleCaptcha2 is available to be used with Rails 3 + 4. +This is a fork of the popular Rubygem simple_captcha which got abandoned. ==Features -* Zero FileSystem usage(secret code moved to db-store and image storage removed). +* Zero FileSystem usage (secret code moved to db-store and image storage removed). * Provides various image styles. * Provides three level of complexity of images. * Works absolutely fine in distributed environment(session and db based implementation works fine in distributed environment). * Implementation is as easy as just writing a single line in your view. "<%= show_simple_captcha %>" within the 'form' tags. -* Flexible DOM and CSS handling(There is a separate view partial for rednering SimpleCaptcha DOM elements). +* Flexible DOM and CSS handling(There is a separate view partial for rendering SimpleCaptcha DOM elements). * Automated removal of 1 hour old unmatched simple_captcha data. ==Requirements @@ -24,6 +24,9 @@ backward compatibility with previous versions of Rails. ==Installation + gem 'simple_captcha2' + + # OR gem 'simple_captcha', :git => 'git://github.com/pludoni/simple-captcha.git' diff --git a/Rakefile b/Rakefile index 2c0a93c..df1c7b4 100644 --- a/Rakefile +++ b/Rakefile @@ -38,7 +38,7 @@ end -Bundler::GemHelper.install_tasks :name => 'pludoni-simple_captcha' +Bundler::GemHelper.install_tasks :name => 'simple_captcha2' require 'rake/testtask' diff --git a/pludoni-simple_captcha.gemspec b/simple_captcha2.gemspec similarity index 96% rename from pludoni-simple_captcha.gemspec rename to simple_captcha2.gemspec index b9cbb32..932ce19 100644 --- a/pludoni-simple_captcha.gemspec +++ b/simple_captcha2.gemspec @@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__) require "simple_captcha/version" Gem::Specification.new do |s| - s.name = "pludoni-simple_captcha" + s.name = "simple_captcha2" s.version = SimpleCaptcha::VERSION.dup s.platform = Gem::Platform::RUBY s.summary = "SimpleCaptcha is the simplest and a robust captcha plugin." From 0ba9297bd3219ff81e2dc8b874db020d025ff3d6 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Mon, 2 Dec 2013 00:27:48 +0100 Subject: [PATCH 024/115] drop Ruby 1.8.7 --- README.rdoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rdoc b/README.rdoc index 1193da4..eef8e00 100644 --- a/README.rdoc +++ b/README.rdoc @@ -17,8 +17,8 @@ This is a fork of the popular Rubygem simple_captcha which got abandoned. ==Requirements -* {Ruby}[http://ruby-lang.org/] >= 1.8.7 -* {Rails}[http://github.com/rails/rails] >= 3 +* {Ruby}[http://ruby-lang.org/] >= 1.9.3 +* {Rails}[http://github.com/rails/rails] >= 3.2 * ImageMagick should be installed on your machine to use this plugin. visit http://www.imagemagick.org/script/index.php for more details. @@ -28,7 +28,7 @@ This is a fork of the popular Rubygem simple_captcha which got abandoned. # OR - gem 'simple_captcha', :git => 'git://github.com/pludoni/simple-captcha.git' + gem 'simple_captcha2', :git => 'git://github.com/pludoni/simple-captcha.git' ==Setup From 251d423a2b8419de29b8ce7386f8e342eb80c908 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Mon, 2 Dec 2013 00:46:50 +0100 Subject: [PATCH 025/115] converted README to markdown with syntax highlighting --- README.md | 293 ++++++++++++++++++++++++++++++++++++++++++++++++++++ README.rdoc | 2 + 2 files changed, 295 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..93e5016 --- /dev/null +++ b/README.md @@ -0,0 +1,293 @@ +#SimpleCaptcha2 + +[![Build Status](https://travis-ci.org/pludoni/simple-captcha.png?branch=master)](https://travis-ci.org/pludoni/simple-captcha) + +SimpleCaptcha(2) is the simplest and a robust captcha plugin. Its implementation requires adding up a single line in views and in controllers/models. +SimpleCaptcha2 is available to be used with Rails 3 + 4. +This is a fork of the popular Rubygem ``simple_captcha`` which got abandoned. + +##Features + +* Zero FileSystem usage (secret code moved to db-store and image storage removed). +* Provides various image styles. +* Provides three level of complexity of images. +* Works absolutely fine in distributed environment(session and db based implementation works fine in distributed environment). +* Implementation is as easy as just writing a single line in your view. ```<%= show_simple_captcha %>``` within the 'form' tags. +* Flexible DOM and CSS handling(There is a separate view partial for rendering SimpleCaptcha DOM elements). +* Automated removal of 1 hour old unmatched simple_captcha data. + +##Requirements + +* Ruby >= 1.9.3 +* Rails >= 3.2 +* ImageMagick should be installed on your machine to use this plugin. + visit http://www.imagemagick.org/script/index.php for more details. + +##Installation + +Put this into your Gemfile + +```ruby +gem 'simple_captcha2' +``` + +and run ``bundle install``. + +## Setup + +After installation, follow these simple steps to setup the plugin. The setup will depend on the version of rails your application is using. + +```bash +rails generate simple_captcha +rake db:migrate +``` + +## Usage + +There are two usage scenarios: + +### Controller Based + +Add the following line in the file "app/controllers/application.rb" + +```ruby +ApplicationController < ActionController::Base + include SimpleCaptcha::ControllerHelpers +end +``` + +In the view file within the form tags add this code + +```erb +<%= show_simple_captcha %> +``` + +and in the controller's action authenticate it as + +```ruby +if simple_captcha_valid? + do this +else + do that +end +``` + +### Model Based + +This is suggested, if you want to integrate the error message into the normal form validation flow. + +In the view file within the form tags write this code + +```erb +<%= show_simple_captcha(:object=>"user") %> +``` + +and in the model class add this code + +```ruby +class User < ActiveRecord::Base + apply_simple_captcha +end +``` + +####Form-Builder helper + +```erb +<%= form_for @user do |form| -%> + ... + <%= form.simple_captcha :label => "Enter numbers.." %> + ... +<% end -%> +``` + +####Validating with captcha + +NOTE: @user.valid? will still work as it should, it will not validate the captcha code. + +```ruby +@user.valid_with_captcha? +``` + +####Saving with captcha + +NOTE: @user.save will still work as it should, it will not validate the captcha code. + +```ruby +@user.save_with_captcha +``` + +##=Formtastic integration + +SimpleCaptcha detects if you are using Formtastic: + +```erb +<%= form.input :captcha, :as => :simple_captcha %> +``` + +##Options & Examples + +###View Options + +* ``:label`` - provides the custom text b/w the image and the text field, the default is "type the code from the image" +* ``:object`` - the name of the object of the model class, to implement the model based captcha. +* ``:code_type`` - return numeric only if set to 'numeric' + +###Global options + +* ``:image_style`` - provides the specific image style for the captcha image. +There are eight different styles available with the plugin as... + + 1. simply_blue + 2. simply_red + 3. simply_green + 4. charcoal_grey + 5. embosed_silver + 6. all_black + 7. distorted_black + 8. almost_invisible + +Default style is 'simply_blue'. +You can also specify 'random' to select the random image style. + +* ``:distortion`` - handles the complexity of the image. The :distortion can be set to 'low', 'medium' or 'high'. Default is 'low'. + +Create "./config/initializers/simple_captcha.rb" + +```ruby +SimpleCaptcha.setup do |sc| + # default: 100x28 + sc.image_size = '120x40' + + # default: 5 + sc.length = 6 + + # default: simply_blue + # possible values: + # 'embosed_silver', + # 'simply_red', + # 'simply_green', + # 'simply_blue', + # 'distorted_black', + # 'all_black', + # 'charcoal_grey', + # 'almost_invisible' + # 'random' + sc.image_style = 'simply_green' + + # default: low + # possible values: 'low', 'medium', 'high', 'random' + sc.distortion = 'medium' +end +``` + +You can add your own style: + +```ruby +SimpleCaptcha.setup do |sc| + sc.image_style = 'mycaptha' + sc.add_image_style('mycaptha', [ + "-background '#F4F7F8'", + "-fill '#86818B'", + "-border 1", + "-bordercolor '#E0E2E3'"]) +end +``` + +You can provide the path where image_magick is installed as well: + +```ruby +SimpleCaptcha.setup do |sc| + sc.image_magick_path = '/usr/bin' # you can check this from console by running: which convert +end +``` + +You can provide the path where should be stored tmp files. +It's usefull when you dont have acces to /tmp (default directory) + +```ruby +SimpleCaptcha.setup do |sc| + sc.tmp_path = '/tmp' # or somewhere in project eg. Rails.root.join('tmp/simple_captcha').to_s, make shure directory exists +end +``` + + +### How to change the CSS for SimpleCaptcha DOM elements? + +You can change the CSS of the SimpleCaptcha DOM elements as per your need in this file. + + ./app/views/simple_captcha/_simple_captcha.erb + +###View's Examples +####Controller Based Example + +```erb +<%= show_simple_captcha %> + +<%= show_simple_captcha(:label => "human authentication") %> +``` + +####Model Based Example + +```erb +<%= show_simple_captcha(:object => 'user', :label => "human authentication") %> +``` + +####Model Options + +* ``:message`` - provides the custom message on failure of captcha authentication the default is "Secret Code did not match with the Image" + +* ``:add_to_base`` - if set to true, appends the error message to the base. + +####=Model's Example + +```ruby +class User < ActiveRecord::Base + apply_simple_captcha +end + +class User < ActiveRecord::Base + apply_simple_captcha :message => "The secret Image and code were different", :add_to_base => true +end +``` + + +##I18n + +```yaml +en: + simple_captcha: + placeholder: "Enter the image value" + label: "Enter the code in the box:" + message: + default: "Secret Code did not match with the Image" + user: "The secret Image and code were different" +``` + +##Contributing + +For testing, generate a temporary Rails dummy app inside test: + +```bash +rake dummy:setup +rake app:db:migrate +rake app:db:migrate RAILS_ENV=test +export BUNDLE_GEMFILE=$PWD/Gemfile +cd test/dummy && rake db:migrate db:test:prepare +rake test +``` + +Please add test cases when adding new functionality. I started with some basic example integration tests for a very basic coverage. + +The tests will be run on [Travis-CI](https://travis-ci.org/pludoni/simple-captcha). + +##Who's who? + +Enjoy the simplest captcha implementation. + +Original Author of the Version for Rails 2: +Author: Sur, Blog: http://expressica.com, Contact: sur.max@gmail.com +Plugin Homepage: http://expressica.com/simple_captcha + +Plugin update for rails 3: http://github.com/galetahub + +update for Rails 4, tests and forked by Stefan Wienert (pludoni GmbH) diff --git a/README.rdoc b/README.rdoc index eef8e00..962f6b7 100644 --- a/README.rdoc +++ b/README.rdoc @@ -1,5 +1,7 @@ =SimpleCaptcha2 +{Build Status}[https://travis-ci.org/pludoni/simple-captcha] + SimpleCaptcha(2) is the simplest and a robust captcha plugin. Its implementation requires adding up a single line in views and in controllers/models. SimpleCaptcha2 is available to be used with Rails 3 + 4. From b9774adc597a9d74da0942e0ad736a039b134884 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Mon, 2 Dec 2013 00:48:25 +0100 Subject: [PATCH 026/115] deleted old README, fixed markdown formatting issues --- README.md | 20 ++--- README.rdoc | 246 ---------------------------------------------------- 2 files changed, 10 insertions(+), 256 deletions(-) delete mode 100644 README.rdoc diff --git a/README.md b/README.md index 93e5016..4edd57c 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ NOTE: @user.save will still work as it should, it will not validate the captcha @user.save_with_captcha ``` -##=Formtastic integration +###Formtastic integration SimpleCaptcha detects if you are using Formtastic: @@ -137,14 +137,14 @@ SimpleCaptcha detects if you are using Formtastic: * ``:image_style`` - provides the specific image style for the captcha image. There are eight different styles available with the plugin as... - 1. simply_blue - 2. simply_red - 3. simply_green - 4. charcoal_grey - 5. embosed_silver - 6. all_black - 7. distorted_black - 8. almost_invisible +1. simply_blue +2. simply_red +3. simply_green +4. charcoal_grey +5. embosed_silver +6. all_black +7. distorted_black +8. almost_invisible Default style is 'simply_blue'. You can also specify 'random' to select the random image style. @@ -215,7 +215,7 @@ end You can change the CSS of the SimpleCaptcha DOM elements as per your need in this file. - ./app/views/simple_captcha/_simple_captcha.erb +``app/views/simple_captcha/_simple_captcha.erb`` ###View's Examples ####Controller Based Example diff --git a/README.rdoc b/README.rdoc deleted file mode 100644 index 962f6b7..0000000 --- a/README.rdoc +++ /dev/null @@ -1,246 +0,0 @@ -=SimpleCaptcha2 - -{Build Status}[https://travis-ci.org/pludoni/simple-captcha] - -SimpleCaptcha(2) is the simplest and a robust captcha plugin. Its implementation requires -adding up a single line in views and in controllers/models. -SimpleCaptcha2 is available to be used with Rails 3 + 4. -This is a fork of the popular Rubygem simple_captcha which got abandoned. - -==Features - -* Zero FileSystem usage (secret code moved to db-store and image storage removed). -* Provides various image styles. -* Provides three level of complexity of images. -* Works absolutely fine in distributed environment(session and db based implementation works fine in distributed environment). -* Implementation is as easy as just writing a single line in your view. "<%= show_simple_captcha %>" within the 'form' tags. -* Flexible DOM and CSS handling(There is a separate view partial for rendering SimpleCaptcha DOM elements). -* Automated removal of 1 hour old unmatched simple_captcha data. - -==Requirements - -* {Ruby}[http://ruby-lang.org/] >= 1.9.3 -* {Rails}[http://github.com/rails/rails] >= 3.2 -* ImageMagick should be installed on your machine to use this plugin. - visit http://www.imagemagick.org/script/index.php for more details. - -==Installation - - gem 'simple_captcha2' - - # OR - - gem 'simple_captcha2', :git => 'git://github.com/pludoni/simple-captcha.git' - -==Setup - -After installation, follow these simple steps to setup the plugin. The setup will depend -on the version of rails your application is using. - - rails generate simple_captcha - - rake db:migrate - -==Usage - -===Controller Based - -Add the following line in the file "app/controllers/application.rb" - - ApplicationController < ActionController::Base - include SimpleCaptcha::ControllerHelpers - end - -In the view file within the form tags add this code - - <%= show_simple_captcha %> - -and in the controller's action authenticate it as - - if simple_captcha_valid? - do this - else - do that - end - -===Model Based - -In the view file within the form tags write this code - - <%= show_simple_captcha(:object=>"user") %> - -and in the model class add this code - - class User < ActiveRecord::Base - apply_simple_captcha - end - -====FormBuilder helper - - <%= form_for @user do |form| -%> - ... - <%= form.simple_captcha :label => "Enter numbers.." %> - ... - <% end -%> - -====Validating with captcha -NOTE: @user.valid? will still work as it should, it will not validate the captcha code. - - @user.valid_with_captcha? - -====Saving with captcha -NOTE: @user.save will still work as it should, it will not validate the captcha code. - - @user.save_with_captcha - -===Formtastic integration -SimpleCaptcha detects if your use Formtastic and appends "SimpleCaptcha::CustomFormBuilder". - - <%= form.input :captcha, :as => :simple_captcha %> - -==Options & Examples -===View Options - -* *label* - provides the custom text b/w the image and the text field, the default is "type the code from the image" - -* *object* - the name of the object of the model class, to implement the model based captcha. - -* *code_type* - return numeric only if set to 'numeric' - -===Global options - -* *image_style* - provides the specific image style for the captcha image. -There are eight different styles available with the plugin as... - 1) simply_blue - 2) simply_red - 3) simply_green - 4) charcoal_grey - 5) embosed_silver - 6) all_black - 7) distorted_black - 8) almost_invisible -Default style is 'simply_blue'. -You can also specify 'random' to select the random image style. - -* *distortion* - handles the complexity of the image. The :distortion can be set to 'low', 'medium' or 'high'. Default is 'low'. - -Create "rails_root/config/initializers/simple_captcha.rb" - - SimpleCaptcha.setup do |sc| - # default: 100x28 - sc.image_size = '120x40' - - # default: 5 - sc.length = 6 - - # default: simply_blue - # possible values: - # 'embosed_silver', - # 'simply_red', - # 'simply_green', - # 'simply_blue', - # 'distorted_black', - # 'all_black', - # 'charcoal_grey', - # 'almost_invisible' - # 'random' - sc.image_style = 'simply_green' - - # default: low - # possible values: 'low', 'medium', 'high', 'random' - sc.distortion = 'medium' - end - -You can add your own style: - - SimpleCaptcha.setup do |sc| - sc.image_style = 'mycaptha' - sc.add_image_style('mycaptha', [ - "-background '#F4F7F8'", - "-fill '#86818B'", - "-border 1", - "-bordercolor '#E0E2E3'"]) - end - -You can provide the path where image_magick is installed as well: - - SimpleCaptcha.setup do |sc| - sc.image_magick_path = '/usr/bin' # you can check this from console by running: which convert - end - -You can provide the path where should be stored tmp files. -It's usefull when you dont have acces to /tmp (default directory) - - SimpleCaptcha.setup do |sc| - sc.tmp_path = '/tmp' # or somewhere in project eg. Rails.root.join('tmp/simple_captcha').to_s, make shure directory exists - end - - -===How to change the CSS for SimpleCaptcha DOM elements? -You can change the CSS of the SimpleCaptcha DOM elements as per your need in this file. - /app/views/simple_captcha/_simple_captcha.erb - -===View's Examples -====Controller Based Example - - <%= show_simple_captcha %> - - <%= show_simple_captcha(:label => "human authentication") %> - -====Model Based Example - - <%= show_simple_captcha(:object => 'user', :label => "human authentication") %> - -====Model Options - -* *message* - provides the custom message on failure of captcha authentication the default is "Secret Code did not match with the Image" - -* *add_to_base* - if set to true, appends the error message to the base. - -=====Model's Example - - class User < ActiveRecord::Base - apply_simple_captcha - end - - class User < ActiveRecord::Base - apply_simple_captcha :message => "The secret Image and code were different", :add_to_base => true - end - -==I18n - - simple_captcha: - placeholder: "Enter the image value" - label: "Enter the code in the box:" - message: - default: "Secret Code did not match with the Image" - user: "The secret Image and code were different" - -==Contributing - -For testing, generate a temporary Rails dummy app inside test: - - rake dummy:setup - rake app:db:migrate - rake app:db:migrate RAILS_ENV=test - export BUNDLE_GEMFILE=$PWD/Gemfile - cd test/dummy && rake db:migrate db:test:prepare - rake test - -Please add test cases when adding new functionality. I started with some basic example integration tests for a very basic coverage. - -==Who's who? - -Enjoy the simplest captcha implementation. - -Author: Sur - -Blog: http://expressica.com - -Contact: sur.max@gmail.com - -Plugin Homepage: http://expressica.com/simple_captcha - -Plugin update for rails 3: http://github.com/galetahub - -Any feedback/comment/issue/donation is welcome! From 24015a5359cb380175f0fc5637767e485b6d3722 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Mon, 2 Dec 2013 00:48:58 +0100 Subject: [PATCH 027/115] ... --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4edd57c..e9379e7 100644 --- a/README.md +++ b/README.md @@ -238,7 +238,7 @@ You can change the CSS of the SimpleCaptcha DOM elements as per your need in thi * ``:add_to_base`` - if set to true, appends the error message to the base. -####=Model's Example +#####Model's Example ```ruby class User < ActiveRecord::Base From 2ea465adca144e63e3f8895326dd935b9d20e09c Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Tue, 3 Dec 2013 16:48:23 +0100 Subject: [PATCH 028/115] clarification: needs to require simple_captcha for now --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e9379e7..47a74c1 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ This is a fork of the popular Rubygem ``simple_captcha`` which got abandoned. Put this into your Gemfile ```ruby -gem 'simple_captcha2' +gem 'simple_captcha2', require: 'simple_captcha' ``` and run ``bundle install``. From fb6d99c47d95b60d48a4c4c15c938c8c415e5362 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Tue, 3 Dec 2013 16:53:53 +0100 Subject: [PATCH 029/115] test usage --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 47a74c1..d2dad6e 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,22 @@ SimpleCaptcha detects if you are using Formtastic: <%= form.input :captcha, :as => :simple_captcha %> ``` +### Tests + +You can make the Captcha always pass with a initializer file: config/initializers/simple_captcha.rb + +```ruby +SimpleCaptcha.always_pass = Rails.env.test? +``` + +You can also ask for the value, e.g. Acceptance Tests/Features: + +```ruby +visit '/pages/form_tag' +assert_equal 1, SimpleCaptcha::SimpleCaptchaData.count +fill_in 'captcha', with: SimpleCaptcha::SimpleCaptchaData.first.value +``` + ##Options & Examples ###View Options From d78bae06cceba34d129316460c5ea06c516aaecb Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Sat, 14 Dec 2013 11:44:08 +0100 Subject: [PATCH 030/115] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index d2dad6e..8dfe4d8 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,12 @@ This is a fork of the popular Rubygem ``simple_captcha`` which got abandoned. * ImageMagick should be installed on your machine to use this plugin. visit http://www.imagemagick.org/script/index.php for more details. +You might need to install Ghostscript on a Mac-System: + +``` +brew install ghostscript +``` + ##Installation Put this into your Gemfile From a023d284b9ac4574164e628c3456a0c89c602c9f Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Sun, 29 Dec 2013 15:06:08 +0100 Subject: [PATCH 031/115] gemspec warning fixed; travis.yml now with ruby 2.1 and rails 4.1beta --- .travis.yml | 3 +++ simple_captcha.gemspec | 4 ++-- simple_captcha2.gemspec | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 59d0354..0eb2b6d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,9 @@ env: - DB=sqlite FORMTASTIC='~> 2.2' RAILS='~> 4.0' matrix: + include: + - rvm: 2.1.0 + env: DB=mysql RAILS='4.1.0.beta1' exclude: - rvm: 1.9.3 env: DB=mysql RAILS='~> 4.0' diff --git a/simple_captcha.gemspec b/simple_captcha.gemspec index 501d66a..feb347b 100644 --- a/simple_captcha.gemspec +++ b/simple_captcha.gemspec @@ -12,8 +12,8 @@ Gem::Specification.new do |s| s.email = "stwienert@gmail.com" s.homepage = "http://github.com/pludoni/simple-captcha" - s.files = Dir["{lib}/**/*"] + ["Rakefile", "README.rdoc"] - s.extra_rdoc_files = ["README.rdoc"] + s.files = Dir["{lib}/**/*"] + ["Rakefile", "README.md"] + s.extra_rdoc_files = ["README.md"] s.require_paths = ["lib"] s.add_dependency 'rails', '>= 3.1' diff --git a/simple_captcha2.gemspec b/simple_captcha2.gemspec index 932ce19..d49f91a 100644 --- a/simple_captcha2.gemspec +++ b/simple_captcha2.gemspec @@ -12,8 +12,8 @@ Gem::Specification.new do |s| s.email = "stwienert@gmail.com" s.homepage = "http://github.com/pludoni/simple-captcha" - s.files = Dir["{lib}/**/*"] + ["Rakefile", "README.rdoc"] - s.extra_rdoc_files = ["README.rdoc"] + s.files = Dir["{lib}/**/*"] + ["Rakefile", "README.md"] + s.extra_rdoc_files = ["README.md"] s.require_paths = ["lib"] s.add_dependency 'rails', '>= 3.1' From 5b83cab718016b6fe1a5b33c85c4e31457fc4f19 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Sun, 29 Dec 2013 15:10:15 +0100 Subject: [PATCH 032/115] tests now work --- .travis.yml | 1 - test/model.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0eb2b6d..85871c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ --- language: ruby script: - - 'cd test/dummy && rake db:migrate db:test:prepare' - rake test rvm: - '1.9.3' diff --git a/test/model.rb b/test/model.rb index 90aad13..7c67ed9 100644 --- a/test/model.rb +++ b/test/model.rb @@ -1,4 +1,4 @@ - +require 'simple_captcha' if Rails.version > '4.0' class User include ActiveModel::Model From c03d99338c40ecdc6dbbb7dd96148853b00ede92 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Sun, 29 Dec 2013 15:14:59 +0100 Subject: [PATCH 033/115] v.0.2.1: fixed bundle warning, missing README.rdoc --- lib/simple_captcha/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/simple_captcha/version.rb b/lib/simple_captcha/version.rb index a8508da..ad91e69 100644 --- a/lib/simple_captcha/version.rb +++ b/lib/simple_captcha/version.rb @@ -1,3 +1,3 @@ module SimpleCaptcha - VERSION = "0.2.0".freeze + VERSION = "0.2.1".freeze end From 7e713fc3a1b0df1b333c0047a83b6e3398a170b3 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Thu, 2 Jan 2014 10:14:19 +0100 Subject: [PATCH 034/115] maybe fix: uninitialized constant --- test/features/form_helper_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/features/form_helper_test.rb b/test/features/form_helper_test.rb index d9e3b4f..eef25f8 100644 --- a/test/features/form_helper_test.rb +++ b/test/features/form_helper_test.rb @@ -1,4 +1,5 @@ require 'test_helper' +require 'simple_captcha/controller' class FormHelperTest < ActionDispatch::IntegrationTest include Capybara::DSL From 6ce88e6972bc022cdbfc33f8ea5c458faea0f679 Mon Sep 17 00:00:00 2001 From: Konstantin Papkovskiy Date: Thu, 16 Jan 2014 18:09:50 +0400 Subject: [PATCH 035/115] fix mass-assignment error when using protected_attributes --- lib/simple_captcha/simple_captcha_data.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/simple_captcha/simple_captcha_data.rb b/lib/simple_captcha/simple_captcha_data.rb index 703d130..c01ba6a 100644 --- a/lib/simple_captcha/simple_captcha_data.rb +++ b/lib/simple_captcha/simple_captcha_data.rb @@ -15,7 +15,7 @@ class SimpleCaptchaData < ::ActiveRecord::Base class << self def get_data(key) - where(key: key).first || new(key: key) + where(key: key).first_or_initialize end def remove_data(key) From 666fd2ee8a1af7f248262240699366d6a57e1ddb Mon Sep 17 00:00:00 2001 From: "fbiete@gmail.com" Date: Tue, 4 Mar 2014 19:51:53 +0100 Subject: [PATCH 036/115] Support for using the same captcha in multiple forms of the same page --- README.md | 1 + lib/simple_captcha/view.rb | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8dfe4d8..566b439 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,7 @@ fill_in 'captcha', with: SimpleCaptcha::SimpleCaptchaData.first.value * ``:label`` - provides the custom text b/w the image and the text field, the default is "type the code from the image" * ``:object`` - the name of the object of the model class, to implement the model based captcha. * ``:code_type`` - return numeric only if set to 'numeric' +* ``:multiple`` - allow to use the same captcha in multiple forms in one page. True for the first appaerance and false for the rest. ###Global options diff --git a/lib/simple_captcha/view.rb b/lib/simple_captcha/view.rb index fc57080..5e7e836 100644 --- a/lib/simple_captcha/view.rb +++ b/lib/simple_captcha/view.rb @@ -44,7 +44,13 @@ module ViewHelper #:nodoc # All Feedbacks/CommentS/Issues/Queries are welcome. def show_simple_captcha(options={}) key = simple_captcha_key(options[:object]) - options[:field_value] = set_simple_captcha_data(key, options) + if options[:multiple] === false + # It's not the first captcha, we only need to return the key + options[:field_value] = key + else + # It's the first captcha in the page, we generate a new key + options[:field_value] = set_simple_captcha_data(key, options) + end defaults = { :image => simple_captcha_image(key, options), From f0677ed6c11c9fdabe58031a7249b3645e4ba221 Mon Sep 17 00:00:00 2001 From: mzaharie Date: Tue, 29 Apr 2014 09:45:22 +0300 Subject: [PATCH 037/115] fix: avoid 'create_migration' method conflict --- lib/generators/simple_captcha_generator.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/generators/simple_captcha_generator.rb b/lib/generators/simple_captcha_generator.rb index 89beb04..c719fa6 100644 --- a/lib/generators/simple_captcha_generator.rb +++ b/lib/generators/simple_captcha_generator.rb @@ -2,7 +2,7 @@ class SimpleCaptchaGenerator < Rails::Generators::Base include Rails::Generators::Migration - + def self.source_root @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates/')) end @@ -10,12 +10,12 @@ def self.source_root def self.next_migration_number(dirname) Time.now.strftime("%Y%m%d%H%M%S") end - + def create_partial template "partial.erb", File.join('app/views', 'simple_captcha', "_simple_captcha.erb") end - - def create_migration + + def create_captcha_migration migration_template "migration.rb", File.join('db/migrate', "create_simple_captcha_data.rb") end end From 3da3d8fba89956b05cbd27efbe48b95e8da61060 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Sun, 4 May 2014 19:19:55 +0200 Subject: [PATCH 038/115] version 0.3.0 -> Rails 4.1 compatibility fixes --- lib/simple_captcha/version.rb | 2 +- simple_captcha2.gemspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/simple_captcha/version.rb b/lib/simple_captcha/version.rb index ad91e69..d3d37a3 100644 --- a/lib/simple_captcha/version.rb +++ b/lib/simple_captcha/version.rb @@ -1,3 +1,3 @@ module SimpleCaptcha - VERSION = "0.2.1".freeze + VERSION = "0.3.0".freeze end diff --git a/simple_captcha2.gemspec b/simple_captcha2.gemspec index d49f91a..3c6f1ff 100644 --- a/simple_captcha2.gemspec +++ b/simple_captcha2.gemspec @@ -16,7 +16,7 @@ Gem::Specification.new do |s| s.extra_rdoc_files = ["README.md"] s.require_paths = ["lib"] - s.add_dependency 'rails', '>= 3.1' + s.add_dependency 'rails', '>= 4.1' s.add_development_dependency "sqlite3" s.add_development_dependency "capybara-mechanize" s.add_development_dependency "pry" From 12cbffca9e47d5656274e8df860ddb4b7c0be00b Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Sun, 4 May 2014 19:27:01 +0200 Subject: [PATCH 039/115] Travis.yml -> Ruby 2.1 and rails 4.1 preferred --- .travis.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 85871c5..58d85dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,22 +5,22 @@ script: rvm: - '1.9.3' - '2.0.0' + - '2.1.0' env: - - DB=sqlite RAILS='~> 4.0' - - DB=mysql RAILS='~> 4.0' - - DB=sqlite FORMTASTIC='~> 2.2' RAILS='~> 3.2' - - DB=sqlite FORMTASTIC='~> 2.2' RAILS='~> 4.0' + - DB=sqlite RAILS='~> 4.1' + - DB=sqlite FORMTASTIC='~> 2.2' RAILS='~> 4.1' matrix: include: - rvm: 2.1.0 - env: DB=mysql RAILS='4.1.0.beta1' - exclude: - - rvm: 1.9.3 - env: DB=mysql RAILS='~> 4.0' - - rvm: 1.9.3 - env: DB=sqlite FORMTASTIC='~> 2.2' RAILS='~> 4.0' + env: DB=mysql RAILS='4.1' + include: + - rvm: 2.1.0 + env: DB=posgresql RAILS='4.1' + include: + - rvm: 2.1.0 + env: DB=sqlite FORMTASTIC='~> 2.2' RAILS='~> 4.1' before_script: From 974a88ee8347ece9b792d68860f34522aa3a67ee Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Sun, 4 May 2014 19:32:49 +0200 Subject: [PATCH 040/115] Ruby version 2.1.1 --- .travis.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 58d85dd..7abc14e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ script: rvm: - '1.9.3' - '2.0.0' - - '2.1.0' + - '2.1.1' env: - DB=sqlite RAILS='~> 4.1' @@ -13,13 +13,13 @@ env: matrix: include: - - rvm: 2.1.0 + - rvm: 2.1.1 env: DB=mysql RAILS='4.1' + # include: + # - rvm: 2.1.0 + # env: DB=posgresql RAILS='4.1' include: - - rvm: 2.1.0 - env: DB=posgresql RAILS='4.1' - include: - - rvm: 2.1.0 + - rvm: 2.1.1 env: DB=sqlite FORMTASTIC='~> 2.2' RAILS='~> 4.1' From da9f3773cf82fc5c05021de7bcd42bfe0642dd64 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Sat, 24 May 2014 20:42:14 +0200 Subject: [PATCH 041/115] simple_captcha_valid? idempotent - saves last result; fixes #13 --- Gemfile | 1 - Rakefile | 9 +++++++++ lib/simple_captcha/controller.rb | 6 ++++-- lib/simple_captcha/version.rb | 2 +- test/features/form_helper_test.rb | 2 ++ .../dummy/templates/app/controllers/pages_controller.rb | 1 + 6 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 850ef6b..7ed26ee 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,6 @@ source "https://rubygems.org" gemspec :name => 'simple_captcha2' -gem 'sqlite3' gem 'rails', ENV['RAILS'] || '~> 4.0' if ENV['DB'] and ENV['DB']['mysql'] diff --git a/Rakefile b/Rakefile index df1c7b4..8177102 100644 --- a/Rakefile +++ b/Rakefile @@ -33,6 +33,15 @@ namespace :dummy do FileUtils.rm_rf "test/dummy" if File.exists?("test/dummy") end + desc 'redo' + task :redo do + sh 'rake dummy:destroy' + sh 'rake dummy:setup' + sh 'rake app:db:migrate' + sh 'rake app:db:migrate RAILS_ENV=test' + end + + end diff --git a/lib/simple_captcha/controller.rb b/lib/simple_captcha/controller.rb index f7fb2ff..3a8a20a 100644 --- a/lib/simple_captcha/controller.rb +++ b/lib/simple_captcha/controller.rb @@ -15,14 +15,16 @@ module ControllerHelpers #:nodoc # end def simple_captcha_valid? return true if SimpleCaptcha.always_pass + return @_simple_captcha_result unless @_simple_captcha_result.nil? if params[:captcha] data = SimpleCaptcha::Utils::simple_captcha_value(params[:captcha_key] || session[:captcha]) result = data == params[:captcha].delete(" ").upcase SimpleCaptcha::Utils::simple_captcha_passed!(session[:captcha]) if result - return result + @_simple_captcha_result = result + result else - return false + false end end end diff --git a/lib/simple_captcha/version.rb b/lib/simple_captcha/version.rb index d3d37a3..accbeab 100644 --- a/lib/simple_captcha/version.rb +++ b/lib/simple_captcha/version.rb @@ -1,3 +1,3 @@ module SimpleCaptcha - VERSION = "0.3.0".freeze + VERSION = "0.3.1".freeze end diff --git a/test/features/form_helper_test.rb b/test/features/form_helper_test.rb index eef25f8..15cb4cc 100644 --- a/test/features/form_helper_test.rb +++ b/test/features/form_helper_test.rb @@ -31,6 +31,7 @@ class FormHelperTest < ActionDispatch::IntegrationTest click_on 'Save changes' assert page.has_content? 'captcha valid' end + test 'model based failure' do visit '/pages/model_tag' assert_equal 1, SimpleCaptcha::SimpleCaptchaData.count @@ -38,4 +39,5 @@ class FormHelperTest < ActionDispatch::IntegrationTest click_on 'Save changes' assert page.has_content? 'captcha not valid' end + end diff --git a/test/lib/generators/simple_captcha/dummy/templates/app/controllers/pages_controller.rb b/test/lib/generators/simple_captcha/dummy/templates/app/controllers/pages_controller.rb index 7824f56..8dcfe92 100644 --- a/test/lib/generators/simple_captcha/dummy/templates/app/controllers/pages_controller.rb +++ b/test/lib/generators/simple_captcha/dummy/templates/app/controllers/pages_controller.rb @@ -3,6 +3,7 @@ def form_tag end def form_tag_submit + simple_captcha_valid? # idempotence if simple_captcha_valid? render text: 'captcha valid!' else From 7ee803ca1177314931152a1b47e761507d2d5699 Mon Sep 17 00:00:00 2001 From: Stefan Wienert Date: Sat, 24 May 2014 21:53:53 +0200 Subject: [PATCH 042/115] Refresh Button: Adjustments with generic id, at least for image, default text --- Gemfile | 1 + lib/generators/templates/partial.erb | 6 +-- lib/simple_captcha/middleware.rb | 16 ++++--- lib/simple_captcha/view.rb | 47 +++++++++++-------- lib/simple_captcha2.rb | 1 + simple_captcha2.gemspec | 1 + test/features/form_helper_test.rb | 16 +++++++ .../app/assets/javascripts/application.js | 2 + .../views/simple_captcha/_simple_captcha.erb | 10 ++-- test/test_helper.rb | 7 +-- 10 files changed, 69 insertions(+), 38 deletions(-) create mode 100644 lib/simple_captcha2.rb create mode 100644 test/lib/generators/simple_captcha/dummy/templates/app/assets/javascripts/application.js diff --git a/Gemfile b/Gemfile index 7ed26ee..a0adcd0 100644 --- a/Gemfile +++ b/Gemfile @@ -3,6 +3,7 @@ source "https://rubygems.org" gemspec :name => 'simple_captcha2' gem 'rails', ENV['RAILS'] || '~> 4.0' +gem 'jquery-rails' if ENV['DB'] and ENV['DB']['mysql'] gem 'mysql2' diff --git a/lib/generators/templates/partial.erb b/lib/generators/templates/partial.erb index 37bcd8a..6419e8f 100644 --- a/lib/generators/templates/partial.erb +++ b/lib/generators/templates/partial.erb @@ -1,4 +1,4 @@ -