Fixed DeleteEventSchedules issue

Issues with DeleteEventSchedules method in conference controller:
1.It deletes EventSchedules of all the conferences that are not in the
hours range. Instead it should delete EventSchedules of those events
only that belong to that particular conference only.
2.If we set invalid start or end hour attribute of a conference then
also EventSchedules gets deleted even though conference is not
successfully updated.
Fixed both the issues and added test for the same.
This commit is contained in:
Siddhant Bajaj 2017-03-06 21:45:48 +05:30
parent ec71b111fe
commit 7ce816e146
3 changed files with 34 additions and 10 deletions

View file

@ -82,7 +82,6 @@ module Admin
short_title = @conference.short_title
@conference.assign_attributes(conference_params)
send_mail_on_conf_update = @conference.notify_on_dates_changed?
delete_event_schedules if @conference.start_hour_changed? || @conference.end_hour_changed?
if @conference.update_attributes(conference_params)
ConferenceDateUpdateMailJob.perform_later(@conference) if send_mail_on_conf_update
@ -189,14 +188,5 @@ module Admin
:targets, :targets_attributes,
:campaigns, :campaigns_attributes, :registration_limit)
end
def delete_event_schedules
event_schedules = EventSchedule.select do |e|
e.start_time.strftime('%H').to_i < @conference.start_hour ||
e.end_time.strftime('%H').to_i > @conference.end_hour ||
(e.end_time.strftime('%H').to_i == @conference.end_hour && e.end_time.strftime('%M').to_i > 0)
end
event_schedules.each(&:destroy)
end
end
end