Skip to content

Commit

Permalink
move media to correct status and set progess_limit correctly (#19)
Browse files Browse the repository at this point in the history
* move media to correct status and set progess_limit correctly

* remove redundent self

* change before save check to use status enum completed?
  • Loading branch information
toyhammered authored and NuckChorris committed Dec 6, 2016
1 parent 8571b66 commit 28c0e55
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions app/models/library_entry.rb
Expand Up @@ -73,8 +73,8 @@ def current_marathon

def progress_limit
return unless progress
progress_cap = media.try(:progress_limit)
default_cap = media.try(:default_progress_limit)
progress_cap = media&.progress_limit
default_cap = media&.default_progress_limit

if progress_cap
if progress > progress_cap
Expand All @@ -100,9 +100,15 @@ def activity
end

before_save do
if status_changed? && status == :completed && media.progress_cap
if status_changed? && completed? && media.progress_limit
# When marked completed, we try to update progress to the cap
self.progress = media.progress_cap
self.progress = media.progress_limit
elsif progress == media.progress_limit
# When in current and progress equals total episodes
self.status = :completed
elsif progress != media.progress_limit && completed?
# When in completed and episodes changed, strange case
self.status = :current
end
end

Expand Down

0 comments on commit 28c0e55

Please sign in to comment.