Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/models/sponsor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ class Sponsor < ApplicationRecord
mount_uploader(:avatar, AvatarUploader)

def coach_spots
number_of_coaches || (seats / 2.0).round
return number_of_coaches if number_of_coaches.present?

seats.present? ? (seats / 2.0).round : nil
end

def self.latest
Expand Down
20 changes: 20 additions & 0 deletions spec/models/sponsor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,24 @@
.with_values(%i[hidden standard bronze silver gold community])
end
end

describe '#coach_spots' do
it 'returns number_of_coaches when present' do
sponsor = Fabricate.build(:sponsor, number_of_coaches: 4, seats: 10)

expect(sponsor.coach_spots).to eq(4)
end

it 'falls back to half the seats rounded' do
sponsor = Fabricate.build(:sponsor, number_of_coaches: nil, seats: 15)

expect(sponsor.coach_spots).to eq(8)
end

it 'does not raise when both seats and number_of_coaches are missing' do
sponsor = Fabricate.build(:sponsor, number_of_coaches: nil, seats: nil)

expect(sponsor.coach_spots).to be_nil
end
end
end