42 lines
1.3 KiB
Ruby
42 lines
1.3 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe Company do
|
|
describe 'associations' do
|
|
it 'has many customers' do
|
|
expect(described_class.reflect_on_association(:customers).macro).to eq(:has_many)
|
|
end
|
|
|
|
it 'has many reservations' do
|
|
expect(described_class.reflect_on_association(:reservations).macro).to eq(:has_many)
|
|
end
|
|
|
|
it 'has many teams' do
|
|
expect(described_class.reflect_on_association(:teams).macro).to eq(:has_many)
|
|
end
|
|
|
|
it 'destroys dependent customers when deleted' do
|
|
expect(described_class.reflect_on_association(:customers).options[:dependent]).to eq(:destroy)
|
|
end
|
|
|
|
it 'destroys dependent reservations when deleted' do
|
|
expect(described_class.reflect_on_association(:reservations).options[:dependent]).to eq(:destroy)
|
|
end
|
|
|
|
it 'destroys dependent teams when deleted' do
|
|
expect(described_class.reflect_on_association(:teams).options[:dependent]).to eq(:destroy)
|
|
end
|
|
end
|
|
|
|
describe 'instance methods' do
|
|
let(:company) { described_class.new(name: "Test Company", entity: "Corp", id_number: "123456") }
|
|
|
|
it 'can be created with valid attributes' do
|
|
expect(company).to be_valid
|
|
end
|
|
|
|
it 'can be saved to the database' do
|
|
expect { company.save }.to change(described_class, :count).by(1)
|
|
end
|
|
end
|
|
end
|