require 'rails_helper' module Mks module Edm RSpec.describe EquipmentItem, type: :model do it 'has a valid factory' do expect(create(:equipment_item)).to be_valid end it 'is invalid with no code' do expect(build(:equipment_item, code: nil)).not_to be_valid end it 'is invalid with no name' do expect(build(:equipment_item, name: nil)).not_to be_valid end it 'is invalid with no serial number' do expect(build(:equipment_item, serial_number: nil)).not_to be_valid end it 'is invalid with no purchase price' do expect(build(:equipment_item, purchase_price: nil)).not_to be_valid end it 'is invalid with no purchase date' do expect(build(:equipment_item, purchase_date: nil)).not_to be_valid end it 'initializes model with ready status' do item = EquipmentItem.new(code: FFaker::Name.name, name: FFaker::Name.name, description: FFaker::Name.name, status: nil, serial_number: FFaker::Name.name, brand: FFaker::Name.name, item_model: FFaker::Name.name, purchase_price: 1.5, purchase_date: Date.new, equipment: create(:equipment), current_location: create(:equipment_location)) expect(item).to be_valid expect(item.status).to eq EquipmentItem::READY end it 'is invalid with duplicate code' do ei = create(:equipment_item) expect(build(:equipment_item, code: ei.code)).not_to be_valid end it 'is invalid with duplicate serial number' do ei = create(:equipment_item) expect(build(:equipment_item, serial_number: ei.serial_number)).not_to be_valid end end end end