40 lines
1.2 KiB
Ruby
40 lines
1.2 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe Team do
|
|
describe 'validations' do
|
|
it 'requires a name' do
|
|
team = described_class.new(company_id: 1)
|
|
expect(team).not_to be_valid
|
|
expect(team.errors[:name]).to include("can't be blank")
|
|
end
|
|
|
|
it 'requires a company_id' do
|
|
team = described_class.new(name: "Test Team")
|
|
expect(team).not_to be_valid
|
|
expect(team.errors[:company_id]).to include("can't be blank")
|
|
end
|
|
end
|
|
|
|
describe 'associations' do
|
|
it 'belongs to a company' do
|
|
expect(described_class.reflect_on_association(:company).macro).to eq(:belongs_to)
|
|
end
|
|
|
|
it 'has many reservations' do
|
|
expect(described_class.reflect_on_association(:reservations).macro).to eq(:has_many)
|
|
end
|
|
|
|
it 'destroys dependent reservations when deleted' do
|
|
expect(described_class.reflect_on_association(:reservations).options[:dependent]).to eq(:destroy)
|
|
end
|
|
end
|
|
|
|
describe 'creation' do
|
|
it 'can be created with valid attributes' do
|
|
company = Company.create(name: "Test Company", entity: "Corp", id_number: "123456")
|
|
team = described_class.new(name: "Test Team", company: company)
|
|
expect(team).to be_valid
|
|
end
|
|
end
|
|
end
|