aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/test/cases/secure_password_test.rb
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2014-06-14 00:39:43 -0700
committerGodfrey Chan <godfreykfc@gmail.com>2014-06-14 00:43:47 -0700
commitee4e86fa4bb6ab0406127e2708e9c3db346ba314 (patch)
tree99518490acf325bdbcb8abcaf12ea060d8c9b1aa /activemodel/test/cases/secure_password_test.rb
parentc416bb87294b05225c5cb4872fd30a067277fd58 (diff)
downloadrails-ee4e86fa4bb6ab0406127e2708e9c3db346ba314.tar.gz
rails-ee4e86fa4bb6ab0406127e2708e9c3db346ba314.tar.bz2
rails-ee4e86fa4bb6ab0406127e2708e9c3db346ba314.zip
Cleaned up the `has_secure_password` test cases
* Grouped the valid test cases in one place * Make the length of the generated password obvious * Removed two wrong (copy-and-pasted) test cases
Diffstat (limited to 'activemodel/test/cases/secure_password_test.rb')
-rw-r--r--activemodel/test/cases/secure_password_test.rb62
1 files changed, 29 insertions, 33 deletions
diff --git a/activemodel/test/cases/secure_password_test.rb b/activemodel/test/cases/secure_password_test.rb
index f6dfdc5342..40a5de3367 100644
--- a/activemodel/test/cases/secure_password_test.rb
+++ b/activemodel/test/cases/secure_password_test.rb
@@ -20,7 +20,7 @@ class SecurePasswordTest < ActiveModel::TestCase
ActiveModel::SecurePassword.min_cost = @original_min_cost
end
- test "create and updating without validations" do
+ test "create/update without validations" do
assert @visitor.valid?(:create), 'visitor should be valid'
assert @visitor.valid?(:update), 'visitor should be valid'
@@ -31,6 +31,18 @@ class SecurePasswordTest < ActiveModel::TestCase
assert @visitor.valid?(:update), 'visitor should be valid'
end
+ test "create a new user with validations and valid password/confirmation" do
+ @user.password = 'password'
+ @user.password_confirmation = 'password'
+
+ assert @user.valid?(:create), 'user should be valid'
+
+ @user.password = 'a' * 72
+ @user.password_confirmation = 'a' * 72
+
+ assert @user.valid?(:create), 'user should be valid'
+ end
+
test "create a new user with validation and a blank password" do
@user.password = ''
assert !@user.valid?(:create), 'user should be invalid'
@@ -45,15 +57,9 @@ class SecurePasswordTest < ActiveModel::TestCase
assert_equal ["can't be blank"], @user.errors[:password]
end
- test 'create a new user with validation and password length less than or equal to 72' do
- @user.password = 'nakshay' * 10
- @user.password_confirmation = @user.password
- assert @user.valid?(:create), 'user should be valid'
- end
-
test 'create a new user with validation and password length greater than 72' do
- @user.password = 'nakshay' * 11
- @user.password_confirmation = @user.password
+ @user.password = 'a' * 73
+ @user.password_confirmation = 'a' * 73
assert !@user.valid?(:create), 'user should be invalid'
assert_equal 1, @user.errors.count
assert_equal ["is too long (maximum is 72 characters)"], @user.errors[:password]
@@ -81,18 +87,22 @@ class SecurePasswordTest < ActiveModel::TestCase
assert_equal ["doesn't match Password"], @user.errors[:password_confirmation]
end
- test "create a new user with validation and a correct password confirmation" do
- @user.password = 'password'
- @user.password_confirmation = 'something else'
- assert !@user.valid?(:create), 'user should be invalid'
- assert_equal 1, @user.errors.count
- assert_equal ["doesn't match Password"], @user.errors[:password_confirmation]
- end
-
test "update an existing user with validation and no change in password" do
assert @existing_user.valid?(:update), 'user should be valid'
end
+ test "update an existing user with validations and valid password/confirmation" do
+ @user.password = 'password'
+ @user.password_confirmation = 'password'
+
+ assert @user.valid?(:update), 'user should be valid'
+
+ @user.password = 'a' * 72
+ @user.password_confirmation = 'a' * 72
+
+ assert @user.valid?(:update), 'user should be valid'
+ end
+
test "updating an existing user with validation and a blank password" do
@existing_user.password = ''
assert @existing_user.valid?(:update), 'user should be valid'
@@ -111,15 +121,9 @@ class SecurePasswordTest < ActiveModel::TestCase
assert_equal ["can't be blank"], @existing_user.errors[:password]
end
- test 'updating an existing user with validation and password length less than or equal to 72' do
- @existing_user.password = 'nakshay' * 10
- @existing_user.password_confirmation = @existing_user.password
- assert @existing_user.valid?(:update), 'user should be valid'
- end
-
test 'updating an existing user with validation and password length greater than 72' do
- @existing_user.password = 'nakshay' * 11
- @existing_user.password_confirmation = @existing_user.password
+ @existing_user.password = 'a' * 73
+ @existing_user.password_confirmation = 'a' * 73
assert !@existing_user.valid?(:update), 'user should be invalid'
assert_equal 1, @existing_user.errors.count
assert_equal ["is too long (maximum is 72 characters)"], @existing_user.errors[:password]
@@ -147,14 +151,6 @@ class SecurePasswordTest < ActiveModel::TestCase
assert_equal ["doesn't match Password"], @existing_user.errors[:password_confirmation]
end
- test "updating an existing user with validation and a correct password confirmation" do
- @existing_user.password = 'password'
- @existing_user.password_confirmation = 'something else'
- assert !@existing_user.valid?(:update), 'user should be invalid'
- assert_equal 1, @existing_user.errors.count
- assert_equal ["doesn't match Password"], @existing_user.errors[:password_confirmation]
- end
-
test "updating an existing user with validation and a blank password digest" do
@existing_user.password_digest = ''
assert !@existing_user.valid?(:update), 'user should be invalid'