Skip to content

Commit 32e4973

Browse files
committed
Fix failing tests due to error in new query
I thought the issue was related to the data fabrication but actually the issue was in the query I made. It was not filtering by workshop id. The query returned an array of workshops and the first workshop was picked and so when two workshops were fabricated the sponsors were always the same. I've resolved this by filtering by workshop id in the query on the workshop model
1 parent 0b3a8fe commit 32e4973

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

app/models/workshop.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +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 }
33+
def workshop_sponsors_with_host_true
34+
Workshop.includes(:workshop_sponsors).flat_map do |workshop|
35+
workshop.workshop_sponsors.select { |ws| ws.host == true && ws.workshop_id == id }
3636
end
3737
end
3838

3939
def host
40-
Workshop.workshop_sponsors_with_host_true.first&.sponsor
40+
workshop_sponsors_with_host_true.first&.sponsor
4141
end
4242

4343
def waiting_list

0 commit comments

Comments
 (0)