Skip to content

Commit

Permalink
use movie/episode airdates for sorting if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
wr0ngway committed Nov 25, 2014
1 parent c8f0100 commit 397c50d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/tivohmo/adapters/plex/episode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def initialize(delegate)

self.title = delegate.title
self.modified_at = Time.at(delegate.updated_at.to_i)
self.created_at = Time.at(delegate.added_at.to_i)
self.created_at = Time.parse(delegate.originally_available_at) rescue nil
self.created_at ||= Time.at(delegate.added_at.to_i)
end

def metadata
Expand Down
3 changes: 2 additions & 1 deletion lib/tivohmo/adapters/plex/movie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def initialize(delegate)

self.title = delegate.title
self.modified_at = Time.at(delegate.updated_at.to_i)
self.created_at = Time.at(delegate.added_at.to_i)
self.created_at = Time.parse(delegate.originally_available_at) rescue nil
self.created_at ||= Time.at(delegate.added_at.to_i)
end

def metadata
Expand Down
10 changes: 5 additions & 5 deletions spec/adapters/plex/category_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@
describe "#children" do

it "should memoize" do
listing = [plex_stub(::Plex::Movie)]
listing = [plex_stub(::Plex::Movie, originally_available_at: "2013-01-02")]
allow(plex_delegate).to receive(:newest).and_return(listing)
section = described_class.new(plex_delegate, :newest)
expect(section.children.object_id).to eq(section.children.object_id)
end

it "should have children" do
listing = [
plex_stub(::Plex::Movie),
plex_stub(::Plex::Episode),
plex_stub(::Plex::Movie, originally_available_at: "2013-01-02"),
plex_stub(::Plex::Episode, originally_available_at: "2013-01-02"),
plex_stub(::Plex::Show)
]
allow(plex_delegate).to receive(:newest).and_return(listing)
Expand All @@ -55,8 +55,8 @@

it "should use category_value for children" do
listing = [
plex_stub(::Plex::Movie),
plex_stub(::Plex::Episode),
plex_stub(::Plex::Movie, originally_available_at: "2013-01-02"),
plex_stub(::Plex::Episode, originally_available_at: "2013-01-02"),
plex_stub(::Plex::Show)
]
cval = {title: 'Title', key: 'key'}
Expand Down
2 changes: 1 addition & 1 deletion spec/adapters/plex/episode_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
expect(episode.title).to eq(plex_delegate.title)
expect(episode.identifier).to eq(plex_delegate.key)
expect(episode.modified_at).to eq(Time.at(plex_delegate.updated_at))
expect(episode.created_at).to eq(Time.at(plex_delegate.added_at))
expect(episode.created_at).to eq(Time.parse(plex_delegate.originally_available_at))
end

end
Expand Down
2 changes: 1 addition & 1 deletion spec/adapters/plex/movie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
expect(movie.title).to eq(plex_delegate.title)
expect(movie.identifier).to eq(plex_delegate.key)
expect(movie.modified_at).to eq(Time.at(plex_delegate.updated_at))
expect(movie.created_at).to eq(Time.at(plex_delegate.added_at))
expect(movie.created_at).to eq(Time.parse(plex_delegate.originally_available_at))
end

end
Expand Down

0 comments on commit 397c50d

Please sign in to comment.