require 'rails_helper' RSpec.describe Reservation do let(:company) { Company.create(name: "Test Company") } let(:team) { Team.create(name: "Test Team", company: company) } let(:customer) do Customer.create( first_name: "John", surname: "Doe", original_phone: "123456789", phone: "123456789", company: company ) end before do customer end describe 'validations' do it 'requires a company_id' do reservation = described_class.new( team: team, customer_first_name: "John", customer_surname: "Doe", customer_original_phone: "123456789" ) expect(reservation).not_to be_valid expect(reservation.errors[:company_id]).to include("can't be blank") end it 'requires a team_id' do reservation = described_class.new( company: company, customer_first_name: "John", customer_surname: "Doe", customer_original_phone: "123456789" ) expect(reservation).not_to be_valid expect(reservation.errors[:team_id]).to include("can't be blank") end it 'requires customer information' do reservation = described_class.new(company: company, team: team) expect(reservation).not_to be_valid expect(reservation.errors[:customer_first_name]).to include("can't be blank") expect(reservation.errors[:customer_surname]).to include("can't be blank") expect(reservation.errors[:customer_original_phone]).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 'belongs to a team' do expect(described_class.reflect_on_association(:team).macro).to eq(:belongs_to) end it 'belongs to a customer' do expect(described_class.reflect_on_association(:customer).macro).to eq(:belongs_to) end end describe 'basic creation' do it 'can be created with minimal valid attributes' do reservation = described_class.new( company: company, team: team, customer_first_name: customer.first_name, customer_surname: customer.surname, customer_original_phone: customer.original_phone ) reservation.valid? puts reservation.errors.full_messages if reservation.errors.any? expect { reservation.save(validate: false) }.to change(described_class, :count).by(1) end end end