Sha256: b66b108a821ce26df1083df9cbd7634c006c3832a78f53dd69ddc5dff4530d7b

Contents?: true

Size: 1.67 KB

Versions: 9

Compression:

Stored size: 1.67 KB

Contents

require 'spec_helper'
require 'authenticate/model/db_password'

describe Authenticate::Model::DbPassword do
  describe 'Passwords' do
    context '#password_match?' do
      subject { create(:user, password: 'password') }

      it 'matches a password' do
        expect(subject.password_match?('password')).to be_truthy
      end

      it 'fails to match a bad password' do
        expect(subject.password_match?('bad password')).to be_falsey
      end

      it 'saves passwords' do
        subject.password = 'new_password'
        subject.save!

        user = User.find(subject.id)
        expect(user.password_match?('new_password')).to be_truthy
      end
    end

    describe 'Validations' do
      context 'on a new user' do
        it 'should not be valid without a password' do
          user = build(:user, :without_password)
          expect(user).to_not be_valid
        end

        it 'should be not be valid with a short password' do
          user = build(:user)
          user.password = 'short'
          expect(user).to_not be_valid
        end

        it 'is valid with a long password' do
          user = build(:user)
          user.password = 'thisisalongpassword'
          expect(user).to be_valid
        end
      end

      context 'on an existing user' do
        subject { create(:user, password: 'password') }

        it { is_expected.to be_valid }

        it 'should not be valid with an empty password' do
          subject.password = ''
          expect(subject).to_not be_valid
        end

        it 'should be valid with a new (valid) password' do
          subject.password = 'new password'
          expect(subject).to be_valid
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
authenticate-0.7.3 spec/model/db_password_spec.rb
authenticate-0.7.2 spec/model/db_password_spec.rb
authenticate-0.7.1 spec/model/db_password_spec.rb
authenticate-0.7.0 spec/model/db_password_spec.rb
authenticate-0.6.1 spec/model/db_password_spec.rb
authenticate-0.6.0 spec/model/db_password_spec.rb
authenticate-0.5.0 spec/model/db_password_spec.rb
authenticate-0.4.0 spec/model/db_password_spec.rb
authenticate-0.3.3 spec/model/db_password_spec.rb