title: Rails: BCrypt::Errors::InvalidSalt: invalid salt
body: <p>Loosely following Ryan Bates's <a href="http://railscasts.com/episodes/275-how-i-test?view=asciicast" rel="nofollow noreferrer">How I Test</a> Railscast to implement sending an email confirmation token to users when they sign up.</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_secure_password
    strip_attributes except: [:password, :password_confirmation]
    ...
  
    def send_email_confirmation
      generate_token(:email_token)
      self.email_token_sent_at = Time.zone.now
      save!
      UserMailer.email_confirmation(self).deliver
    end
  
    private
      def generate_token(column)
        begin
          self[column] = SecureRandom.urlsafe_base64
        end while User.exists?(column =&gt; self[column])
      end
  end
  </code></pre>
  
  <p>This is failing (in feature specs and when manually clicking through sign-up process) with: </p>
  
  <pre><code>Failures:
  
    1) UserPages sign up with valid information should create a user
       Failure/Error: expect { click_button submit }.to change(User, :count).by(1)
       BCrypt::Errors::InvalidSalt:
         invalid salt
       # ./app/models/user.rb:70:in `send_email_confirmation'
       # ./app/controllers/users_controller.rb:27:in `create'
       # ./spec/features/user_pages_spec.rb:165:in `block (5 levels) in &lt;top (required)&gt;'
       # ./spec/features/user_pages_spec.rb:165:in `block (4 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>I've tried reinstalling bcrypt gem (as suggested <a href="https://stackoverflow.com/questions/11579696/bcrypterrorsinvalidsalt-invalid-salt-devise">elsewhere</a> even though it was Devise related and I'm not using Devise): <code>gem uninstall bcrypt-ruby</code> and then <code>gem install bcrypt-ruby</code> but to no avail. ideas?</p>