This commit is contained in:
Jon Phenow
2015-06-19 14:21:10 -05:00
parent eb091b867f
commit c744dcf07a
3 changed files with 33 additions and 6 deletions

View File

@@ -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")

View File

@@ -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

View File

@@ -0,0 +1,5 @@
module StubModelFilters
def stub_filter(name)
define_singleton_method(name) { |*| nil }
end
end