diff --git a/lib/devise/orm/active_record.rb b/lib/devise/orm/active_record.rb index 4ffe1989..781c8dfe 100644 --- a/lib/devise/orm/active_record.rb +++ b/lib/devise/orm/active_record.rb @@ -23,7 +23,7 @@ module Devise include Devise::Schema # Tell how to apply schema methods. - def apply_schema(name, type, options={}) + def apply_devise_schema(name, type, options={}) column name, type.to_s.downcase.to_sym, options end end diff --git a/lib/devise/orm/data_mapper.rb b/lib/devise/orm/data_mapper.rb index 0de22c70..ae157976 100644 --- a/lib/devise/orm/data_mapper.rb +++ b/lib/devise/orm/data_mapper.rb @@ -21,7 +21,7 @@ module Devise # Tell how to apply schema methods. This automatically maps :limit to # :length and :null to :required. - def apply_schema(name, type, options={}) + def apply_devise_schema(name, type, options={}) SCHEMA_OPTIONS.each do |old_key, new_key| next unless options.key?(old_key) options[new_key] = options.delete(old_key) diff --git a/lib/devise/orm/mongoid.rb b/lib/devise/orm/mongoid.rb index 0c110208..7cb368da 100644 --- a/lib/devise/orm/mongoid.rb +++ b/lib/devise/orm/mongoid.rb @@ -4,32 +4,21 @@ module Devise module Hook def devise_modules_hook! extend Schema - include ::Mongoid::Timestamps - include Compatibility yield return unless Devise.apply_schema devise_modules.each { |m| send(m) if respond_to?(m, true) } end end - + module Schema include Devise::Schema # Tell how to apply schema methods - def apply_schema(name, type, options={}) + def apply_devise_schema(name, type, options={}) type = Time if type == DateTime field name, { :type => type }.merge(options) end end - - module Compatibility - def save(validate = true) - if validate.is_a?(Hash) && validate.has_key?(:validate) - validate = validate[:validate] - end - super(validate) - end - end end end end diff --git a/lib/devise/schema.rb b/lib/devise/schema.rb index e82c8372..b9d58474 100644 --- a/lib/devise/schema.rb +++ b/lib/devise/schema.rb @@ -21,42 +21,42 @@ module Devise ActiveSupport::Deprecation.warn ":encryptor as option is deprecated, simply remove it." end - apply_schema :email, String, :null => null, :default => default - apply_schema :encrypted_password, String, :null => null, :default => default, :limit => 128 - apply_schema :password_salt, String, :null => null, :default => default + apply_devise_schema :email, String, :null => null, :default => default + apply_devise_schema :encrypted_password, String, :null => null, :default => default, :limit => 128 + apply_devise_schema :password_salt, String, :null => null, :default => default end # Creates authentication_token. def token_authenticatable(options={}) - apply_schema :authentication_token, String + apply_devise_schema :authentication_token, String end # Creates confirmation_token, confirmed_at and confirmation_sent_at. def confirmable - apply_schema :confirmation_token, String - apply_schema :confirmed_at, DateTime - apply_schema :confirmation_sent_at, DateTime + apply_devise_schema :confirmation_token, String + apply_devise_schema :confirmed_at, DateTime + apply_devise_schema :confirmation_sent_at, DateTime end # Creates reset_password_token. def recoverable - apply_schema :reset_password_token, String + apply_devise_schema :reset_password_token, String end # Creates remember_token and remember_created_at. def rememberable - apply_schema :remember_token, String - apply_schema :remember_created_at, DateTime + apply_devise_schema :remember_token, String + apply_devise_schema :remember_created_at, DateTime end # Creates sign_in_count, current_sign_in_at, last_sign_in_at, # current_sign_in_ip, last_sign_in_ip. def trackable - apply_schema :sign_in_count, Integer, :default => 0 - apply_schema :current_sign_in_at, DateTime - apply_schema :last_sign_in_at, DateTime - apply_schema :current_sign_in_ip, String - apply_schema :last_sign_in_ip, String + apply_devise_schema :sign_in_count, Integer, :default => 0 + apply_devise_schema :current_sign_in_at, DateTime + apply_devise_schema :last_sign_in_at, DateTime + apply_devise_schema :current_sign_in_ip, String + apply_devise_schema :last_sign_in_ip, String end # Creates failed_attempts, unlock_token and locked_at depending on the options given. @@ -75,18 +75,18 @@ module Devise lock_strategy ||= :failed_attempts if lock_strategy == :failed_attempts - apply_schema :failed_attempts, Integer, :default => 0 + apply_devise_schema :failed_attempts, Integer, :default => 0 end if [:both, :email].include?(unlock_strategy) - apply_schema :unlock_token, String + apply_devise_schema :unlock_token, String end - apply_schema :locked_at, DateTime + apply_devise_schema :locked_at, DateTime end # Overwrite with specific modification to create your own schema. - def apply_schema(name, type, options={}) + def apply_devise_schema(name, type, options={}) raise NotImplementedError end end diff --git a/test/integration/database_authenticatable_test.rb b/test/integration/database_authenticatable_test.rb index 4ace5474..3641ca5d 100644 --- a/test/integration/database_authenticatable_test.rb +++ b/test/integration/database_authenticatable_test.rb @@ -309,4 +309,13 @@ class AuthenticationTest < ActionController::IntegrationTest get '/sign_in' end end + + # Invalid session + test 'invalid session does not cause errors' do + get "/" + session["warden.user.user.key"] = 170410 + + get users_path + assert_equal 302, response.status + end end diff --git a/test/rails_app/app/mongoid/admin.rb b/test/rails_app/app/mongoid/admin.rb index 083d7f2e..2fd0f10b 100644 --- a/test/rails_app/app/mongoid/admin.rb +++ b/test/rails_app/app/mongoid/admin.rb @@ -1,15 +1,6 @@ class Admin include Mongoid::Document + include Shim devise :database_authenticatable, :timeoutable, :registerable, :recoverable - - def self.last(options={}) - options.delete(:order) if options[:order] == "id" - super options - end - - # overwrite equality (because some devise tests use this for asserting model equality) - def ==(other) - other.is_a?(self.class) && _id == other._id - end end diff --git a/test/rails_app/app/mongoid/shim.rb b/test/rails_app/app/mongoid/shim.rb new file mode 100644 index 00000000..fb01ec0d --- /dev/null +++ b/test/rails_app/app/mongoid/shim.rb @@ -0,0 +1,16 @@ +module Shim + extend ::ActiveSupport::Concern + include ::Mongoid::Timestamps + + module ClassMethods + def last(options={}) + options.delete(:order) if options[:order] == "id" + super(options) + end + end + + # overwrite equality (because some devise tests use this for asserting model equality) + def ==(other) + other.is_a?(self.class) && _id == other._id + end +end diff --git a/test/rails_app/app/mongoid/user.rb b/test/rails_app/app/mongoid/user.rb index db622b7b..a133f459 100644 --- a/test/rails_app/app/mongoid/user.rb +++ b/test/rails_app/app/mongoid/user.rb @@ -1,21 +1,10 @@ class User include Mongoid::Document + include Shim field :created_at, :type => DateTime devise :database_authenticatable, :confirmable, :lockable, :recoverable, :registerable, :rememberable, :timeoutable, :token_authenticatable, :trackable, :validatable - - # attr_accessible :username, :email, :password, :password_confirmation - - def self.last(options={}) - options.delete(:order) if options[:order] == "id" - super options - end - - # overwrite equality (because some devise tests use this for asserting model equality) - def ==(other) - other.is_a?(self.class) && _id == other._id - end end