Sha256: 2d997f5e55b86cf291052bb9d3f7a3fcd262851da55dd830328ea554394b47c6

Contents?: true

Size: 1.41 KB

Versions: 6

Compression:

Stored size: 1.41 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
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mks_auth-1.0.9 spec/models/mks/auth/user_spec.rb
mks_auth-1.0.8 spec/models/mks/auth/user_spec.rb
mks_auth-1.0.7 spec/models/mks/auth/user_spec.rb
mks_auth-1.0.6 spec/models/mks/auth/user_spec.rb
mks_auth-1.0.5 spec/models/mks/auth/user_spec.rb
mks_auth-1.0.4 spec/models/mks/auth/user_spec.rb