require 'rails_helper' module Mks module Edm RSpec.describe EquipmentValuation, type: :model do it 'has a valid factory' do expect(create(:equipment_valuation)).to be_valid end it 'is invalid without an equipment item' do expect(build(:equipment_valuation, equipment_item: nil)).not_to be_valid end it 'is invalid without an initial_cost' do expect(build(:equipment_valuation, initial_cost: nil)).not_to be_valid end it 'is invalid without a residual value' do expect(build(:equipment_valuation, residual_value: nil)).not_to be_valid end it 'is invalid without working hours per year' do expect(build(:equipment_valuation, work_hrs_per_yr: nil)).not_to be_valid end it 'is invalid without life year' do expect(build(:equipment_valuation, life_year: nil)).not_to be_valid end it 'is invalid without insurance premium' do expect(build(:equipment_valuation, insurance_premium: nil)).not_to be_valid end it 'is invalid without fuel cost per hour' do expect(build(:equipment_valuation, fuel_cost_per_hr: nil)).not_to be_valid end it 'gives makes a new valuation current by default' do valuation = create(:equipment_valuation, is_current: nil) expect(valuation.is_current).to be_truthy end it 'resets other valuations before making the new valuation current' do ei = create(:equipment_item) v1 = create(:equipment_valuation, equipment_item: ei) expect(v1.is_current).to be_truthy v2 = create(:equipment_valuation, equipment_item: ei) expect(v2.is_current).to be_truthy v1.reload expect(v1.is_current).to be_falsey end end end end