Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix saving episodes when end_at > midnight #310

Merged
merged 2 commits into from
Oct 26, 2023
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
9 changes: 7 additions & 2 deletions app/models/show_series.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class ShowSeries < ApplicationRecord
def convert_to! interval, new_start_date
case interval.to_sym
when :biweek
# TODO sometimes have to subtract 2 weeks for recurrences to generate properly???
# will investigate further
# self.update start_date: new_start_date - 2.weeks, recurring_interval: interval
self.update start_date: new_start_date, recurring_interval: interval
self.episodes.where("start_at >= ?", new_start_date).destroy_all
self.save_episodes
Expand Down Expand Up @@ -92,8 +95,10 @@ def save_episodes
scheduled_show.radio = self.radio
scheduled_show.dj = self.users.first # TODO drop dj_id from ScheduledShow?
scheduled_show.image = self.image if self.image.present?
scheduled_show.start_at = DateTime.new r.year, r.month, r.day, self.start_time.hour, self.start_time.min, self.start_time.sec, self.start_time.zone
scheduled_show.end_at = DateTime.new r.year, r.month, r.day, self.end_time.hour, self.end_time.min, self.end_time.sec, self.end_time.zone
start_at = DateTime.new r.year, r.month, r.day, self.start_time.hour, self.start_time.min, self.start_time.sec, self.start_time.zone

scheduled_show.start_at = start_at
scheduled_show.end_at = start_at + (self.end_time - self.start_time)
scheduled_show.slug = nil
scheduled_show.title = self.title
if self.default_playlist.present?
Expand Down
2 changes: 2 additions & 0 deletions spec/models/show_series_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@
show_series.save!
expect(show_series.episodes.count).to eq 1200

new_start_time = 1.week.from_now
show_series.convert_to! "biweek", 1.week.from_now
expect(show_series.reload.episodes.count).to eq 600
expect(show_series.episodes.future.first.start_at).to eq new_start_time
end

xit "creates a unique slug for each recurrence"
Expand Down
Loading