Sha256: 9c6cb8f1bd6341e007dfaa14c5bf35bc0c2d5ac32d936bda56f5cee8886a5767

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

require 'rails_helper'

module Mks
  module Auth
    RSpec.describe User, type: :model do
      it 'has a valid factory' do
        expect(create(:user)).to be_valid
      end

      it 'is invalid with no first name' do
        expect(build(:user, first_name: nil)).not_to be_valid
      end

      it 'is invalid with no last name' do
        expect(build(:user, last_name: nil)).not_to be_valid
      end

      it 'is invalid with no email' do
        expect(build(:user, email: nil)).not_to be_valid
      end

      it 'is invalid with password less than 6 characters' do
        expect(build(:user, password: '1234')).not_to be_valid
      end

      it 'is invalid with duplicate email' do
        u = create(:user)
        expect(build(:user, email: u.email)).not_to be_valid
      end

      it 'is invalid with no active value' do
        expect(build(:user, active: nil)).not_to be_valid
      end

      it 'is invalid with invalid email' do
        expect(build(:user, email: '123456.com')).not_to be_valid
      end

      it 'can access user roles' do
        u = create(:user, :with_roles)
        expect(u.roles.count).to eq 3
      end

      it 'role_names returns role names' do
        r1 = create(:user_role)
        r2 = create(:user_role)
        u = create(:user, roles: [r1, r2])

        roles = u.role_names
        expect(roles).to include r1.name
        expect(roles).to include r2.name
      end

      it 'role? checks if a role exists' do
        r1 = create(:user_role)
        r2 = create(:user_role)
        r3 = create(:user_role)
        u = create(:user, roles: [r1, r2])

        expect(u.role?(r1.sym_name)).to be_truthy
        expect(u.role?(r2.sym_name)).to be_truthy
        expect(u.role?(r3.sym_name)).to be_falsey
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mks_auth-1.0.10 spec/models/mks/auth/user_spec.rb