ramon-devise 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. data/CHANGELOG.rdoc +109 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +243 -0
  4. data/Rakefile +45 -0
  5. data/TODO +8 -0
  6. data/app/controllers/confirmations_controller.rb +33 -0
  7. data/app/controllers/passwords_controller.rb +41 -0
  8. data/app/controllers/sessions_controller.rb +33 -0
  9. data/app/models/devise_mailer.rb +53 -0
  10. data/app/views/confirmations/new.html.erb +16 -0
  11. data/app/views/devise_mailer/confirmation_instructions.html.erb +5 -0
  12. data/app/views/devise_mailer/reset_password_instructions.html.erb +8 -0
  13. data/app/views/passwords/edit.html.erb +20 -0
  14. data/app/views/passwords/new.html.erb +16 -0
  15. data/app/views/sessions/new.html.erb +23 -0
  16. data/generators/devise/USAGE +5 -0
  17. data/generators/devise/devise_generator.rb +25 -0
  18. data/generators/devise/lib/route_devise.rb +32 -0
  19. data/generators/devise/templates/README +22 -0
  20. data/generators/devise/templates/migration.rb +20 -0
  21. data/generators/devise/templates/model.rb +5 -0
  22. data/generators/devise_install/USAGE +3 -0
  23. data/generators/devise_install/devise_install_generator.rb +9 -0
  24. data/generators/devise_install/templates/devise.rb +40 -0
  25. data/generators/devise_views/USAGE +3 -0
  26. data/generators/devise_views/devise_views_generator.rb +24 -0
  27. data/init.rb +2 -0
  28. data/lib/devise.rb +79 -0
  29. data/lib/devise/controllers/filters.rb +111 -0
  30. data/lib/devise/controllers/helpers.rb +130 -0
  31. data/lib/devise/controllers/url_helpers.rb +49 -0
  32. data/lib/devise/failure.rb +38 -0
  33. data/lib/devise/hooks/confirmable.rb +11 -0
  34. data/lib/devise/hooks/rememberable.rb +27 -0
  35. data/lib/devise/locales/en.yml +18 -0
  36. data/lib/devise/mapping.rb +120 -0
  37. data/lib/devise/migrations.rb +51 -0
  38. data/lib/devise/models.rb +105 -0
  39. data/lib/devise/models/authenticatable.rb +97 -0
  40. data/lib/devise/models/confirmable.rb +156 -0
  41. data/lib/devise/models/recoverable.rb +88 -0
  42. data/lib/devise/models/rememberable.rb +95 -0
  43. data/lib/devise/models/validatable.rb +36 -0
  44. data/lib/devise/rails.rb +17 -0
  45. data/lib/devise/rails/routes.rb +109 -0
  46. data/lib/devise/rails/warden_compat.rb +26 -0
  47. data/lib/devise/strategies/authenticatable.rb +46 -0
  48. data/lib/devise/strategies/base.rb +24 -0
  49. data/lib/devise/strategies/rememberable.rb +35 -0
  50. data/lib/devise/version.rb +3 -0
  51. data/lib/devise/warden.rb +24 -0
  52. data/test/controllers/filters_test.rb +103 -0
  53. data/test/controllers/helpers_test.rb +55 -0
  54. data/test/controllers/url_helpers_test.rb +47 -0
  55. data/test/devise_test.rb +72 -0
  56. data/test/failure_test.rb +34 -0
  57. data/test/integration/authenticatable_test.rb +187 -0
  58. data/test/integration/confirmable_test.rb +89 -0
  59. data/test/integration/recoverable_test.rb +131 -0
  60. data/test/integration/rememberable_test.rb +65 -0
  61. data/test/mailers/confirmation_instructions_test.rb +59 -0
  62. data/test/mailers/reset_password_instructions_test.rb +62 -0
  63. data/test/mapping_test.rb +101 -0
  64. data/test/models/authenticatable_test.rb +118 -0
  65. data/test/models/confirmable_test.rb +237 -0
  66. data/test/models/recoverable_test.rb +141 -0
  67. data/test/models/rememberable_test.rb +130 -0
  68. data/test/models/validatable_test.rb +99 -0
  69. data/test/models_test.rb +111 -0
  70. data/test/rails_app/app/controllers/admins_controller.rb +6 -0
  71. data/test/rails_app/app/controllers/application_controller.rb +10 -0
  72. data/test/rails_app/app/controllers/home_controller.rb +4 -0
  73. data/test/rails_app/app/controllers/users_controller.rb +7 -0
  74. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  75. data/test/rails_app/app/models/account.rb +3 -0
  76. data/test/rails_app/app/models/admin.rb +3 -0
  77. data/test/rails_app/app/models/organizer.rb +3 -0
  78. data/test/rails_app/app/models/user.rb +3 -0
  79. data/test/rails_app/config/boot.rb +110 -0
  80. data/test/rails_app/config/environment.rb +41 -0
  81. data/test/rails_app/config/environments/development.rb +17 -0
  82. data/test/rails_app/config/environments/production.rb +28 -0
  83. data/test/rails_app/config/environments/test.rb +28 -0
  84. data/test/rails_app/config/initializers/new_rails_defaults.rb +21 -0
  85. data/test/rails_app/config/initializers/session_store.rb +15 -0
  86. data/test/rails_app/config/routes.rb +18 -0
  87. data/test/routes_test.rb +79 -0
  88. data/test/support/assertions_helper.rb +22 -0
  89. data/test/support/integration_tests_helper.rb +66 -0
  90. data/test/support/model_tests_helper.rb +51 -0
  91. data/test/test_helper.rb +40 -0
  92. metadata +154 -0
@@ -0,0 +1,99 @@
1
+ require 'test/test_helper'
2
+
3
+ class ValidatableTest < ActiveSupport::TestCase
4
+
5
+ test 'should require email to be set' do
6
+ user = new_user(:email => nil)
7
+ assert user.invalid?
8
+ assert user.errors[:email]
9
+ assert_equal 'can\'t be blank', user.errors[:email]
10
+ end
11
+
12
+ test 'should require uniqueness of email, allowing blank' do
13
+ existing_user = create_user
14
+ user = new_user(:email => '')
15
+ assert user.invalid?
16
+ assert_not_equal 'has already been taken', user.errors[:email]
17
+ user.email = existing_user.email
18
+ assert user.invalid?
19
+ assert user.errors[:email]
20
+ assert_equal 1, user.errors[:email].to_a.size
21
+ assert_equal 'has already been taken', user.errors[:email]
22
+ end
23
+
24
+ test 'should require correct email format, allowing blank' do
25
+ user = new_user(:email => '')
26
+ assert user.invalid?
27
+ assert_not_equal 'is invalid', user.errors[:email]
28
+ %w(invalid_email_format email@invalid invalid$character@mail.com other@not 123).each do |email|
29
+ user.email = email
30
+ assert user.invalid?, 'should be invalid with email ' << email
31
+ assert user.errors[:email]
32
+ assert_equal 1, user.errors[:email].to_a.size
33
+ assert_equal 'is invalid', user.errors[:email]
34
+ end
35
+ end
36
+
37
+ test 'should accept valid emails' do
38
+ %w(a.b.c@example.com test_mail@gmail.com any@any.net email@test.br 123@mail.test).each do |email|
39
+ user = new_user(:email => email)
40
+ assert user.valid?, 'should be valid with email ' << email
41
+ assert_nil user.errors[:email]
42
+ end
43
+ end
44
+
45
+ test 'should require password to be set when creating a new record' do
46
+ user = new_user(:password => '', :password_confirmation => '')
47
+ assert user.invalid?
48
+ assert user.errors[:password]
49
+ assert_equal 'can\'t be blank', user.errors[:password]
50
+ end
51
+
52
+ test 'should require confirmation to be set when creating a new record' do
53
+ user = new_user(:password => 'new_password', :password_confirmation => 'blabla')
54
+ assert user.invalid?
55
+ assert user.errors[:password]
56
+ assert_equal 'doesn\'t match confirmation', user.errors[:password]
57
+ end
58
+
59
+ test 'should require password when updating/reseting password' do
60
+ user = create_user
61
+ user.password = ''
62
+ user.password_confirmation = ''
63
+ assert user.invalid?
64
+ assert user.errors[:password]
65
+ assert_equal 'can\'t be blank', user.errors[:password]
66
+ end
67
+
68
+ test 'should require confirmation when updating/reseting password' do
69
+ user = create_user
70
+ user.password_confirmation = 'another_password'
71
+ assert user.invalid?
72
+ assert user.errors[:password]
73
+ assert_equal 'doesn\'t match confirmation', user.errors[:password]
74
+ end
75
+
76
+ test 'should require a password with minimum of 6 characters' do
77
+ user = new_user(:password => '12345', :password_confirmation => '12345')
78
+ assert user.invalid?
79
+ assert user.errors[:password]
80
+ assert_equal 'is too short (minimum is 6 characters)', user.errors[:password]
81
+ end
82
+
83
+ test 'should require a password with maximum of 20 characters long' do
84
+ user = new_user(:password => 'x'*21, :password_confirmation => 'x'*21)
85
+ assert user.invalid?
86
+ assert user.errors[:password]
87
+ assert_equal 'is too long (maximum is 20 characters)', user.errors[:password]
88
+ end
89
+
90
+ test 'should not require password length when it\'s not changed' do
91
+ user = create_user.reload
92
+ user.password = user.password_confirmation = nil
93
+ assert user.valid?
94
+ user.password_confirmation = 'confirmation'
95
+ assert user.invalid?
96
+ assert user.errors[:password]
97
+ assert_not user.errors[:password].to_a.include?('is too short (minimum is 6 characters)')
98
+ end
99
+ end
@@ -0,0 +1,111 @@
1
+ require 'test/test_helper'
2
+
3
+ class Authenticable < User
4
+ devise
5
+ end
6
+
7
+ class Confirmable < User
8
+ devise :confirmable
9
+ end
10
+
11
+ class Recoverable < User
12
+ devise :recoverable
13
+ end
14
+
15
+ class Rememberable < User
16
+ devise :rememberable
17
+ end
18
+
19
+ class Validatable < User
20
+ devise :validatable
21
+ end
22
+
23
+ class Devisable < User
24
+ devise :all
25
+ end
26
+
27
+ class Exceptable < User
28
+ devise :all, :except => [:recoverable, :rememberable, :validatable]
29
+ end
30
+
31
+ class Configurable < User
32
+ devise :all, :stretches => 15,
33
+ :pepper => 'abcdef',
34
+ :confirm_within => 5.days,
35
+ :remember_for => 7.days
36
+ end
37
+
38
+ class ActiveRecordTest < ActiveSupport::TestCase
39
+
40
+ def include_module?(klass, mod)
41
+ klass.devise_modules.include?(mod) &&
42
+ klass.included_modules.include?(Devise::Models::const_get(mod.to_s.classify))
43
+ end
44
+
45
+ def assert_include_modules(klass, *modules)
46
+ modules.each do |mod|
47
+ assert include_module?(klass, mod)
48
+ end
49
+ end
50
+
51
+ def assert_not_include_modules(klass, *modules)
52
+ modules.each do |mod|
53
+ assert_not include_module?(klass, mod)
54
+ end
55
+ end
56
+
57
+ test 'include by default authenticatable only' do
58
+ assert_include_modules Authenticable, :authenticatable
59
+ assert_not_include_modules Authenticable, :confirmable, :recoverable, :rememberable, :validatable
60
+ end
61
+
62
+ test 'add confirmable module only' do
63
+ assert_include_modules Confirmable, :authenticatable, :confirmable
64
+ assert_not_include_modules Confirmable, :recoverable, :rememberable, :validatable
65
+ end
66
+
67
+ test 'add recoverable module only' do
68
+ assert_include_modules Recoverable, :authenticatable, :recoverable
69
+ assert_not_include_modules Recoverable, :confirmable, :rememberable, :validatable
70
+ end
71
+
72
+ test 'add rememberable module only' do
73
+ assert_include_modules Rememberable, :authenticatable, :rememberable
74
+ assert_not_include_modules Rememberable, :confirmable, :recoverable, :validatable
75
+ end
76
+
77
+ test 'add validatable module only' do
78
+ assert_include_modules Validatable, :authenticatable, :validatable
79
+ assert_not_include_modules Validatable, :confirmable, :recoverable, :rememberable
80
+ end
81
+
82
+ test 'add all modules' do
83
+ assert_include_modules Devisable,
84
+ :authenticatable, :confirmable, :recoverable, :rememberable, :validatable
85
+ end
86
+
87
+ test 'configure modules with except option' do
88
+ assert_include_modules Exceptable, :authenticatable, :confirmable
89
+ assert_not_include_modules Exceptable, :recoverable, :rememberable, :validatable
90
+ end
91
+
92
+ test 'set a default value for stretches' do
93
+ assert_equal 15, Configurable.new.stretches
94
+ end
95
+
96
+ test 'set a default value for pepper' do
97
+ assert_equal 'abcdef', Configurable.new.pepper
98
+ end
99
+
100
+ test 'set a default value for confirm_within' do
101
+ assert_equal 5.days, Configurable.new.confirm_within
102
+ end
103
+
104
+ test 'set a default value for remember_for' do
105
+ assert_equal 7.days, Configurable.new.remember_for
106
+ end
107
+
108
+ test 'set null fields on migrations' do
109
+ Admin.create!
110
+ end
111
+ end
@@ -0,0 +1,6 @@
1
+ class AdminsController < ApplicationController
2
+ before_filter :authenticate_admin!
3
+
4
+ def index
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ # Filters added to this controller apply to all controllers in the application.
2
+ # Likewise, all the methods added will be available for all controllers.
3
+
4
+ class ApplicationController < ActionController::Base
5
+ helper :all # include all helpers, all the time
6
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
7
+
8
+ # Scrub sensitive parameters from your log
9
+ filter_parameter_logging :password
10
+ end
@@ -0,0 +1,4 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ class UsersController < ApplicationController
2
+ before_filter :authenticate_user!
3
+
4
+ def index
5
+ user_session[:cart] = "Cart"
6
+ end
7
+ 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,3 @@
1
+ class Account < ActiveRecord::Base
2
+ devise :all
3
+ end
@@ -0,0 +1,3 @@
1
+ class Admin < ActiveRecord::Base
2
+ devise :all, :except => [:recoverable, :confirmable, :rememberable, :validatable]
3
+ end
@@ -0,0 +1,3 @@
1
+ class Organizer < ActiveRecord::Base
2
+ devise :all
3
+ end
@@ -0,0 +1,3 @@
1
+ class User < ActiveRecord::Base
2
+ devise :all
3
+ end
@@ -0,0 +1,110 @@
1
+ # Don't change this file!
2
+ # Configure your app in config/environment.rb and config/environments/*.rb
3
+
4
+ RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
5
+
6
+ module Rails
7
+ class << self
8
+ def boot!
9
+ unless booted?
10
+ preinitialize
11
+ pick_boot.run
12
+ end
13
+ end
14
+
15
+ def booted?
16
+ defined? Rails::Initializer
17
+ end
18
+
19
+ def pick_boot
20
+ (vendor_rails? ? VendorBoot : GemBoot).new
21
+ end
22
+
23
+ def vendor_rails?
24
+ File.exist?("#{RAILS_ROOT}/vendor/rails")
25
+ end
26
+
27
+ def preinitialize
28
+ load(preinitializer_path) if File.exist?(preinitializer_path)
29
+ end
30
+
31
+ def preinitializer_path
32
+ "#{RAILS_ROOT}/config/preinitializer.rb"
33
+ end
34
+ end
35
+
36
+ class Boot
37
+ def run
38
+ load_initializer
39
+ Rails::Initializer.run(:set_load_path)
40
+ end
41
+ end
42
+
43
+ class VendorBoot < Boot
44
+ def load_initializer
45
+ require "#{RAILS_ROOT}/vendor/rails/railties/lib/initializer"
46
+ Rails::Initializer.run(:install_gem_spec_stubs)
47
+ Rails::GemDependency.add_frozen_gem_path
48
+ end
49
+ end
50
+
51
+ class GemBoot < Boot
52
+ def load_initializer
53
+ self.class.load_rubygems
54
+ load_rails_gem
55
+ require 'initializer'
56
+ end
57
+
58
+ def load_rails_gem
59
+ if version = self.class.gem_version
60
+ gem 'rails', version
61
+ else
62
+ gem 'rails'
63
+ end
64
+ rescue Gem::LoadError => load_error
65
+ $stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
66
+ exit 1
67
+ end
68
+
69
+ class << self
70
+ def rubygems_version
71
+ Gem::RubyGemsVersion rescue nil
72
+ end
73
+
74
+ def gem_version
75
+ if defined? RAILS_GEM_VERSION
76
+ RAILS_GEM_VERSION
77
+ elsif ENV.include?('RAILS_GEM_VERSION')
78
+ ENV['RAILS_GEM_VERSION']
79
+ else
80
+ parse_gem_version(read_environment_rb)
81
+ end
82
+ end
83
+
84
+ def load_rubygems
85
+ min_version = '1.3.2'
86
+ require 'rubygems'
87
+ unless rubygems_version >= min_version
88
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
89
+ exit 1
90
+ end
91
+
92
+ rescue LoadError
93
+ $stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
94
+ exit 1
95
+ end
96
+
97
+ def parse_gem_version(text)
98
+ $1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
99
+ end
100
+
101
+ private
102
+ def read_environment_rb
103
+ File.read("#{RAILS_ROOT}/config/environment.rb")
104
+ end
105
+ end
106
+ end
107
+ end
108
+
109
+ # All that for this:
110
+ Rails.boot!
@@ -0,0 +1,41 @@
1
+ # Be sure to restart your server when you modify this file
2
+
3
+ # Specifies gem version of Rails to use when vendor/rails is not present
4
+ RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION
5
+
6
+ # Bootstrap the Rails environment, frameworks, and default configuration
7
+ require File.join(File.dirname(__FILE__), 'boot')
8
+
9
+ Rails::Initializer.run do |config|
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Add additional load paths for your own custom dirs
15
+ # config.load_paths += %W( #{RAILS_ROOT}/extras )
16
+
17
+ # Specify gems that this application depends on and have them installed with rake gems:install
18
+ # config.gem "bj"
19
+ # config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
20
+ # config.gem "sqlite3-ruby", :lib => "sqlite3"
21
+ # config.gem "aws-s3", :lib => "aws/s3"
22
+
23
+ # Only load the plugins named here, in the order given (default is alphabetical).
24
+ # :all can be used as a placeholder for all plugins not explicitly named
25
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
26
+
27
+ # Skip frameworks you're not going to use. To use Rails without a database,
28
+ # you must remove the Active Record framework.
29
+ # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
30
+
31
+ # Activate observers that should always be running
32
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
33
+
34
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
35
+ # Run "rake -D time" for a list of tasks for finding time zone names.
36
+ config.time_zone = 'UTC'
37
+
38
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
39
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}')]
40
+ # config.i18n.default_locale = :en
41
+ end
@@ -0,0 +1,17 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # In the development environment your application's code is reloaded on
4
+ # every request. This slows down response time but is perfect for development
5
+ # since you don't have to restart the webserver when you make code changes.
6
+ config.cache_classes = false
7
+
8
+ # Log error messages when you accidentally call methods on nil.
9
+ config.whiny_nils = true
10
+
11
+ # Show full error reports and disable caching
12
+ config.action_controller.consider_all_requests_local = true
13
+ config.action_view.debug_rjs = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send
17
+ config.action_mailer.raise_delivery_errors = false
@@ -0,0 +1,28 @@
1
+ # Settings specified here will take precedence over those in config/environment.rb
2
+
3
+ # The production environment is meant for finished, "live" apps.
4
+ # Code is not reloaded between requests
5
+ config.cache_classes = true
6
+
7
+ # Full error reports are disabled and caching is turned on
8
+ config.action_controller.consider_all_requests_local = false
9
+ config.action_controller.perform_caching = true
10
+ config.action_view.cache_template_loading = 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
+ # Enable serving of images, stylesheets, and javascripts from an asset server
22
+ # config.action_controller.asset_host = "http://assets.example.com"
23
+
24
+ # Disable delivery errors, bad email addresses will be ignored
25
+ # config.action_mailer.raise_delivery_errors = false
26
+
27
+ # Enable threaded mode
28
+ # config.threadsafe!