test/overrides/data_mapper_test.rb in dm-devise-1.3.1 vs test/overrides/data_mapper_test.rb in dm-devise-1.4.0

- old
+ new

@@ -62,6 +62,61 @@ assert_equal email, user.email user.save assert_equal email.downcase, user.email end + + undef test_should_remove_whitespace_from_strip_whitespace_keys_when_saving + + test 'should remove whitespace from strip whitespace keys when saving' do + # strip_whitespace_keys is set to :email by default. + email = ' foo@bar.com ' + user = new_user(:email => email) + + assert_equal email, user.email + user.save + assert_equal email.strip, user.email + end +end + +class ValidatableTest < ActiveSupport::TestCase + # user.save! is failing in these tests, since validation are running anyway. + # See https://github.com/datamapper/dm-validations/pull/13. + + undef :"test_should_require_uniqueness_of_email_if_email_has_changed,_allowing_blank" + + test 'should require uniqueness of email if email has changed, allowing blank' do + existing_user = create_user + + user = new_user(:email => '') + assert user.invalid? + assert_no_match(/taken/, user.errors[:email].join) + + user.email = existing_user.email + assert user.invalid? + assert_match(/taken/, user.errors[:email].join) + + pending do + user.save(:validate => false) + assert user.valid? + end + end + + undef :"test_should_require_correct_email_format_if_email_has_changed,_allowing_blank" + + test 'should require correct email format if email has changed, allowing blank' do + user = new_user(:email => '') + assert user.invalid? + assert_not_equal 'is invalid', user.errors[:email].join + + %w(invalid_email_format 123 $$$ \(\) ).each do |email| + user.email = email + assert user.invalid?, 'should be invalid with email ' << email + assert_equal 'is invalid', user.errors[:email].join + end + + pending do + user.save(:validate => false) + assert user.valid? + end + end end