diff options
author | Trevor Turk <trevorturk@gmail.com> | 2012-11-14 09:42:54 -0600 |
---|---|---|
committer | Trevor Turk <trevorturk@gmail.com> | 2012-11-14 09:42:54 -0600 |
commit | 06faa6da808ef9e98455c35aefd4a4112c811c8f (patch) | |
tree | 4a2af25cbd23b2b91a1454a15f7890ffbfc80391 /activemodel/lib/active_model | |
parent | 087150d9b7a73f20677f9bc3ff52fe66b1f1e549 (diff) | |
download | rails-06faa6da808ef9e98455c35aefd4a4112c811c8f.tar.gz rails-06faa6da808ef9e98455c35aefd4a4112c811c8f.tar.bz2 rails-06faa6da808ef9e98455c35aefd4a4112c811c8f.zip |
Use BCrypt's MIN_COST in the test environment for speedier tests
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r-- | activemodel/lib/active_model/railtie.rb | 4 | ||||
-rw-r--r-- | activemodel/lib/active_model/secure_password.rb | 5 |
2 files changed, 8 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/railtie.rb b/activemodel/lib/active_model/railtie.rb index 75cde900e3..1671eb7bd4 100644 --- a/activemodel/lib/active_model/railtie.rb +++ b/activemodel/lib/active_model/railtie.rb @@ -4,5 +4,9 @@ require "rails" module ActiveModel class Railtie < Rails::Railtie # :nodoc: config.eager_load_namespaces << ActiveModel + + initializer "active_model.secure_password" do + ActiveModel::SecurePassword.min_cost = Rails.env.test? + end end end diff --git a/activemodel/lib/active_model/secure_password.rb b/activemodel/lib/active_model/secure_password.rb index 4b328b399a..3dc615c9f3 100644 --- a/activemodel/lib/active_model/secure_password.rb +++ b/activemodel/lib/active_model/secure_password.rb @@ -2,6 +2,8 @@ module ActiveModel module SecurePassword extend ActiveSupport::Concern + class << self; attr_accessor :min_cost; end + module ClassMethods # Adds methods to set and authenticate against a BCrypt password. # This mechanism requires you to have a password_digest attribute. @@ -88,7 +90,8 @@ module ActiveModel def password=(unencrypted_password) unless unencrypted_password.blank? @password = unencrypted_password - self.password_digest = BCrypt::Password.create(unencrypted_password) + cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST : BCrypt::Engine::DEFAULT_COST + self.password_digest = BCrypt::Password.create(unencrypted_password, cost: cost) end end end |