# frozen_string_literal: true

require_relative '../spec_helper'

RSpec.describe(Test) do
  describe 'Test Creation' do
    it 'Test creation updates model count.' do
      expect { described_class.create(name: 'Test Test') }.to(change(described_class, :count).by(1))
    end
  end

  describe 'Test Read' do
    before do
      described_class.create(name: 'Test Test')
    end

    it 'Test model has name.' do
      tst = described_class.first()
      expect(tst.name).to(eq('Test Test'))
    end
  end

  describe 'Test one-to-many association with Hardware' do
    it 'Test model has Hardware associated with it.' do
      hardware = Hardware.create(name: 'Test Hardware', type: 'gpu')
      tst = described_class.create(name: 'Test Test', hardware_id: hardware.id)
      expect(tst.hardware).to(eq(hardware))
    end

    it 'Test model\'s hardware has name set.' do
      hardware = Hardware.create(name: 'Test Hardware', type: 'gpu')
      tst = described_class.create(name: 'Test Test', hardware_id: hardware.id)
      expect(tst.hardware.name).to(eq('Test Hardware'))
    end
  end
end
