require 'rails_helper' module Logistics module Core RSpec.describe Unit, type: :model do it 'has a valid factory' do expect(create(:unit)).to be_valid end it 'is invalid with no abbreviation' do expect(build(:unit, :abbreviation => '')).not_to be_valid end it 'is invalid with no name' do expect(build(:unit, :name => '')).not_to be_valid end it 'is invalid with duplicate abbreviation' do u = create(:unit) expect(build(:unit, :abbreviation => u.abbreviation)).not_to be_valid end it 'is invalid with duplicate name' do u = create(:unit) expect(build(:unit, :name => u.name)).not_to be_valid end it 'is invalid with no unit type' do expect(build(:unit, :unit_type => nil)).not_to be_valid end end end end