Sha256: 2db4037c06136b7ad7b10a7e388f0c6d01a5b53ee373ada50c3eeefacc80e883

Contents?: true

Size: 1.01 KB

Versions: 13

Compression:

Stored size: 1.01 KB

Contents

require 'spec_helper'

describe Clearance::PasswordStrategies::SHA1 do
  subject do
    fake_model_with_password_strategy(Clearance::PasswordStrategies::SHA1)
  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

13 entries across 13 versions & 1 rubygems

Version Path
clearance-1.4.3 spec/models/sha1_spec.rb
clearance-1.4.2 spec/models/sha1_spec.rb
clearance-1.4.1 spec/models/sha1_spec.rb
clearance-1.4.0 spec/models/sha1_spec.rb
clearance-1.3.0 spec/models/sha1_spec.rb
clearance-1.2.1 spec/models/sha1_spec.rb
clearance-1.2.0 spec/models/sha1_spec.rb
clearance-1.1.0 spec/models/sha1_spec.rb
clearance-1.0.1 spec/models/sha1_spec.rb
clearance-1.0.0 spec/models/sha1_spec.rb
clearance-1.0.0.rc8 spec/models/sha1_spec.rb
clearance-1.0.0.rc7 spec/models/sha1_spec.rb
clearance-1.0.0.rc6 spec/models/sha1_spec.rb