Sha256: 750001eaad9fcfd8bb444c9bcaebb3c24ff4d79b4da0c0bbc02e94a0530028b6

Contents?: true

Size: 1.74 KB

Versions: 4

Compression:

Stored size: 1.74 KB

Contents

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mks_edm-1.0.5 spec/models/mks/edm/equipment_item_spec.rb
mks_edm-1.0.4 spec/models/mks/edm/equipment_item_spec.rb
mks_edm-1.0.2 spec/models/mks/edm/equipment_item_spec.rb
mks_edm-1.0.1 spec/models/mks/edm/equipment_item_spec.rb