How to make has_secure_password (bcrypt hashes) faster in Rails

Another independent answer for posterity. :)

Creating models with has_secure_password (which uses the bcrypt hash code) is very slow. User.create! takes about 0.3 seconds.

This slows down my test suite. How to increase productivity?

+4
source share
1 answer

Semyon Perepelitsa kindly posted the following snippet for test_helper / spec_helper:

 require "bcrypt" silence_warnings do BCrypt::Engine::DEFAULT_COST = BCrypt::Engine::MIN_COST end 

This weakens the hash function, making the hash calculation almost instantaneous in test mode - exactly what we want!

+5
source

All Articles