Sha256: e26c026cde408a337881af3f2d8ce1a738f17172c5d3a42f5f15a35fd6261910

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

require 'spec_helper'

describe Clearance::PasswordStrategies::SHA1 do
  subject do
    Class.new do
      attr_accessor :salt, :encrypted_password
      include Clearance::PasswordStrategies::SHA1

      def generate_random_code; "code"; end
    end.new
  end

  describe '#password=' do
    context 'when the password is set' do
      let(:salt) { 'salt' }
      let(:password) { 'password' }

      before do
        subject.salt = salt
        subject.password = password
      end

      it 'does not initialize the salt' do
        subject.salt.should == salt
      end

      it 'encrypts the password using SHA1 and the existing salt' do
        expected = Digest::SHA1.hexdigest("--#{salt}--#{password}--")
        subject.encrypted_password.should == expected
      end
    end

    context "when the password is not set" do
      before do
        subject.salt     = nil
        subject.password = ""
      end

      it "initializes the salt" do
        subject.salt.should_not be_nil
      end

      it "doesn't encrpt the password" do
        subject.encrypted_password.should be_nil
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
clearance-1.0.0.rc4 spec/models/sha1_spec.rb
clearance-1.0.0.rc3 spec/models/sha1_spec.rb
clearance-1.0.0.rc2 spec/models/sha1_spec.rb
clearance-1.0.0.rc1 spec/models/sha1_spec.rb