Skip to content

Commit 0b3a8fe

Browse files
committed
chore: use associations for finding workshop sponsors with hosts
I have implemented workshop associations' hosts to be returned by the host method and I've removed the scope to do the same on the workshop_sponsor model
1 parent a5a1604 commit 0b3a8fe

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

app/models/workshop.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ class Workshop < ApplicationRecord
3030
before_validation :set_date_and_time, :set_end_date_and_time, if: proc { |model| model.chapter_id.present? }
3131
before_validation :set_opens_at
3232

33+
def self.workshop_sponsors_with_host_true
34+
includes(:workshop_sponsors).flat_map do |workshop|
35+
workshop.workshop_sponsors.select { |ws| ws.host == true }
36+
end
37+
end
38+
3339
def host
34-
WorkshopSponsor.hosts.for_workshop(id).first&.sponsor
40+
Workshop.workshop_sponsors_with_host_true.first&.sponsor
3541
end
3642

3743
def waiting_list

spec/models/workshop_sponsor_spec.rb

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,5 @@
1919
expect(WorkshopSponsor.hosts).to eq []
2020
end
2121
end
22-
23-
context '#for_workshop' do
24-
it 'includes sponsors of the workshop' do
25-
workshop_sponsor = Fabricate(:workshop_sponsor)
26-
expect(WorkshopSponsor.for_workshop(workshop_sponsor.workshop)).to include(workshop_sponsor)
27-
end
28-
29-
it 'excludes sponsors not sponsoring the workshop' do
30-
Fabricate(:workshop_sponsor)
31-
workshop = Fabricate(:workshop_no_sponsor)
32-
expect(WorkshopSponsor.for_workshop(workshop)).to eq []
33-
end
34-
end
3522
end
3623
end

0 commit comments

Comments
 (0)