devise_certifiable 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +10 -0
  3. data/LICENSE +19 -0
  4. data/README.rdoc +53 -0
  5. data/Rakefile +26 -0
  6. data/app/controllers/devise/certifications_controller.rb +34 -0
  7. data/app/views/devise/certifications/edit.html.erb +14 -0
  8. data/app/views/devise/mailer/certification_request.html.erb +8 -0
  9. data/config/locales/en.yml +17 -0
  10. data/devise_certifiable.gemspec +25 -0
  11. data/lib/devise_certifiable.rb +13 -0
  12. data/lib/devise_certifiable/controllers/helpers.rb +7 -0
  13. data/lib/devise_certifiable/controllers/url_helpers.rb +24 -0
  14. data/lib/devise_certifiable/mailer.rb +10 -0
  15. data/lib/devise_certifiable/model.rb +98 -0
  16. data/lib/devise_certifiable/rails.rb +12 -0
  17. data/lib/devise_certifiable/routes.rb +10 -0
  18. data/lib/devise_certifiable/schema.rb +12 -0
  19. data/lib/devise_certifiable/version.rb +3 -0
  20. data/lib/generators/active_record/devise_certifiable_generator.rb +13 -0
  21. data/lib/generators/active_record/templates/migration.rb +18 -0
  22. data/lib/generators/devise_certifiable/devise_certifiable_generator.rb +16 -0
  23. data/lib/generators/devise_certifiable/install_generator.rb +11 -0
  24. data/test/controllers/url_helpers_test.rb +34 -0
  25. data/test/generators/active_record_generator_test.rb +24 -0
  26. data/test/generators/devise_certifiable_generator_test.rb +27 -0
  27. data/test/generators/install_generator_test.rb +15 -0
  28. data/test/integration/certification_test.rb +80 -0
  29. data/test/mailers/certification_request_test.rb +63 -0
  30. data/test/models/certifiable_test.rb +172 -0
  31. data/test/models_test.rb +26 -0
  32. data/test/orm/active_record.rb +4 -0
  33. data/test/rails_app/Rakefile +10 -0
  34. data/test/rails_app/app/active_record/user.rb +7 -0
  35. data/test/rails_app/app/controllers/application_controller.rb +3 -0
  36. data/test/rails_app/app/controllers/home_controller.rb +4 -0
  37. data/test/rails_app/app/controllers/users_controller.rb +12 -0
  38. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  39. data/test/rails_app/app/models/monster.rb +5 -0
  40. data/test/rails_app/app/views/home/index.html.erb +1 -0
  41. data/test/rails_app/app/views/layouts/application.html.erb +20 -0
  42. data/test/rails_app/app/views/users/index.html.erb +1 -0
  43. data/test/rails_app/config.ru +4 -0
  44. data/test/rails_app/config/application.rb +29 -0
  45. data/test/rails_app/config/boot.rb +11 -0
  46. data/test/rails_app/config/database.yml +18 -0
  47. data/test/rails_app/config/environment.rb +5 -0
  48. data/test/rails_app/config/environments/development.rb +22 -0
  49. data/test/rails_app/config/environments/production.rb +33 -0
  50. data/test/rails_app/config/environments/test.rb +33 -0
  51. data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  52. data/test/rails_app/config/initializers/devise.rb +179 -0
  53. data/test/rails_app/config/initializers/inflections.rb +2 -0
  54. data/test/rails_app/config/initializers/secret_token.rb +2 -0
  55. data/test/rails_app/config/routes.rb +6 -0
  56. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +17 -0
  57. data/test/rails_app/lib/shared_user.rb +7 -0
  58. data/test/rails_app/script/rails +6 -0
  59. data/test/routes_test.rb +11 -0
  60. data/test/support/assertions.rb +24 -0
  61. data/test/support/helpers.rb +39 -0
  62. data/test/support/integration.rb +59 -0
  63. data/test/support/locale/en.yml +4 -0
  64. data/test/test_helper.rb +20 -0
  65. metadata +203 -0
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ class Certifiable < User
4
+ devise :certifiable
5
+ end
6
+
7
+ class ModelsTest < ActiveSupport::TestCase
8
+ def include_module?(klass, mod)
9
+ klass.devise_modules.include?(mod) &&
10
+ klass.included_modules.include?(Devise::Models::const_get(mod.to_s.classify))
11
+ end
12
+
13
+ def assert_include_modules(klass, *modules)
14
+ modules.each do |mod|
15
+ assert include_module?(klass, mod)
16
+ end
17
+
18
+ (Devise::ALL - modules).each do |mod|
19
+ assert_not include_module?(klass, mod)
20
+ end
21
+ end
22
+
23
+ test 'can cherry pick modules' do
24
+ assert_include_modules User, :database_authenticatable, :recoverable, :confirmable, :registerable, :validatable, :certifiable
25
+ end
26
+ end
@@ -0,0 +1,4 @@
1
+ ActiveRecord::Migration.verbose = false
2
+ ActiveRecord::Base.logger = Logger.new(nil)
3
+
4
+ ActiveRecord::Migrator.migrate(File.expand_path("../../rails_app/db/migrate/", __FILE__))
@@ -0,0 +1,10 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+ require 'rake/rdoctask'
9
+
10
+ Rails.application.load_tasks
@@ -0,0 +1,7 @@
1
+ require 'shared_user'
2
+
3
+ class User < ActiveRecord::Base
4
+ include SharedUser
5
+
6
+ attr_accessible :username, :email, :password, :password_confirmation
7
+ end
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,4 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ end
4
+ end
@@ -0,0 +1,12 @@
1
+ class UsersController < ApplicationController
2
+ before_filter :authenticate_user!
3
+
4
+ def index
5
+ user_session[:cart] = "Cart"
6
+ end
7
+
8
+ def expire
9
+ user_session['last_request_at'] = 31.minutes.ago.utc
10
+ render :text => 'User will be expired on next request'
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ # Methods added to this helper will be available to all templates in the application.
2
+ module ApplicationHelper
3
+ end
@@ -0,0 +1,5 @@
1
+ if DEVISE_ORM == :active_record
2
+ class Monster < ActiveRecord::Base
3
+ devise :database_authenticatable, :validatable, :confirmable, :encryptable
4
+ end
5
+ end
@@ -0,0 +1,20 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html>
4
+ <head>
5
+ <title>Devise Test App</title>
6
+ </head>
7
+ <body>
8
+ <div id="container">
9
+ <%- flash.each do |name, msg| -%>
10
+ <%= content_tag :div, msg, :id => "flash_#{name}" %>
11
+ <%- end -%>
12
+
13
+ <% if user_signed_in? -%>
14
+ <p>Hello User <%= current_user.email %>! You are signed in!</p>
15
+ <% end -%>
16
+
17
+ <%= yield %>
18
+ </div>
19
+ </body>
20
+ </html>
@@ -0,0 +1 @@
1
+ Welcome User #<%= current_user.id %>!
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run RailsApp::Application
@@ -0,0 +1,29 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "action_controller/railtie"
4
+ require "action_mailer/railtie"
5
+ require "active_resource/railtie"
6
+ require "rails/test_unit/railtie"
7
+
8
+ Bundler.require(:default, DEVISE_ORM) if defined?(Bundler)
9
+
10
+ begin
11
+ require "#{DEVISE_ORM}/railtie"
12
+ rescue LoadError
13
+ end
14
+
15
+ require "devise"
16
+ require "devise_certifiable"
17
+
18
+ module RailsApp
19
+ class Application < Rails::Application
20
+ # Add additional load paths for your own custom dirs
21
+ config.autoload_paths.reject!{ |p| p =~ /\/app\/(\w+)$/ && !%w(controllers helpers views).include?($1) }
22
+ config.autoload_paths += [ "#{config.root}/app/#{DEVISE_ORM}" ]
23
+
24
+ # Configure sensitive parameters which will be filtered from the log file.
25
+ config.filter_parameters << :password
26
+
27
+ config.action_mailer.default_url_options = { :host => "localhost:3000" }
28
+ end
29
+ end
@@ -0,0 +1,11 @@
1
+ unless defined?(DEVISE_ORM)
2
+ DEVISE_ORM = (ENV["DEVISE_ORM"] || :active_record).to_sym
3
+ end
4
+
5
+ begin
6
+ require File.expand_path("../../../../.bundle/environment", __FILE__)
7
+ rescue LoadError
8
+ require 'rubygems'
9
+ require 'bundler'
10
+ Bundler.setup :default, :test, DEVISE_ORM
11
+ end
@@ -0,0 +1,18 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3-ruby (not necessary on OS X Leopard)
3
+ development:
4
+ adapter: sqlite3
5
+ database: db/development.sqlite3
6
+ pool: 5
7
+ timeout: 5000
8
+
9
+ # Warning: The database defined as "test" will be erased and
10
+ # re-generated from your development database when you run "rake".
11
+ # Do not set this db to the same as development or production.
12
+ test:
13
+ adapter: sqlite3
14
+ database: ":memory:"
15
+
16
+ production:
17
+ adapter: sqlite3
18
+ database: ":memory:"
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ RailsApp::Application.initialize!
@@ -0,0 +1,22 @@
1
+ RailsApp::Application.configure do
2
+ # Settings specified here will take precedence over those in config/environment.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the webserver when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_view.debug_rjs = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Don't care if the mailer can't send
18
+ config.action_mailer.raise_delivery_errors = false
19
+
20
+ # Print deprecation notices to the Rails logger
21
+ config.active_support.deprecation = :log
22
+ end
@@ -0,0 +1,33 @@
1
+ RailsApp::Application.configure do
2
+ # Settings specified here will take precedence over those in config/environment.rb
3
+
4
+ # The production environment is meant for finished, "live" apps.
5
+ # Code is not reloaded between requests
6
+ config.cache_classes = true
7
+
8
+ # Full error reports are disabled and caching is turned on
9
+ config.consider_all_requests_local = false
10
+ config.action_controller.perform_caching = true
11
+
12
+ # See everything in the log (default is :info)
13
+ # config.log_level = :debug
14
+
15
+ # Use a different logger for distributed setups
16
+ # config.logger = SyslogLogger.new
17
+
18
+ # Use a different cache store in production
19
+ # config.cache_store = :mem_cache_store
20
+
21
+ # Disable Rails's static asset server
22
+ # In production, Apache or nginx will already do this
23
+ config.serve_static_assets = false
24
+
25
+ # Enable serving of images, stylesheets, and javascripts from an asset server
26
+ # config.action_controller.asset_host = "http://assets.example.com"
27
+
28
+ # Disable delivery errors, bad email addresses will be ignored
29
+ # config.action_mailer.raise_delivery_errors = false
30
+
31
+ # Enable threaded mode
32
+ # config.threadsafe!
33
+ end
@@ -0,0 +1,33 @@
1
+ RailsApp::Application.configure do
2
+ # Settings specified here will take precedence over those in config/environment.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ # Log error messages when you accidentally call methods on nil.
11
+ config.whiny_nils = true
12
+
13
+ # Show full error reports and disable caching
14
+ config.consider_all_requests_local = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Disable request forgery protection in test environment
18
+ config.action_controller.allow_forgery_protection = false
19
+
20
+ # Tell Action Mailer not to deliver emails to the real world.
21
+ # The :test delivery method accumulates sent emails in the
22
+ # ActionMailer::Base.deliveries array.
23
+ config.action_mailer.delivery_method = :test
24
+
25
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
26
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
27
+ # like if you have constraints or database-specific column types
28
+ # config.active_record.schema_format = :sql
29
+
30
+ config.action_dispatch.show_exceptions = false
31
+
32
+ config.active_support.deprecation = :stderr
33
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,179 @@
1
+ # Use this hook to configure devise mailer, warden hooks and so forth. The first
2
+ # four configuration values can also be set straight in your models.
3
+ Devise.setup do |config|
4
+ # ==> Mailer Configuration
5
+ # Configure the e-mail address which will be shown in DeviseMailer.
6
+ config.mailer_sender = "please-change-me@config-initializers-devise.com"
7
+
8
+ # Configure the class responsible to send e-mails.
9
+ # config.mailer = "Devise::Mailer"
10
+
11
+ # ==> ORM configuration
12
+ # Load and configure the ORM. Supports :active_record (default) and
13
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
14
+ # available as additional gems.
15
+ require "devise/orm/#{DEVISE_ORM}"
16
+
17
+ # ==> Configuration for any authentication mechanism
18
+ # Configure which keys are used when authenticating a user. By default is
19
+ # just :email. You can configure it to use [:username, :subdomain], so for
20
+ # authenticating a user, both parameters are required. Remember that those
21
+ # parameters are used only when authenticating and not when retrieving from
22
+ # session. If you need permissions, you should implement that in a before filter.
23
+ # You can also supply hash where the value is a boolean expliciting if authentication
24
+ # should be aborted or not if the value is not present. By default is empty.
25
+ # config.authentication_keys = [ :email ]
26
+
27
+ # Configure parameters from the request object used for authentication. Each entry
28
+ # given should be a request method and it will automatically be passed to
29
+ # find_for_authentication method and considered in your model lookup. For instance,
30
+ # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
31
+ # The same considerations mentioned for authentication_keys also apply to request_keys.
32
+ # config.request_keys = []
33
+
34
+ # Configure which authentication keys should be case-insensitive.
35
+ # These keys will be downcased upon creating or modifying a user and when used
36
+ # to authenticate or find a user. Default is :email.
37
+ config.case_insensitive_keys = [ :email ]
38
+
39
+ # Tell if authentication through request.params is enabled. True by default.
40
+ # config.params_authenticatable = true
41
+
42
+ # Tell if authentication through HTTP Basic Auth is enabled. False by default.
43
+ # config.http_authenticatable = false
44
+
45
+ # If http headers should be returned for AJAX requests. True by default.
46
+ # config.http_authenticatable_on_xhr = true
47
+
48
+ # The realm used in Http Basic Authentication. "Application" by default.
49
+ # config.http_authentication_realm = "Application"
50
+
51
+ # ==> Configuration for :database_authenticatable
52
+ # For bcrypt, this is the cost for hashing the password and defaults to 10. If
53
+ # using other encryptors, it sets how many times you want the password re-encrypted.
54
+ config.stretches = 10
55
+
56
+ # ==> Configuration for :confirmable
57
+ # The time you want to give your user to confirm his account. During this time
58
+ # he will be able to access your application without confirming. Default is nil.
59
+ # When confirm_within is zero, the user won't be able to sign in without confirming.
60
+ # You can use this to let your user access some features of your application
61
+ # without confirming the account, but blocking it after a certain period
62
+ # (ie 2 days).
63
+ # config.confirm_within = 2.days
64
+
65
+ # Defines which key will be used when confirming an account
66
+ # config.confirmation_keys = [ :email ]
67
+
68
+ # ==> Configuration for :rememberable
69
+ # The time the user will be remembered without asking for credentials again.
70
+ # config.remember_for = 2.weeks
71
+
72
+ # If true, a valid remember token can be re-used between multiple browsers.
73
+ # config.remember_across_browsers = true
74
+
75
+ # If true, extends the user's remember period when remembered via cookie.
76
+ # config.extend_remember_period = false
77
+
78
+ # If true, uses the password salt as remember token. This should be turned
79
+ # to false if you are not using database authenticatable.
80
+ config.use_salt_as_remember_token = true
81
+
82
+ # ==> Configuration for :validatable
83
+ # Range for password length. Default is 6..20.
84
+ # config.password_length = 6..20
85
+
86
+ # Regex to use to validate the email address
87
+ # config.email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
88
+
89
+ # ==> Configuration for :timeoutable
90
+ # The time you want to timeout the user session without activity. After this
91
+ # time the user will be asked for credentials again. Default is 30 minutes.
92
+ # config.timeout_in = 30.minutes
93
+
94
+ # ==> Configuration for :lockable
95
+ # Defines which strategy will be used to lock an account.
96
+ # :failed_attempts = Locks an account after a number of failed attempts to sign in.
97
+ # :none = No lock strategy. You should handle locking by yourself.
98
+ # config.lock_strategy = :failed_attempts
99
+
100
+ # Defines which key will be used when locking and unlocking an account
101
+ # config.unlock_keys = [ :email ]
102
+
103
+ # Defines which strategy will be used to unlock an account.
104
+ # :email = Sends an unlock link to the user email
105
+ # :time = Re-enables login after a certain amount of time (see :unlock_in below)
106
+ # :both = Enables both strategies
107
+ # :none = No unlock strategy. You should handle unlocking by yourself.
108
+ # config.unlock_strategy = :both
109
+
110
+ # Number of authentication tries before locking an account if lock_strategy
111
+ # is failed attempts.
112
+ # config.maximum_attempts = 20
113
+
114
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
115
+ # config.unlock_in = 1.hour
116
+
117
+ # ==> Configuration for :recoverable
118
+ #
119
+ # Defines which key will be used when recovering the password for an account
120
+ # config.reset_password_keys = [ :email ]
121
+
122
+ # ==> Configuration for :encryptable
123
+ # Allow you to use another encryption algorithm besides bcrypt (default). You can use
124
+ # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
125
+ # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
126
+ # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
127
+ # REST_AUTH_SITE_KEY to pepper)
128
+ # config.encryptor = :sha512
129
+
130
+ # Setup a pepper to generate the encrypted password.
131
+ config.pepper = "8cca6618709ea1214a9da8fd396b2a25e5f1e87403ffc9063309c30f6225927bae331d60e40b83b15ab93c7e80bf70fb975dab3cafe843f1c00b814eef0e22c8"
132
+
133
+ # ==> Configuration for :token_authenticatable
134
+ # Defines name of the authentication token params key
135
+ # config.token_authentication_key = :auth_token
136
+
137
+ # If true, authentication through token does not store user in session and needs
138
+ # to be supplied on each request. Useful if you are using the token as API token.
139
+ # config.stateless_token = false
140
+
141
+ # ==> Scopes configuration
142
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
143
+ # "users/sessions/new". It's turned off by default because it's slower if you
144
+ # are using only default views.
145
+ # config.scoped_views = false
146
+
147
+ # Configure the default scope given to Warden. By default it's the first
148
+ # devise role declared in your routes (usually :user).
149
+ # config.default_scope = :user
150
+
151
+ # Configure sign_out behavior.
152
+ # Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
153
+ # The default is true, which means any logout action will sign out all active scopes.
154
+ # config.sign_out_all_scopes = true
155
+
156
+ # ==> Navigation configuration
157
+ # Lists the formats that should be treated as navigational. Formats like
158
+ # :html, should redirect to the sign in page when the user does not have
159
+ # access, but formats like :xml or :json, should return 401.
160
+ # If you have any extra navigational formats, like :iphone or :mobile, you
161
+ # should add them to the navigational formats lists. Default is [:html]
162
+ # config.navigational_formats = [:html, :iphone]
163
+
164
+ # The default HTTP method used to sign out a resource. Default is :get.
165
+ # config.sign_out_via = :get
166
+
167
+ # ==> OmniAuth
168
+ # config.omniauth :facebook, 'APP_ID', 'APP_SECRET', :scope => 'email,offline_access'
169
+ # config.omniauth :open_id
170
+
171
+ # ==> Warden configuration
172
+ # If you want to use other strategies, that are not supported by Devise, or
173
+ # change the failure app, you can configure them inside the config.warden block.
174
+ #
175
+ # config.warden do |manager|
176
+ # manager.failure_app = AnotherApp
177
+ # manager.default_strategies(:scope => :user).unshift :some_external_strategy
178
+ # end
179
+ end