require 'rails_helper' module Mks module Rate RSpec.describe ChargeableService, type: :model do it 'has a valid factory' do expect(create(:chargeable_service)).to be_valid end it 'is invalid without code' do expect(build(:chargeable_service, code: nil)).not_to be_valid end it 'is invalid without name' do expect(build(:chargeable_service, name: nil)).not_to be_valid end it 'is invalid with without base unit' do expect(build(:chargeable_service, base_unit: nil)).not_to be_valid end it 'is invalid without service delivery unit' do expect(build(:chargeable_service, service_delivery_unit_id: nil)).not_to be_valid end it 'can not have chargeable services with same code' do cs = create(:chargeable_service) expect(build(:chargeable_service, code: cs.code, service_delivery_unit_id: cs.service_delivery_unit_id)).not_to be_valid end it 'can create default service bundle upon save' do cs = create(:chargeable_service) expect(ServiceBundle.count).to eq 1 sb = ServiceBundle.first expect(sb.name).to eq cs.name expect(sb.code).to eq cs.code expect(sb.chargeable_services.count).to eq 1 end end end end