Add unregistered speakers scope to program

And use it in Conference#registration_limit_exceeded?

Also change self.registered(conference) to registered(conference) to fix failures in linters
This commit is contained in:
Christina Anagnostou 2017-12-16 16:30:11 +02:00 committed by Stella Rouzi
parent e5948698db
commit 979377f2df
2 changed files with 5 additions and 1 deletions

View file

@ -719,7 +719,7 @@ class Conference < ApplicationRecord
# * +True+ -> If the registration limit has been reached or exceeded
# * +False+ -> If the registration limit hasn't been exceeded
def registration_limit_exceeded?
registration_limit > 0 && registrations.count + program.speakers.confirmed.count - program.speakers.confirmed.registered(program.conference).count >= registration_limit
registration_limit > 0 && registrations.count + program.speakers.confirmed.unregistered(program.conference).count >= registration_limit
end
# Returns an hexadecimal color given a collection. The returned color changed

View file

@ -51,6 +51,10 @@ class Program < ApplicationRecord
def registered(conference)
joins(:registrations).where('registrations.conference_id = ?', conference.id)
end
def unregistered(conference)
self - registered(conference)
end
end
accepts_nested_attributes_for :event_types, allow_destroy: true