mirror of
https://github.com/heartcombo/devise.git
synced 2026-01-09 23:08:05 -05:00
tests
This commit is contained in:
@@ -3,6 +3,10 @@ require 'test_models'
|
||||
require 'digest/sha1'
|
||||
|
||||
class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
||||
def setup
|
||||
setup_mailer
|
||||
end
|
||||
|
||||
test 'should downcase case insensitive keys when saving' do
|
||||
# case_insensitive_keys is set to :email by default.
|
||||
email = 'Foo@Bar.com'
|
||||
@@ -225,6 +229,21 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
||||
assert_match "can't be blank", user.errors[:current_password].join
|
||||
end
|
||||
|
||||
test 'should not email on password change' do
|
||||
user = create_user
|
||||
assert_email_not_sent do
|
||||
assert user.update_attributes(password: 'newpass', password_confirmation: 'newpass')
|
||||
end
|
||||
end
|
||||
|
||||
test 'should email on password change when configured' do
|
||||
User.stubs(:send_password_change_notification).returns(true)
|
||||
user = create_user
|
||||
assert_email_sent user.email do
|
||||
assert user.update_attributes(password: 'newpass', password_confirmation: 'newpass')
|
||||
end
|
||||
end
|
||||
|
||||
test 'downcase_keys with validation' do
|
||||
User.create(email: "HEllO@example.com", password: "123456")
|
||||
user = User.create(email: "HEllO@example.com", password: "123456")
|
||||
|
||||
@@ -96,9 +96,10 @@ class CheckFieldsTest < ActiveSupport::TestCase
|
||||
test 'checks if the class respond_to the required fields' do
|
||||
Player = Class.new do
|
||||
extend Devise::Models
|
||||
extend StubModelFilters
|
||||
|
||||
def self.before_validation(instance)
|
||||
end
|
||||
stub_filter :before_validation
|
||||
stub_filter :after_update
|
||||
|
||||
devise :database_authenticatable
|
||||
|
||||
@@ -113,9 +114,10 @@ class CheckFieldsTest < ActiveSupport::TestCase
|
||||
test 'raises Devise::Models::MissingAtrribute and shows the missing attribute if the class doesn\'t respond_to one of the attributes' do
|
||||
Clown = Class.new do
|
||||
extend Devise::Models
|
||||
extend StubModelFilters
|
||||
|
||||
def self.before_validation(instance)
|
||||
end
|
||||
stub_filter :before_validation
|
||||
stub_filter :after_update
|
||||
|
||||
devise :database_authenticatable
|
||||
|
||||
@@ -130,9 +132,10 @@ class CheckFieldsTest < ActiveSupport::TestCase
|
||||
test 'raises Devise::Models::MissingAtrribute with all the missing attributes if there is more than one' do
|
||||
Magician = Class.new do
|
||||
extend Devise::Models
|
||||
extend StubModelFilters
|
||||
|
||||
def self.before_validation(instance)
|
||||
end
|
||||
stub_filter :before_validation
|
||||
stub_filter :after_update
|
||||
|
||||
devise :database_authenticatable
|
||||
end
|
||||
|
||||
5
test/support/stub_model_filters.rb
Normal file
5
test/support/stub_model_filters.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
module StubModelFilters
|
||||
def stub_filter(name)
|
||||
define_singleton_method(name) { |*| nil }
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user