Sha256: 4116ce06af1a1b19984386795a7cc6c4dd33cf79a98ff43db4749ca070d72ebd

Contents?: true

Size: 1.84 KB

Versions: 2

Compression:

Stored size: 1.84 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'
          user.password_changing = true
          expect(user).to_not be_valid
        end

        it 'is valid with a long password' do
          user = build(:user)
          user.password = 'thisisalongpassword'
          user.password_changing = true
          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 = ''
          subject.password_changing = true
          expect(subject).to_not be_valid
        end

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

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
authenticate-0.3.1 spec/model/db_password_spec.rb
authenticate-0.3.0 spec/model/db_password_spec.rb