Permalink
Browse files

Use secure password min cost option in its own tests for a speed up

Around 0.564359s => 0.092244s speed up in my machine.
  • Loading branch information...
1 parent 293c121 commit c2c1ecb05e98dacab04f02c08cc3876de436e4dd @carlosantoniodasilva carlosantoniodasilva committed Nov 20, 2012
Showing with 10 additions and 2 deletions.
  1. +10 −2 activemodel/test/cases/secure_password_test.rb
@@ -5,13 +5,18 @@
require 'models/administrator'
class SecurePasswordTest < ActiveModel::TestCase
-
setup do
+ ActiveModel::SecurePassword.min_cost = true
+
@user = User.new
@visitor = Visitor.new
@oauthed_user = OauthedUser.new
end
+ teardown do
+ ActiveModel::SecurePassword.min_cost = false
+ end
+
test "blank password" do
@user.password = @visitor.password = ''
assert !@user.valid?(:create), 'user should be invalid'
@@ -70,13 +75,16 @@ class SecurePasswordTest < ActiveModel::TestCase
end
end
- test "Password digest cost defaults to bcrypt default cost" do
+ test "Password digest cost defaults to bcrypt default cost when min_cost is false" do
+ ActiveModel::SecurePassword.min_cost = false
+
@user.password = "secret"
assert_equal BCrypt::Engine::DEFAULT_COST, @user.password_digest.cost
end
test "Password digest cost can be set to bcrypt min cost to speed up tests" do
ActiveModel::SecurePassword.min_cost = true
+
@user.password = "secret"
assert_equal BCrypt::Engine::MIN_COST, @user.password_digest.cost
end

0 comments on commit c2c1ecb

Please sign in to comment.